Skip to content

Commit 2c5bb5d

Browse files
committed
Fix and arc creation error when linking IDF files. For negative angles we need to use the absolute value of the angle. Also simplify the formula for center distance calculation.
1 parent 8042810 commit 2c5bb5d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/importidf.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static Vector ArcCenter(Vector p0, Vector p1, double angle) {
211211
// indicates a circle centered at x1,y1 passing through x2,y2 and is a complete loop.
212212
static void CreateEntity(EntityList *el, int *id, hEntity h0, hEntity h1, hEntity hnorm,
213213
Vector p0, Vector p1, double angle, bool keepout) {
214-
if (angle == 0.0) {
214+
if (fabs(angle) < 0.1) {
215215
//line
216216
if(p0.Equals(p1)) return;
217217

@@ -228,16 +228,14 @@ static void CreateEntity(EntityList *el, int *id, hEntity h0, hEntity h1, hEntit
228228
if(angle < 0.0) {
229229
swap(p0,p1);
230230
swap(h0,h1);
231+
angle = fabs(angle);
231232
}
232233
// locate the center of the arc
233234
Vector m = p0.Plus(p1).ScaledBy(0.5);
234235
Vector perp = Vector::From(p1.y-p0.y, p0.x-p1.x, 0.0).WithMagnitude(1.0);
235-
double dist = 0;
236-
if (angle != 180) {
237-
dist = (p1.Minus(m).Magnitude())/tan(0.5*angle*3.141592653589793/180.0);
238-
} else {
239-
dist = 0.0;
240-
}
236+
// half angle in radians
237+
double theta = 0.5*angle*PI/180.0;
238+
double dist = (p1.Minus(m).Magnitude())*cos(theta)/sin(theta);
241239
Vector c = m.Minus(perp.ScaledBy(dist));
242240
hEntity hc = newPoint(el, id, c, /*visible=*/false);
243241
newArc(el, id, h0, h1, hc, hnorm, keepout);

0 commit comments

Comments
 (0)