public static ICollection <Face> OffsetFaceEdgesInward(this Face face, double distance, OffsetCornerType offsetCornerType) { if (!(face.Geometry is Plane)) { throw new ArgumentException("Face must be planar"); } Plane plane = (Plane)face.Geometry; ITrimmedCurve[] curves = face.Edges.ToArray(); ITrimmedCurve firstEdge = curves.First(); ITrimmedCurve[] otherEdges = curves.Skip(1).ToArray(); ICollection <ITrimmedCurve> offsetCurves = firstEdge.OffsetChain(plane, distance, otherEdges, offsetCornerType); if (offsetCurves.Count == 0) { return(null); } if (face.ContainsPoint(offsetCurves.First().StartPoint) ^ distance > 0) { return(DoInWriteBlock <ICollection <Face> >(() => Body.CreatePlanarBody(plane, offsetCurves).SeparatePieces().Select(b => b.Faces.First()).ToList())); } offsetCurves = firstEdge.OffsetChain(plane, -distance, otherEdges, offsetCornerType); if (offsetCurves.Count == 0) { return(null); } return(Body.CreatePlanarBody(plane, offsetCurves).SeparatePieces().Select(b => b.Faces.First()).ToList()); }
public static ICollection <ITrimmedCurve> OffsetChainInward(this ICollection <ITrimmedCurve> curves, Face face, double distance, OffsetCornerType offsetCornerType) { if (!(face.Geometry is Plane)) { throw new ArgumentException("Face must be planar"); } Plane plane = (Plane)face.Geometry; ITrimmedCurve firstEdge = curves.First(); ITrimmedCurve[] otherEdges = curves.Skip(1).ToArray(); ICollection <ITrimmedCurve> offsetCurves = firstEdge.OffsetChain(plane, distance, otherEdges, offsetCornerType); if (offsetCurves.Count == 0) { return(new ITrimmedCurve[0]); } if (face.ContainsPoint(offsetCurves.First().StartPoint) ^ distance > 0) { return(offsetCurves); } offsetCurves = firstEdge.OffsetChain(plane, -distance, otherEdges, offsetCornerType); if (offsetCurves.Count == 0) { return(new ITrimmedCurve[0]); } return(offsetCurves); }
public static ICollection <ITrimmedCurve> OffsetChainInward(this ICollection <ITrimmedCurve> curves, Plane plane, double distance, OffsetCornerType offsetCornerType) { ITrimmedCurve firstEdge = curves.First(); ITrimmedCurve[] otherEdges = curves.Skip(1).ToArray(); ICollection <ITrimmedCurve> offsetCurvesA = firstEdge.OffsetChain(plane, distance, otherEdges, offsetCornerType); ICollection <ITrimmedCurve> offsetCurvesB = firstEdge.OffsetChain(plane, -distance, otherEdges, offsetCornerType); if (offsetCurvesA.Count == 0 || offsetCurvesB.Count == 0) { return(new ITrimmedCurve[0]); } if (offsetCurvesA.Select(c => c.Length).Sum() < offsetCurvesB.Select(c => c.Length).Sum()) { return(offsetCurvesA); } else { return(offsetCurvesB); } }
private static ICollection <ITrimmedCurve> OffsetChainInwardWithInnerLoops(Face face, double distance, OffsetCornerType offsetCornerType, ITrimmedCurve[] outerLoop, List <ITrimmedCurve[]> innerLoops) { if (!(face.Geometry is Plane)) { throw new ArgumentException("Face must be planar"); } Plane plane = (Plane)face.Geometry; Body outerBody = null; try { outerBody = Body.CreatePlanarBody(plane, outerLoop.OffsetChainInward(plane, distance, offsetCornerType)); } catch { return(null); } Body[] innerBodies = innerLoops.Select(l => Body.CreatePlanarBody(plane, outerLoop.OffsetChainInward(plane, -distance, offsetCornerType))).ToArray(); try { outerBody.Subtract(innerBodies); } catch { return(null); } if (outerBody == null) { return(null); } return(outerBody.Edges.Cast <ITrimmedCurve>().ToArray()); }
public static ICollection <ITrimmedCurve> OffsetAllLoops(this Face face, double distance, OffsetCornerType offsetCornerType) { Plane plane; ITrimmedCurve[] outerLoop = null; var innerLoops = new List <ITrimmedCurve[]>(); plane = face.Geometry as Plane; if (plane == null) { throw new NotImplementedException(); } Debug.Assert(face.Loops.Where(l => l.IsOuter).Count() == 1, "Multiple outer loops not implemented"); foreach (Loop loop in face.Loops) { if (loop.IsOuter) { outerLoop = loop.Edges.ToArray(); } else { innerLoops.Add(loop.Edges.ToArray()); } } if (innerLoops.Count == 0) { return(outerLoop.OffsetChainInward(plane, distance, offsetCornerType)); } throw new NotImplementedException(); // DTR throws exception in SpaceClaim return(DoInWriteBlock <ICollection <ITrimmedCurve> >(() => OffsetChainInwardWithInnerLoops(face, distance, offsetCornerType, outerLoop, innerLoops))); }
public static ICollection <ITrimmedCurve> OffsetAllLoops(this ICollection <ITrimmedCurve> curves, Plane plane, double distance, OffsetCornerType offsetCornerType) { Body body = Body.CreatePlanarBody(plane, curves); Debug.Assert(body.Faces.Count == 1); Face face = body.Faces.First(); return(face.OffsetAllLoops(distance, offsetCornerType)); }