Skip to content

Commit

Permalink
Merge pull request #197 from FriendsOfCADability/PrematureReturninLoop
Browse files Browse the repository at this point in the history
Premature Return in Loop Causing Incomplete Processing
  • Loading branch information
dsn27 authored Dec 12, 2024
2 parents e784dae + 1fc6727 commit d9e7aea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
30 changes: 18 additions & 12 deletions CADability/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3668,16 +3668,16 @@ public GeoPoint2D SomeInnerPoint
}
}
}

internal Border[] RemoveConstrictions(double precision)
{ // Wenn es Einschnürungen gibt, also Stellen, an denen sich das Border auf "precision" selbst berührt,
// dann entferne diese Einschnürungen und liefere eine Liste von Teilborders, die auch mindesten precision voneinander entfernt sind
// und keine solchen Engstellen haben
{
// If there are constrictions, i.e., areas where the border touches itself within "precision",
// remove these constrictions and return a list of sub-borders that are at least "precision" apart
// and do not have such narrow areas.

List<Border> res = new List<Border>();
double len = this.Extent.Size;
double leneps = len * precision;

//TODO: This doesn't make sense. Directly returning inside the for loop
for (int i = 0; i < segment.Length; i++)
{
ICollection cl = QuadTree.GetObjectsCloseTo(segment[i]);
Expand All @@ -3692,7 +3692,8 @@ internal Border[] RemoveConstrictions(double precision)
double par1 = segment[i].PositionOf(p1);
double par2 = curve.PositionOf(p2);
if (Precision.OppositeDirection(segment[i].DirectionAt(par1), curve.DirectionAt(par2)))
{// hier müssen wir aufspalten
{
// Split into parts
int k = (int)segmentToIndex[curve];
Border[] parts = Split(new double[] { i + par1, k + par2 });
if (parts.Length == 3)
Expand All @@ -3706,22 +3707,27 @@ internal Border[] RemoveConstrictions(double precision)
bdr1.RemoveNarrowEnd(precision);
bdr2.forceClosed();
bdr2.RemoveNarrowEnd(precision);
// jetzt beide Border an der Nahtstelle soweit zurückverfolgen, bis der Abstand größer precision wird
// Dabei kann das Border auch verschwinden
if (bdr1.Area > precision * precision) res.AddRange(bdr1.RemoveConstrictions(precision));
if (bdr2.Area > precision * precision) res.AddRange(bdr2.RemoveConstrictions(precision));
return res.ToArray();

// Recursively remove constrictions
if (bdr1.Area > precision * precision)
res.AddRange(bdr1.RemoveConstrictions(precision));
if (bdr2.Area > precision * precision)
res.AddRange(bdr2.RemoveConstrictions(precision));
}
}
}
}
}
return new Border[] { this }; // dieses unverändert
}

// If no constrictions were found, add the current border
if (res.Count == 0)
res.Add(this);

return res.ToArray();
}


private bool RemoveNarrowEnd(double precision)
{ // an der Naht ist dieses Border möglicherweise spitz. Gehe soweit zurück, bis mindestens eine Breite von precision erreicht wird
if (Area < precision * precision)
Expand Down
12 changes: 5 additions & 7 deletions CADability/GeneralCurve2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1442,20 +1442,18 @@ public void Debug(string Title)

GeoPoint2D[] I2DIntersectable.IntersectWith(I2DIntersectable other)
{
if (other is ICurve2D)
if (other is ICurve2D curve2D)
{
GeoPoint2DWithParameter[] ips = Intersect(other as ICurve2D);
GeoPoint2DWithParameter[] ips = Intersect(curve2D);
GeoPoint2D[] res = new GeoPoint2D[ips.Length];

//TODO: This does not make sense. Returning directly in a for loop
for (int i = 0; i < ips.Length; i++)
{
res[i] = ips[i].p;
return res;
}

return res;
}

return other.IntersectWith(this);
// throw new NotImplementedException("I2DIntersectable.IntersectWith " + other.GetType().Name);
}
#if DEBUG
public GeoObjectList debug
Expand Down

0 comments on commit d9e7aea

Please sign in to comment.