Skip to content

Commit 7aceffd

Browse files
author
Fraser Greenroyd
authored
Geometry_Engine: redundant calls to clone removed (#3232)
2 parents d53362f + 3ec8c04 commit 7aceffd

26 files changed

+67
-68
lines changed

Geometry_Engine/Compute/BooleanDifference.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static partial class Compute
4545
public static List<Line> BooleanDifference(this Line line, Line refLine, double tolerance = Tolerance.Distance)
4646
{
4747
if (refLine.Length() <= tolerance)
48-
return new List<Line> { line.DeepClone() };
48+
return new List<Line> { line };
4949

5050
if (line.IsCollinear(refLine, tolerance))
5151
{
@@ -69,14 +69,14 @@ public static List<Line> BooleanDifference(this Line line, Line refLine, double
6969
Point aRPt = refLine.ControlPoints().Average();
7070

7171
if (aRPt.SquareDistance(splitLine[0]) > sqTol && aPt.SquareDistance(refLine) > sqTol)
72-
splitLine = new List<Line> { line.DeepClone() };
72+
splitLine = new List<Line> { line };
7373
else
7474
splitLine = new List<Line>();
7575
}
7676

7777
return splitLine;
7878
}
79-
return new List<Line> { line.DeepClone() };
79+
return new List<Line> { line };
8080
}
8181

8282
/***************************************************/
@@ -92,7 +92,7 @@ public static List<Line> BooleanDifference(this List<Line> lines, List<Line> ref
9292

9393
foreach (Line line in lines)
9494
{
95-
List<Line> splitLine = new List<Line> { line.DeepClone() };
95+
List<Line> splitLine = new List<Line> { line };
9696
int k = 0;
9797
bool split = false;
9898
do

Geometry_Engine/Compute/BooleanIntersection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static Line BooleanIntersection(this Line line, Line refLine, double tole
9595
double sqTol = tolerance * tolerance;
9696
Point aPt = splitLine[0].ControlPoints().Average();
9797
Point aRPt = refLine.ControlPoints().Average();
98-
return aRPt.SquareDistance(splitLine[0]) > sqTol && aPt.SquareDistance(refLine) > sqTol ? null : line.DeepClone();
98+
return aRPt.SquareDistance(splitLine[0]) > sqTol && aPt.SquareDistance(refLine) > sqTol ? null : line;
9999
}
100100
}
101101

@@ -136,7 +136,7 @@ public static Line BooleanIntersection(this List<Line> lines, double tolerance =
136136
if (lines[0].Length() <= tolerance)
137137
return null;
138138

139-
Line result = lines[0].DeepClone();
139+
Line result = lines[0];
140140
for (int i = 1; i < lines.Count; i++)
141141
{
142142
result = result.BooleanIntersection(lines[i], tolerance);

Geometry_Engine/Compute/BooleanUnion.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ public static List<Line> BooleanUnion(this Line line, Line refLine, double toler
6464
}
6565
}
6666

67-
return new List<Line> { line.DeepClone(), refLine.DeepClone() };
67+
return new List<Line> { line, refLine };
6868
}
6969

7070
/***************************************************/
7171

7272
public static List<Line> BooleanUnion(this List<Line> lines, double tolerance = Tolerance.Distance)
7373
{
74-
List<Line> result = lines.Select(l => l.DeepClone()).ToList();
74+
List<Line> result = lines.ToList();
7575
bool union;
7676
do
7777
{

Geometry_Engine/Compute/ClusterCollinear.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public static List<List<Line>> ClusterCollinear(this List<Line> lines, double to
4444
{
4545
if (l.IsCollinear(ll[0], tolerance))
4646
{
47-
ll.Add(l.DeepClone());
47+
ll.Add(l);
4848
collinear = true;
4949
break;
5050
}
5151
}
5252

5353
if (!collinear)
54-
lineClusters.Add(new List<Line> { l.DeepClone() });
54+
lineClusters.Add(new List<Line> { l });
5555
}
5656

5757
return lineClusters;

Geometry_Engine/Compute/DistributeOutlines.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public static List<List<Polyline>> DistributeOutlines(this List<Polyline> outlin
7979
outlinesByType.Add(new Tuple<Polyline, bool>(o, true));
8080
}
8181

82-
List<Polyline> panelOutlines = outlinesByType.Where(x => x.Item2 == true).Select(x => x.Item1.DeepClone()).ToList();
83-
List<Polyline> panelOpenings = outlinesByType.Where(x => x.Item2 == false).Select(x => x.Item1.DeepClone()).ToList();
82+
List<Polyline> panelOutlines = outlinesByType.Where(x => x.Item2 == true).Select(x => x.Item1).ToList();
83+
List<Polyline> panelOpenings = outlinesByType.Where(x => x.Item2 == false).Select(x => x.Item1).ToList();
8484
return panelOutlines.DistributeOpenings(panelOpenings, tolerance);
8585
}
8686

@@ -127,8 +127,8 @@ public static List<List<ICurve>> DistributeOutlines(this List<ICurve> outlines,
127127
if (!assigned)
128128
outlinesByType.Add(new Tuple<ICurve, bool>(o, true));
129129
}
130-
List<ICurve> panelOutlines = outlinesByType.Where(x => x.Item2 == true).Select(x => x.Item1.DeepClone()).ToList();
131-
List<ICurve> panelOpenings = outlinesByType.Where(x => x.Item2 == false).Select(x => x.Item1.DeepClone()).ToList();
130+
List<ICurve> panelOutlines = outlinesByType.Where(x => x.Item2 == true).Select(x => x.Item1).ToList();
131+
List<ICurve> panelOpenings = outlinesByType.Where(x => x.Item2 == false).Select(x => x.Item1).ToList();
132132
return panelOutlines.DistributeOpenings(panelOpenings, tolerance);
133133
}
134134

Geometry_Engine/Compute/SortAlongCurve.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public static partial class Compute
4646
public static List<Point> SortAlongCurve(this List<Point> points, Arc arc, double distanceTolerance = Tolerance.Distance, double angleTolerance = Tolerance.Angle)
4747
{
4848
if (arc.Angle() <= angleTolerance)
49-
return points.Select(p => p.DeepClone()).ToList();
49+
return points;
5050

51-
List<Tuple<Point, double>> cData = points.Select(p => new Tuple<Point, double>(p.DeepClone(), arc.ParameterAtPoint(arc.ClosestPoint(p)))).ToList();
51+
List<Tuple<Point, double>> cData = points.Select(p => new Tuple<Point, double>(p, arc.ParameterAtPoint(arc.ClosestPoint(p)))).ToList();
5252

5353
cData.Sort(delegate (Tuple<Point, double> d1, Tuple<Point, double> d2)
5454
{
@@ -69,9 +69,9 @@ public static List<Point> SortAlongCurve(this List<Point> points, Arc arc, doubl
6969
public static List<Point> SortAlongCurve(this List<Point> points, Circle circle, double distanceTolerance = Tolerance.Distance, double angleTolerance = Tolerance.Angle)
7070
{
7171
if (circle.Radius <= distanceTolerance)
72-
return points.Select(p => p.DeepClone()).ToList();
72+
return points;
7373

74-
List<Tuple<Point, double>> cData = points.Select(p => new Tuple<Point, double>(p.DeepClone(), circle.ParameterAtPoint(circle.ClosestPoint(p)))).ToList();
74+
List<Tuple<Point, double>> cData = points.Select(p => new Tuple<Point, double>(p, circle.ParameterAtPoint(circle.ClosestPoint(p)))).ToList();
7575

7676
cData.Sort(delegate (Tuple<Point, double> d1, Tuple<Point, double> d2)
7777
{
@@ -101,10 +101,10 @@ public static List<Point> SortAlongCurve(this List<Point> points, Ellipse ellips
101101
return null;
102102

103103
if (ellipse.Radius1 <= distanceTolerance && ellipse.Radius2 <= distanceTolerance)
104-
return points.Select(p => p.DeepClone()).ToList();
104+
return points;
105105

106106
//Could be optimised to avoid the mutliple calls to closest point (avoiding the additional call made by ParameterAtPoint, but mimicing how the other methods are running for now.
107-
List<Tuple<Point, double>> cData = points.Select(p => new Tuple<Point, double>(p.DeepClone(), ellipse.ParameterAtPoint(ellipse.ClosestPoint(p, distanceTolerance), distanceTolerance))).ToList();
107+
List<Tuple<Point, double>> cData = points.Select(p => new Tuple<Point, double>(p, ellipse.ParameterAtPoint(ellipse.ClosestPoint(p, distanceTolerance), distanceTolerance))).ToList();
108108

109109
cData.Sort(delegate (Tuple<Point, double> d1, Tuple<Point, double> d2)
110110
{
@@ -125,10 +125,10 @@ public static List<Point> SortAlongCurve(this List<Point> points, Ellipse ellips
125125
public static List<Point> SortAlongCurve(this List<Point> points, Line line, double distanceTolerance = Tolerance.Distance, double angleTolerance = Tolerance.Angle)
126126
{
127127
if (line.Length() <= distanceTolerance)
128-
return points.Select(p => p.DeepClone()).ToList();
128+
return points;
129129

130130
Vector lDir = line.Direction();
131-
List<Tuple<Point, Point>> cData = points.Select(p => new Tuple<Point, Point>(p.DeepClone(), (p.Project(line)))).ToList();
131+
List<Tuple<Point, Point>> cData = points.Select(p => new Tuple<Point, Point>(p, (p.Project(line)))).ToList();
132132

133133
if ((Math.Abs(lDir.X)) > angleTolerance)
134134
{
@@ -174,8 +174,7 @@ public static List<Point> SortAlongCurve(this List<Point> points, Line line, dou
174174
[Output("sortedPts", "The provided points sorted along the curve.")]
175175
public static List<Point> SortAlongCurve(this List<Point> points, PolyCurve curve, double tolerance = Tolerance.Distance, double angleTolerance = Tolerance.Angle)
176176
{
177-
178-
List<Tuple<Point, double>> cData = points.Select(p => new Tuple<Point, double>(p.DeepClone(), curve.ParameterAtPoint(curve.ClosestPoint(p)))).ToList();
177+
List<Tuple<Point, double>> cData = points.Select(p => new Tuple<Point, double>(p, curve.ParameterAtPoint(curve.ClosestPoint(p)))).ToList();
179178

180179
cData.Sort(delegate (Tuple<Point, double> d1, Tuple<Point, double> d2)
181180
{

Geometry_Engine/Compute/SortCollinear.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static partial class Compute
3636

3737
public static List<Point> SortCollinear(this List<Point> points, double tolerance = Tolerance.Distance)
3838
{
39-
List<Point> cPoints = points.Select(p => p.DeepClone()).ToList();
39+
List<Point> cPoints = points.ToList();
4040
for (int i = 1; i < cPoints.Count; i++)
4141
{
4242
if (Math.Abs(cPoints[0].X - cPoints[i].X) > tolerance)

Geometry_Engine/Compute/WetBlanketInterpretation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static partial class Compute
4343
[Output("C", "A single Polyline oriented counter clockwise with the same area as the sum of all the polylines.")]
4444
public static Polyline WetBlanketInterpretation(List<Polyline> pLines, double tol = Tolerance.Distance)
4545
{
46-
List<Polyline> clones = pLines.Select(x => x.RemoveShortSegments(tol, tol).DeepClone()).ToList();
46+
List<Polyline> clones = pLines.Select(x => x.RemoveShortSegments(tol, tol)).ToList();
4747

4848
int digits = (int)Math.Floor(-Math.Log10(tol));
4949

Geometry_Engine/Convert/NurbsForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static NurbsCurve ToNurbsCurve(this Line line)
150150

151151
public static NurbsCurve ToNurbsCurve(this NurbsCurve curve)
152152
{
153-
return curve.DeepClone();
153+
return curve;
154154
}
155155

156156
/***************************************************/

Geometry_Engine/Create/Plane.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static Plane Plane(Point origin, Vector normal)
5454
public static Plane Plane(Point p1, Point p2, Point p3)
5555
{
5656
Vector normal = Query.CrossProduct(p2 - p1, p3 - p1).Normalise();
57-
return new Plane { Origin = p1.DeepClone(), Normal = normal };
57+
return new Plane { Origin = p1, Normal = normal };
5858
}
5959

6060

Geometry_Engine/Modify/CollapseToPolyline.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static Polyline CollapseToPolyline(this Line curve, double angleTolerance
5858

5959
public static Polyline CollapseToPolyline(this Polyline curve, double angleTolerance, int maxSegmentCount = 100)
6060
{
61-
return curve.DeepClone();
61+
return new Polyline { ControlPoints = curve.ControlPoints.ToList() };
6262
}
6363

6464
/***************************************************/
@@ -158,7 +158,7 @@ private static List<Point> CollapseToPolylineVertices(this Line curve, double an
158158

159159
private static List<Point> CollapseToPolylineVertices(this Polyline curve, double angleTolerance, int maxSegmentCount = 100)
160160
{
161-
return curve.ControlPoints.Select(p => p.DeepClone()).ToList();
161+
return curve.ControlPoints.ToList();
162162
}
163163

164164
/***************************************************/

Geometry_Engine/Modify/Mirror.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public static PolySurface Mirror(this PolySurface surface, Plane p)
198198

199199
public static Mesh Mirror(this Mesh mesh, Plane p)
200200
{
201-
return new Mesh { Vertices = mesh.Vertices.Select(x => x.Mirror(p)).ToList(), Faces = mesh.Faces.Select(x => x.DeepClone()).ToList() };
201+
return new Mesh { Vertices = mesh.Vertices.Select(x => x.Mirror(p)).ToList(), Faces = mesh.Faces.ToList() };
202202
}
203203

204204
/***************************************************/

Geometry_Engine/Modify/Normalise.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static Vector Normalise(this Vector vector)
4040
double d = Math.Sqrt(x * x + y * y + z * z);
4141

4242
if (d == 0)
43-
return vector.DeepClone();
43+
return vector;
4444

4545
return new Vector { X = x / d, Y = y / d, Z = z / d };
4646
}

Geometry_Engine/Modify/Project.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static ICurve Project(this Arc arc, Plane p)
103103
public static ICurve Project(this Circle circle, Plane p)
104104
{
105105
if (circle.Normal.IsParallel(p.Normal) != 0)
106-
return new Circle { Centre = circle.Centre.Project(p), Normal = circle.Normal.DeepClone(), Radius = circle.Radius };
106+
return new Circle { Centre = circle.Centre.Project(p), Normal = circle.Normal, Radius = circle.Radius };
107107

108108
Vector axis1 = p.Normal.CrossProduct(circle.Normal);
109109
Vector axis2 = axis1.CrossProduct(p.Normal);
@@ -210,7 +210,7 @@ public static PolySurface Project(this PolySurface surface, Plane p)
210210

211211
public static Mesh Project(this Mesh mesh, Plane p)
212212
{
213-
return new Mesh { Vertices = mesh.Vertices.Select(x => x.Project(p)).ToList(), Faces = mesh.Faces.Select(x => x.DeepClone()).ToList() };
213+
return new Mesh { Vertices = mesh.Vertices.Select(x => x.Project(p)).ToList(), Faces = mesh.Faces.ToList() };
214214
}
215215

216216
/***************************************************/

Geometry_Engine/Modify/ProjectAlong.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static ICurve ProjectAlong(this Arc arc, Plane plane, Vector vector)
8080
public static ICurve ProjectAlong(this Circle circle, Plane plane, Vector vector)
8181
{
8282
if (circle.Normal.IsParallel(plane.Normal) != 0)
83-
return new Circle { Centre = circle.Centre.ProjectAlong(plane, vector), Normal = circle.Normal.DeepClone(), Radius = circle.Radius };
83+
return new Circle { Centre = circle.Centre.ProjectAlong(plane, vector), Normal = circle.Normal, Radius = circle.Radius };
8484

8585
TransformMatrix project = Create.ProjectionMatrix(plane, vector);
8686
return circle.Transform(project);
@@ -186,7 +186,7 @@ public static PolySurface ProjectAlong(this PolySurface surface, Plane plane, Ve
186186

187187
public static Mesh ProjectAlong(this Mesh mesh, Plane plane, Vector vector)
188188
{
189-
return new Mesh { Vertices = mesh.Vertices.Select(x => x.ProjectAlong(plane, vector)).ToList(), Faces = mesh.Faces.Select(x => x.DeepClone()).ToList() };
189+
return new Mesh { Vertices = mesh.Vertices.Select(x => x.ProjectAlong(plane, vector)).ToList(), Faces = mesh.Faces.ToList() };
190190
}
191191

192192
/***************************************************/

Geometry_Engine/Modify/SetGeometry.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,56 +33,56 @@ public static partial class Modify
3333

3434
public static Point SetGeometry(this Point point, Point newPoint)
3535
{
36-
return newPoint.DeepClone();
36+
return newPoint;
3737
}
3838

3939
/***************************************************/
4040

4141
public static ICurve SetGeometry(this Line curve, ICurve newCurve)
4242
{
43-
return newCurve.DeepClone();
43+
return newCurve;
4444
}
4545

4646
/***************************************************/
4747

4848
public static ICurve SetGeometry(this Arc curve, ICurve newCurve)
4949
{
50-
return newCurve.DeepClone();
50+
return newCurve;
5151
}
5252

5353
/***************************************************/
5454

5555
public static ICurve SetGeometry(this Circle curve, ICurve newCurve)
5656
{
57-
return newCurve.DeepClone();
57+
return newCurve;
5858
}
5959

6060
/***************************************************/
6161

6262
public static ICurve SetGeometry(this Ellipse curve, ICurve newCurve)
6363
{
64-
return newCurve.DeepClone();
64+
return newCurve;
6565
}
6666

6767
/***************************************************/
6868

6969
public static ICurve SetGeometry(this NurbsCurve curve, ICurve newCurve)
7070
{
71-
return newCurve.DeepClone();
71+
return newCurve;
7272
}
7373

7474
/***************************************************/
7575

7676
public static ICurve SetGeometry(this Polyline curve, ICurve newCurve)
7777
{
78-
return newCurve.DeepClone();
78+
return newCurve;
7979
}
8080

8181
/***************************************************/
8282

8383
public static ICurve SetGeometry(this PolyCurve curve, ICurve newCurve)
8484
{
85-
return newCurve.DeepClone();
85+
return newCurve ;
8686
}
8787

8888
/***************************************************/

Geometry_Engine/Modify/SortCurves.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public static partial class Modify
3737
public static PolyCurve SortCurves(this PolyCurve curve, double tolerance = Tolerance.Distance)
3838
{
3939
if (curve.Curves.Count < 2)
40-
return curve.DeepClone();
40+
return curve;
4141

42-
List<ICurve> pending = curve.Curves.Select(x => x.DeepClone()).ToList();
42+
List<ICurve> pending = curve.Curves.ToList();
4343
PolyCurve result = new PolyCurve { Curves = new List<ICurve> { pending[0] } };
4444
pending.RemoveAt(0);
4545

0 commit comments

Comments
 (0)