Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geometry_Engine: UTs refreshed and Boolean operations bugfixed #3319

Merged
merged 10 commits into from
Mar 13, 2024

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .ci/Datasets/Geometry_Engine/Compute/BooleanUnion.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .ci/Datasets/Geometry_Engine/Compute/FitLine.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .ci/Datasets/Geometry_Engine/Compute/FitPlane.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .ci/Datasets/Geometry_Engine/Compute/GrahamScan.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .ci/Datasets/Geometry_Engine/Compute/Split.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .ci/Datasets/Geometry_Engine/Query/IsCollinear.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .ci/Datasets/Geometry_Engine/Query/IsCoplanar.json

Large diffs are not rendered by default.

36 changes: 23 additions & 13 deletions Geometry_Engine/Compute/BooleanDifference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ public static partial class Compute
/**** public Methods - Lines ****/
/***************************************************/

[Description("Returns the parts of the first line that are _not_ overlapping with the reference line, i.e. removes that parts of the first line that _is_ overlapping with the reference line. If the lines are not colinear or within tolerance distance of each other the full first line is returned.")]
[Description("Returns the parts of the first line that are not overlapping with the reference line, i.e. removes that parts of the first line that is overlapping with the reference line. If the lines are not colinear or within tolerance distance of each other the full first line is returned.")]
[Input("line", "The line to remove overlaps from.")]
[Input("refLine", "The reference line. Any parts of this line that are overlapping with the first line are removed from the first line.")]
[Input("tolerance", "Tolerance used for checking colinearity and proximity of the two lines.", typeof(Length))]
[Output("line", "The parts of the first line _not_ overlapping with the reference line.")]
[Output("line", "The parts of the first line not overlapping with the reference line.")]
public static List<Line> BooleanDifference(this Line line, Line refLine, double tolerance = Tolerance.Distance)
{
return new List<Line> { line }.BooleanDifference(new List<Line> { refLine }, tolerance);
}

/***************************************************/

[Description("Returns the parts of the first lines that are _not_ overlapping with any of the reference lines, i.e. removes that parts of the first lines that _is_ overlapping with any of the reference lines. If a line and a reference line are not colinear or within distance tolerance of each other, no action will be taken for that particular pair of lines.")]
[Description("Returns the parts of the first lines that are not overlapping with any of the reference lines, i.e. removes that parts of the first lines that is overlapping with any of the reference lines. If a line and a reference line are not colinear or within distance tolerance of each other, no action will be taken for that particular pair of lines.")]
[Input("lines", "The lines to remove overlaps from.")]
[Input("refLines", "The reference lines. Any parts of these lines that are overlapping with the first lines are removed from the first lines.")]
[Input("tolerance", "Tolerance used for checking colinearity and proximity between two lines.", typeof(Length))]
[Output("lines", "The parts of the first lines _not_ overlapping with the reference lines.")]
[Output("lines", "The parts of the first lines not overlapping with the reference lines.")]
public static List<Line> BooleanDifference(this List<Line> lines, List<Line> refLines, double tolerance = Tolerance.Distance)
{
double sqTol = tolerance * tolerance;
Expand All @@ -64,12 +64,12 @@ public static List<Line> BooleanDifference(this List<Line> lines, List<Line> ref
foreach (var cluster in lines.ClusterCollinear(tolerance))
{
List<Line> toCull = new List<Line>();
for (int i = refLines.Count - 1; i >= 0; i--)
for (int i = refLeft.Count - 1; i >= 0; i--)
{
if (refLines[i].IsCollinear(cluster[0]))
if (refLeft[i].IsCollinear(cluster[0]))
{
toCull.Add(refLines[i]);
refLines.RemoveAt(i);
toCull.Add(refLeft[i]);
refLeft.RemoveAt(i);
}
}

Expand All @@ -87,11 +87,11 @@ public static List<Line> BooleanDifference(this List<Line> lines, List<Line> ref
/**** public Methods - Regions ****/
/***************************************************/

[Description("Returns the areas of the closed Polyline region that are _not_ overlapping with the closed Polyline reference regions, i.e. removes that areas of the first region that _is_ overlapping with any of the reference regions. Requires the region and all reference regions to be closed. The method only considers reference regions that are co-planar with the region being evaluated.")]
[Description("Returns the areas of the closed Polyline region that are not overlapping with the closed Polyline reference regions, i.e. removes that areas of the first region that is overlapping with any of the reference regions. Requires the region and all reference regions to be closed. The method only considers reference regions that are co-planar with the region being evaluated.")]
[Input("region", "The line to remove overlaps from. Should be a closed planar curve.")]
[Input("refRegions", "The reference regions. Any parts of these regions that are overlapping with the first region are removed from the first region. All regions required to be closed. Reference regions not coplanar with the region are not considered.")]
[Input("tolerance", "Tolerance used for checking co-planarity and proximity of the regions.", typeof(Length))]
[Output("regions", "The region parts of the first region _not_ overlapping with any of the reference regions.")]
[Output("regions", "The region parts of the first region not overlapping with any of the reference regions.")]
public static List<Polyline> BooleanDifference(this Polyline region, List<Polyline> refRegions, double tolerance = Tolerance.Distance)
{
if (!region.IsClosed(tolerance) || refRegions.Any(x => !x.IsClosed()))
Expand Down Expand Up @@ -242,11 +242,11 @@ public static List<Polyline> BooleanDifference(this Polyline region, List<Polyli

/***************************************************/

[Description("Returns the areas of the closed ICurve region that are _not_ overlapping with the closed ICurve reference regions, i.e. removes that areas of the first region that _is_ overlapping with any of the reference regions. Requires the region and all reference regions to be closed. The method only considers reference regions that are co-planar with the region being evaluated.")]
[Description("Returns the areas of the closed ICurve region that are not overlapping with the closed ICurve reference regions, i.e. removes that areas of the first region that is overlapping with any of the reference regions. Requires the region and all reference regions to be closed. The method only considers reference regions that are co-planar with the region being evaluated.")]
[Input("region", "The line to remove overlaps from. Should be a closed planar curve.")]
[Input("refRegions", "The reference regions. Any parts of these regions that are overlapping with the first region are removed from the first region. All regions required to be closed. Reference regions not coplanar with the region are not considered.")]
[Input("tolerance", "Tolerance used for checking co-planarity and proximity of the regions.", typeof(Length))]
[Output("regions", "The region parts of the first region _not_ overlapping with any of the reference regions.")]
[Output("regions", "The region parts of the first region not overlapping with any of the reference regions.")]
public static List<PolyCurve> BooleanDifference(this ICurve region, IEnumerable<ICurve> refRegions, double tolerance = Tolerance.Distance)
{
List<ICurve> refRegionsList = refRegions.ToList();
Expand Down Expand Up @@ -433,14 +433,24 @@ private static List<Line> BooleanDifferenceCollinear(this List<Line> lines1, Lis
int i = 0;
foreach ((double, double) range in mergedRanges2)
{
double exclusionStart = range.Item1;
for (; i < mergedRanges1.Count; i++)
{
if (exclusionStart - mergedRanges1[i].Item2 < -tolerance)
break;

if (mergedRanges1[i].Item2 - mergedRanges1[i].Item1 > tolerance)
differenceRanges.Add(mergedRanges1[i]);
}

for (; i < mergedRanges1.Count; i++)
{
if (mergedRanges1[i].Item1 - range.Item1 < -tolerance)
differenceRanges.Add((mergedRanges1[i].Item1, Math.Min(mergedRanges1[i].Item2, range.Item1)));

if (range.Item2 - mergedRanges1[i].Item2 < tolerance)
{
mergedRanges1[i] = (range.Item2, mergedRanges1[i].Item2);
mergedRanges1[i] = (Math.Max(mergedRanges1[i].Item1, range.Item2), mergedRanges1[i].Item2);
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions Geometry_Engine/Compute/BooleanIntersection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ public static List<Line> BooleanIntersection(this List<Line> lines, List<Line> r
foreach (var cluster in lines.ClusterCollinear(tolerance))
{
List<Line> toIntersect = new List<Line>();
for (int i = refLines.Count - 1; i >= 0; i--)
for (int i = refLeft.Count - 1; i >= 0; i--)
{
if (refLines[i].IsCollinear(cluster[0]))
if (refLeft[i].IsCollinear(cluster[0]))
{
toIntersect.Add(refLines[i]);
refLines.RemoveAt(i);
toIntersect.Add(refLeft[i]);
refLeft.RemoveAt(i);
}
}

Expand Down