[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: gEDA-user: pcb, howto get plain rats lines instead of circles
On Tue, 2008-10-07 at 23:46 -0700, Ben Jackson wrote:
> On Wed, Oct 08, 2008 at 07:56:27AM +0200, Bert Timmerman wrote:
> From my quick test it seems to be due to 'IsPointInBox' having wholly
> unexpected behavior due to a rather bizzare implementation. It turns
> the 'box' it gets as input into a pad and then calls the pad intersection.
> It looks like the code is broken if the box is wider than tall. If you
> replace the rectangle in that b2.pcb someone sent out with a new one
> that's taller than wide, it works fine.
Here is a patch "fixing" IsPointInBox. I've not tested it extensively
(with a radius parameter passed).
This function would be one-line for the case where radius is zero.
--
Peter Clifton
Electrical Engineering Division,
Engineering Department,
University of Cambridge,
9, JJ Thomson Avenue,
Cambridge
CB3 0FA
Tel: +44 (0)7729 980173 - (No signal in the lab!)
From fc63eb7b87be582d5a0578c648502a8ef33d576f Mon Sep 17 00:00:00 2001
From: Peter Clifton <pcjc2@xxxxxxxxx>
Date: Wed, 8 Oct 2008 15:53:55 +0100
Subject: [PATCH] Fix IsPointInBox to work with wide as well as tall boxes
---
src/search.c | 53 ++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 44 insertions(+), 9 deletions(-)
diff --git a/src/search.c b/src/search.c
index 4304ec3..0d75500 100644
--- a/src/search.c
+++ b/src/search.c
@@ -1005,15 +1005,50 @@ IsPointInPad (LocationType X, LocationType Y, BDimension Radius,
Boolean
IsPointInBox (LocationType X, LocationType Y, BoxTypePtr box, BDimension Radius)
{
- PadType pad;
-
- pad.Thickness = (box->X1 - box->X2); ASSIGN_FLAG (SQUAREFLAG, True, &pad);
- if (pad.Thickness < 0)
- pad.Thickness = - pad.Thickness;
- pad.Point1.X = pad.Point2.X = (box->X1 + box->X2) / 2;
- pad.Point1.Y = MIN (box->Y1, box->Y2) + pad.Thickness / 2;
- pad.Point2.Y = MAX (box->Y1, box->Y2) - pad.Thickness / 2;
- return IsPointInPad (X, Y, Radius, &pad);
+ BDimension width, height, range;
+
+ /* NB: Assumes box has point1 with numerically lower X and Y coordinates */
+
+ /* Compute coordinates relative to Point1 */
+ X -= box->X1;
+ Y -= box->Y1;
+
+ width = box->X2 - box->X1;
+ height = box->Y2 - box->Y1;
+
+ if (X <= 0)
+ {
+ if (Y < 0)
+ return (Radius >= 0) && (Radius * (double)Radius >
+ (double)Y * Y + (double)X * X);
+ else if (Y > height)
+ return (Radius >= 0) && (Radius * (double)Radius >
+ (double)(Y - height) * (Y - height) + (double)X * X);
+ else
+ range = -X;
+ }
+ else if (X >= width)
+ {
+ if (Y < 0)
+ return (Radius >= 0) && (Radius * (double)Radius >
+ (double)Y * Y + (double)(X - width) * (X - width));
+ else if (Y > height)
+ return (Radius >= 0) && (Radius * (double)Radius >
+ (double)(Y - height) * (Y - height) + (double)(X - width) * (X - width));
+ else
+ range = X - width;
+ }
+ else
+ {
+ if (Y < 0)
+ range = -Y;
+ else if (Y > height)
+ range = Y - height;
+ else
+ return True;
+ }
+
+ return range < Radius;
}
int ClosestArcPoint (float X, float Y, ArcTypePtr Arc)
--
1.5.6.3
_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user