Skip to content

Commit

Permalink
Merge pull request #200 from FriendsOfCADability/RemoveAllEdgesIterated
Browse files Browse the repository at this point in the history
Remove obsolete Face.AllEdgesIterated()
  • Loading branch information
dsn27 authored Dec 17, 2024
2 parents d9e7aea + f6e8f2c commit 049d21a
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 118 deletions.
86 changes: 43 additions & 43 deletions CADability/BRepIntersection.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions CADability/Constr3DScrewPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Constr3DScrewPath(GeoObjectList selectedObjects)
// here we could directely set shape and plane
}
clones.Clear();
foreach (Edge edg in (selectedObjects[0] as Face).AllEdgesIterated())
foreach (Edge edg in (selectedObjects[0] as Face).Edges)
{
if (edg.Curve3D != null) clones.Add(edg.Curve3D as IGeoObject);
}
Expand Down Expand Up @@ -87,7 +87,7 @@ static public bool canUseList(GeoObjectList selectedObjects)
{
if ((selectedObjects[0] as Face).Surface is PlaneSurface) return true;
clones.Clear();
foreach (Edge edg in (selectedObjects[0] as Face).AllEdgesIterated())
foreach (Edge edg in (selectedObjects[0] as Face).Edges)
{
if (edg.Curve3D != null) clones.Add(edg.Curve3D as IGeoObject);
}
Expand Down
68 changes: 25 additions & 43 deletions CADability/Face.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3509,7 +3509,7 @@ internal static Face MakeFace(ISurface surface, Edge[] outline)
res.outline = outline;
res.holes = new Edge[0][]; // keine Löcher
SimpleShape forceArea = res.Area; // das SimpleShape wird hier erstmalig berechnet
foreach (Edge edge in res.AllEdgesIterated())
foreach (Edge edge in res.Edges)
{
if (edge.Curve3D is IGeoObject go) go.Style = EdgeStyle;
}
Expand Down Expand Up @@ -3751,7 +3751,7 @@ internal void RemoveEdge(Edge edge, bool mayHaveDifferntVertices = false)
#endif
public void FreeCachedMemory()
{
foreach (Edge edge in AllEdgesIterated())
foreach (Edge edge in Edges)
{
edge.FreeCachedMemory();
}
Expand Down Expand Up @@ -4287,38 +4287,20 @@ public Edge[] AllEdges
return res.ToArray();
}
}
[Obsolete("renamed to Edges")]
public IEnumerable<Edge> AllEdgesIterated()
{
for (int i = 0; i < outline.Length; ++i)
{
yield return outline[i];
}
for (int i = 0; i < holes.Length; i++)
{
for (int j = 0; j < holes[i].Length; ++j)
{
yield return holes[i][j];
}
}
}

public IEnumerable<Edge> Edges
{
get
{
for (int i = 0; i < outline.Length; ++i)
{
yield return outline[i];
}
for (int i = 0; i < holes.Length; i++)
{
for (int j = 0; j < holes[i].Length; ++j)
{
yield return holes[i][j];
}
}
foreach (var edge in outline)
yield return edge;

foreach (var hole in holes)
foreach (var edge in hole)
yield return edge;
}
}

public Set<Edge> AllEdgesSet
{
get
Expand Down Expand Up @@ -4480,7 +4462,7 @@ internal List<Edge> FindEdges(GeoPoint2D uv)
{ // find the edge(s) that are close to this 2d point on the surface
List<Edge> res = new List<Edge>();
GeoPoint p = Surface.PointAt(uv);
foreach (Edge edg in AllEdgesIterated())
foreach (Edge edg in Edges)
{
ICurve2D c2d = edg.Curve2D(this);
double d = c2d.MinDistance(uv);
Expand Down Expand Up @@ -4808,7 +4790,7 @@ internal void SubstitudeEdge(Edge oldEdge, Edge newEgde)

private Edge findEdgeFromCurve2D(double precision, ICurve2D c2d)
{ // suche die Kante, die c2d entspricht. c2d kann auch nur ein Teil der Kante sein oder auch garnicht zu den Kanten gehören (aber dann nicht schneiden
foreach (Edge edg in AllEdgesIterated())
foreach (Edge edg in Edges)
{
ICurve2D e2d = edg.Curve2D(this);
double d = Math.Abs(e2d.MinDistance(c2d.StartPoint));
Expand Down Expand Up @@ -5279,7 +5261,7 @@ internal bool Simplify(double precision)
//bounds.Top = double.MaxValue;
}
canonical.SetBounds(bounds); // need finite bounds for boxedsurface
foreach (Edge edg in AllEdgesIterated())
foreach (Edge edg in Edges)
{
if (edg.Curve3D != null)
{
Expand Down Expand Up @@ -7392,7 +7374,7 @@ public double Distance(GeoPoint fromHere)
if (res == double.MaxValue)
{ // wenn es einen Fußpunkt auf die Fläche gibt, dann ist der näher als die Kanten
// stimmt das im Allgemeinen???
foreach (Edge edg in AllEdgesIterated())
foreach (Edge edg in Edges)
{
if (edg.Curve3D != null)
{
Expand Down Expand Up @@ -8546,7 +8528,7 @@ public bool MakeRegularSurface(double maxError)
ModOp2D modify;
if ((surface as NurbsSurface).GetSimpleSurface(maxError, out simpleSurface, out modify))
{
foreach (Edge edge in AllEdgesIterated())
foreach (Edge edge in Edges)
{
if (edge.PrimaryFace == this)
{
Expand Down Expand Up @@ -8574,7 +8556,7 @@ internal ModOp2D MakeRegularSurface(double maxError, Set<Edge> recalcEdges)
if ((surface as NurbsSurface).GetSimpleSurface(maxError, out simpleSurface, out modify))
{ // die Kanten werden grundlegend neu berechnet, die 2D Kurven werden neu gemacht, es ist hier also
// keine Modifikation der 2D Kurven nötig.
recalcEdges.AddMany(AllEdgesIterated());
recalcEdges.AddMany(Edges);
this.surface = simpleSurface;
this.area = null; // aber noch nicht neu berechnen
return modify;
Expand Down Expand Up @@ -8634,7 +8616,7 @@ internal void IntersectAndPosition(Edge edg, out GeoPoint[] ip, out GeoPoint2D[]
}
if (!added)
{ // BRepOperation needs the point if it is close egnough to an edge
foreach (Edge edge in AllEdgesIterated())
foreach (Edge edge in Edges)
{
if (edge.Curve3D != null)
{
Expand Down Expand Up @@ -8756,7 +8738,7 @@ internal void CollectConnectedFaces(HashSet<Face> collection, ICollection<Edge>
if (!collection.Contains(this))
{
collection.Add(this);
foreach (Edge edge in AllEdgesIterated())
foreach (Edge edge in Edges)
{
if (!bounds.Contains(edge)) edge.OtherFace(this).CollectConnectedFaces(collection, bounds);
}
Expand Down Expand Up @@ -8958,7 +8940,7 @@ public void ReverseOrientation()
{
vtx.RemovePositionOnFace(this);
}
foreach (Edge edg in AllEdgesIterated())
foreach (Edge edg in Edges)
{
edg.Orient(); // ModifyCurve2D unsets the "oriented"-Flag of the edge. Maybe the edge has already been oriented, so ReverseOrientation(this) doesn't help
if (edg.Curve3D is InterpolatedDualSurfaceCurve)
Expand Down Expand Up @@ -9034,7 +9016,7 @@ internal void MakeInverseOrientation()
{
ReverseOrientation(); // das ist identisch mit diesem hier!!
return;

//Unreachable code
/*
SimpleShape ss = Area;
Expand Down Expand Up @@ -9881,7 +9863,7 @@ internal bool UseEdge(Edge toUse)
if (toUse.Curve3D == null) return false;
GeoPoint startPoint = toUse.Curve3D.StartPoint;
GeoPoint endPoint = toUse.Curve3D.EndPoint;
foreach (Edge edg in AllEdgesIterated())
foreach (Edge edg in Edges)
{
if ((edg.Vertex1.Position | startPoint) + (edg.Vertex2.Position | endPoint) < Precision.eps || (edg.Vertex2.Position | startPoint) + (edg.Vertex1.Position | endPoint) < Precision.eps)
{
Expand Down Expand Up @@ -10233,8 +10215,8 @@ internal Set<Edge> CombineWith(Face other, ModOp2D toOtherSurface)
Vertex[] dbg1 = this.Vertices;
Vertex[] dbg2 = other.Vertices;

Set<Edge> onThis = new Set<Edge>(AllEdgesIterated());
Set<Edge> onOther = new Set<Edge>(other.AllEdgesIterated());
Set<Edge> onThis = new Set<Edge>(Edges);
Set<Edge> onOther = new Set<Edge>(other.Edges);
Set<Edge> usableEdges = onThis.SymmetricDifference(onOther); // all edges of the resulting face, which belong to one of the faces but not to both
Set<Edge> commonEdges = onThis.Intersection(onOther); // these will be removed
List<List<Edge>> loops = new List<List<Edge>>(); // the loops, one of them is the outline, the others are holes
Expand Down Expand Up @@ -10544,7 +10526,7 @@ internal bool CheckConsistency()

public bool IsConnectedWith(Face fc1)
{
foreach (Edge edge in AllEdgesIterated())
foreach (Edge edge in Edges)
{
if (edge.PrimaryFace == this && edge.SecondaryFace == fc1) return true;
if (edge.SecondaryFace == this && edge.PrimaryFace == fc1) return true;
Expand Down Expand Up @@ -10834,7 +10816,7 @@ public static bool ConnectTwoFaces(Face face1, Face face2, double precision)
// collect pairs of edge, which are geomatrically identical
// we collect the edges rather than combining them immediately, because we are iterating over the edges
List<Pair<Edge, Edge>> edgePairs = new List<Pair<Edge, Edge>>();
foreach (Edge edg in face1.AllEdgesIterated())
foreach (Edge edg in face1.Edges)
{
if (vertexPairs.ContainsKey(edg.Vertex1) && vertexPairs.ContainsKey(edg.Vertex2))
{
Expand Down
2 changes: 1 addition & 1 deletion CADability/ImportStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2894,7 +2894,7 @@ private object CreateEntity(Item item)
//if (2859 == item.definingIndex || 3219 == item.definingIndex)
// (item.val as Face[])[i].AssureTriangles(0.004); // remove when done

//foreach (Edge edg in (item.val as Face[])[i].AllEdgesIterated())
//foreach (Edge edg in (item.val as Face[])[i].Edges)
//{
// if (edg.PrimaryFace != (item.val as Face[])[i]) edg.PrimaryFace.CheckConsistency();
// if (edg.SecondaryFace != null && edg.SecondaryFace != (item.val as Face[])[i]) edg.SecondaryFace.CheckConsistency();
Expand Down
10 changes: 5 additions & 5 deletions CADability/Make3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1585,15 +1585,15 @@ internal static Solid MakeHelicalSolid(GeoPoint2D axisLocation, Plane plane, Pat

// make the bottom and the top cover to close the solid
Edge e0 = null, e1 = null;
foreach (Edge edg in fc0.AllEdgesIterated())
foreach (Edge edg in fc0.Edges)
{
if (edg.Curve3D is Ellipse)
{
e0 = edg;
break;
}
}
foreach (Edge edg in fc1.AllEdgesIterated())
foreach (Edge edg in fc1.Edges)
{
if (edg.Curve3D is Ellipse)
{
Expand All @@ -1609,15 +1609,15 @@ internal static Solid MakeHelicalSolid(GeoPoint2D axisLocation, Plane plane, Pat
faces.Add(bfc);

Edge e2 = null, e3 = null;
foreach (Edge edg in fc2.AllEdgesIterated())
foreach (Edge edg in fc2.Edges)
{
if (edg.Curve3D is Ellipse)
{
e2 = edg;
break;
}
}
foreach (Edge edg in fc3.AllEdgesIterated())
foreach (Edge edg in fc3.Edges)
{
if (edg.Curve3D is Ellipse)
{
Expand Down Expand Up @@ -1930,7 +1930,7 @@ private static void extractConnectedFaces(Set<Face> allFaces, Face startWith, Se
{
result.Add(startWith);
allFaces.Remove(startWith);
foreach (Edge edge in startWith.AllEdgesIterated())
foreach (Edge edge in startWith.Edges)
{
if (allFaces.Contains(edge.PrimaryFace))
{
Expand Down
20 changes: 10 additions & 10 deletions CADability/Parametric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal void OffsetFaces(IEnumerable<Face> faces, double offset)
if (!faceDict.TryGetValue(face, out Face faceToMove)) faceToMove = face; // toMove may be from the original shell or from the cloned shell
modifiedFaces.Add(faceToMove);
ISurface offsetSurface = faceToMove.Surface.GetOffsetSurface(offset);
foreach (Edge edge in faceToMove.AllEdgesIterated())
foreach (Edge edge in faceToMove.Edges)
{ // tangential edges must connect two of the provided faces, so they appear twice here
if (edge.IsTangentialEdge() && !tangentialEdgesModified.ContainsKey(edge))
{
Expand Down Expand Up @@ -105,7 +105,7 @@ public void MoveFaces(Dictionary<Face, GeoVector> toMove, GeoVector mainMovement
else
{
modifiedFaces.Add(faceToMove);
foreach (Edge edge in faceToMove.AllEdgesIterated())
foreach (Edge edge in faceToMove.Edges)
{
Face otherFace = edge.OtherFace(faceToMove);
bool tangential = edge.IsTangentialEdge();
Expand Down Expand Up @@ -235,7 +235,7 @@ public bool ModifyRadius(IEnumerable<Face> toModify, double newRadius)

// HashSet<Face> lengthwayTangential = new HashSet<Face>(); // the two faces that this fillet rounds
// HashSet<Edge> crosswayTangential = new HashSet<Edge>(); // the following or previous fillet
// foreach (Edge edge in faceToModify.AllEdgesIterated())
// foreach (Edge edge in faceToModify.Edges)
// {
// Face otherFace = edge.OtherFace(faceToModify);
// if (edge.IsTangentialEdge())
Expand Down Expand Up @@ -275,7 +275,7 @@ public bool ModifyRadius(IEnumerable<Face> toModify, double newRadius)
// modifiedFaces.Add(faceToModify);
// // this modified face is tangential to t[0] and t[1]. The edges between this faceToModify and t[0] resp. t[1] need to be recalculated
// // in order to have a curve for recalculating the vertices in Result()
// foreach (Edge edg in faceToModify.AllEdgesIterated())
// foreach (Edge edg in faceToModify.Edges)
// {
// for (int i = 0; i < 2; i++)
// {
Expand Down Expand Up @@ -323,7 +323,7 @@ private void followCrosswayTangential(Edge edge, ICurve axis, double newRadius)
}
modifiedFaces.Add(faceToModify);
// follow the crossway tangential faces
foreach (Edge edg in faceToModify.AllEdgesIterated())
foreach (Edge edg in faceToModify.Edges)
{
Face otherFace = edge.OtherFace(faceToModify);
if (edg.IsTangentialEdge())
Expand All @@ -347,7 +347,7 @@ private void CollectSameSurfaceFaces(Face face, HashSet<Face> sameSurfaceFaces,
{
if (sameSurfaceFaces.Contains(face)) return; // already tested
sameSurfaceFaces.Add(face);
foreach (Edge edge in face.AllEdgesIterated())
foreach (Edge edge in face.Edges)
{
Face otherFace = edge.OtherFace(face);
if (edge.IsTangentialEdge())
Expand Down Expand Up @@ -383,7 +383,7 @@ public bool ModifyFilletRadius(Face[] toModify, double newRadius)
ICurve axis = extrusion.Axis(faceToModify.Domain); // a line for a cylinder, an arc for a torus, some 3d curve for a swept curve
HashSet<Face> lengthwayTangential = new HashSet<Face>(); // the two faces that this fillet rounds
HashSet<Edge> crosswayTangential = new HashSet<Edge>(); // the following or previous fillet
foreach (Edge edge in faceToModify.AllEdgesIterated())
foreach (Edge edge in faceToModify.Edges)
{
Face otherFace = edge.OtherFace(faceToModify);
if (edge.IsTangentialEdge())
Expand Down Expand Up @@ -420,7 +420,7 @@ public bool ModifyFilletRadius(Face[] toModify, double newRadius)
modifiedFaces.Add(faceToModify);
// this modified face is tangential to t[0] and t[1]. The edges between this faceToModify and t[0] resp. t[1] need to be recalculated
// in order to have a curve for recalculating the vertices in Result()
foreach (Edge edg in faceToModify.AllEdgesIterated())
foreach (Edge edg in faceToModify.Edges)
{
for (int i = 0; i < 2; i++)
{
Expand Down Expand Up @@ -454,7 +454,7 @@ public bool ModifyFilletRadius(Face[] toModify, double newRadius)
ICurve axis = (cyl as ICylinder).Axis.Clip(faceToModify.GetExtent(0.0)); // the axis as a clipped line
HashSet<Face> lengthwayTangential = new HashSet<Face>(); // the two faces that this fillet rounds
HashSet<Edge> crosswayTangential = new HashSet<Edge>(); // the following or previous fillet
foreach (Edge edge in faceToModify.AllEdgesIterated())
foreach (Edge edge in faceToModify.Edges)
{
Face otherFace = edge.OtherFace(faceToModify);
if (edge.IsTangentialEdge())
Expand Down Expand Up @@ -495,7 +495,7 @@ public bool ModifyFilletRadius(Face[] toModify, double newRadius)
// in order to have a curve for recalculating the vertices in Result()
for (int i = 0; i < t.Length; i++)
{
foreach (Edge edg in faceToModify.AllEdgesIterated())
foreach (Edge edg in faceToModify.Edges)
{
if (edg.OtherFace(faceToModify) == t[i])
{
Expand Down
6 changes: 3 additions & 3 deletions CADability/RemoveFillet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Shell Result()
{
if (face.Surface is ISurfaceOfArcExtrusion extrusion)
{
foreach (Edge edge in face.AllEdgesIterated())
foreach (Edge edge in face.Edges)
{
Face otherFace = edge.OtherFace(face);
if (edge.IsTangentialEdge() && edge.Curve2D(face).DirectionAt(0.5).IsMoreHorizontal != extrusion.ExtrusionDirectionIsV)
Expand All @@ -52,7 +52,7 @@ public Shell Result()
}
else if (face.Surface is SphericalSurface)
{
foreach (Edge edge in face.AllEdgesIterated())
foreach (Edge edge in face.Edges)
{
Face otherFace = edge.OtherFace(face);
if (fillets.Contains(otherFace)) crossway.Add(edge);
Expand Down Expand Up @@ -219,7 +219,7 @@ public Shell Result()
foreach (Face face in shell.Faces)
{
if (fillets.Contains(face)) continue;
foreach (Edge edge in face.AllEdgesIterated())
foreach (Edge edge in face.Edges)
{
if (verticesToReplace.ContainsKey(edge.Vertex1))
{
Expand Down
Loading

0 comments on commit 049d21a

Please sign in to comment.