Beispiel #1
0
        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());
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public static ICollection <ITrimmedCurve> OffsetTowards(this ICollection <ITrimmedCurve> curves, Point point, Plane plane, double distance)
        {
            ITrimmedCurve firstCurve = curves.First();

            ITrimmedCurve[] otherCurves = curves.Skip(1).ToArray();

            bool isLeft = Vector.Dot(Vector.Cross(firstCurve.Geometry.Evaluate(0).Tangent.UnitVector, point - firstCurve.StartPoint), plane.Frame.DirZ.UnitVector) >= 0;

            return(firstCurve.OffsetChain(plane, (isLeft ? -1 : 1) * distance, otherCurves, OffsetCornerType.NaturalExtension));
        }
Beispiel #4
0
        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);
            }
        }