diff --git a/src/RhinoInside.Revit.External/Extensions/RhinoCommon.cs b/src/RhinoInside.Revit.External/Extensions/RhinoCommon.cs index 394edac60..a45d4a641 100644 --- a/src/RhinoInside.Revit.External/Extensions/RhinoCommon.cs +++ b/src/RhinoInside.Revit.External/Extensions/RhinoCommon.cs @@ -314,7 +314,7 @@ public PlanarBrepFace(BrepFace f) public NurbsCurve Loop { - get { if (Plane.IsValid && loop is null) loop = Curve.ProjectToPlane(Face.OuterLoop.To3dCurve()?.ToNurbsCurve(), Plane) as NurbsCurve; return loop; } + get { if (Plane.IsValid && loop is null) loop = Face.OuterLoop.To3dCurve().ProjectToPlane(Plane) as NurbsCurve; return loop; } } public Point3d Centroid { @@ -897,6 +897,40 @@ public static IEnumerable Discontinuities(this Curve curve, Continuity c while (curve.GetNextDiscontinuity(continuity, t, domain.T1, tol1, tol2, out t)) yield return t; } + + public static Curve ProjectToPlane(this Curve curve, Plane plane) + { + switch (curve) + { + case null: + return null; + + case LineCurve line: + line = line.DuplicateCurve() as LineCurve; + line.SetStartPoint(plane.ClosestPoint(line.PointAtStart)); + line.SetEndPoint(plane.ClosestPoint(line.PointAtEnd)); + return line; + + case PolylineCurve polyline: + polyline = polyline.DuplicateCurve() as PolylineCurve; + for(int p = 0; p < polyline.PointCount; ++p) + polyline.SetPoint(p, plane.ClosestPoint(polyline.Point(p))); + return polyline; + + case ArcCurve arc: + + if (arc.Arc.Plane.Normal.EpsilonEquals(plane.Normal, RhinoMath.Epsilon)) + { + arc = arc.DuplicateCurve() as ArcCurve; + arc.Translate(plane.ClosestPoint(arc.Arc.Plane.Origin) - arc.Arc.Plane.Origin); + return arc; + } + else return Curve.ProjectToPlane(curve?.ToNurbsCurve(), plane); + + default: + return Curve.ProjectToPlane(curve?.ToNurbsCurve(), plane); + } + } } static class SurfaceExtension diff --git a/src/RhinoInside.Revit.GH/Components/Annotations/AddDetailLine.cs b/src/RhinoInside.Revit.GH/Components/Annotations/AddDetailLine.cs index e2627cdc0..8ceb75123 100644 --- a/src/RhinoInside.Revit.GH/Components/Annotations/AddDetailLine.cs +++ b/src/RhinoInside.Revit.GH/Components/Annotations/AddDetailLine.cs @@ -82,7 +82,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA) var plane = view.DetailPlane; var tol = GeometryTolerance.Model; - if (Curve.ProjectToPlane(curve.ToNurbsCurve(), plane) is Curve projectedCurve) + if (curve.ProjectToPlane(plane) is Curve projectedCurve) curve = projectedCurve; else throw new Exceptions.RuntimeArgumentException("Curve", "Failed to project 'Curve' into view plane", curve); diff --git a/src/RhinoInside.Revit.GH/Components/Annotations/AddRegion.cs b/src/RhinoInside.Revit.GH/Components/Annotations/AddRegion.cs index 54583e073..814d1919e 100644 --- a/src/RhinoInside.Revit.GH/Components/Annotations/AddRegion.cs +++ b/src/RhinoInside.Revit.GH/Components/Annotations/AddRegion.cs @@ -117,7 +117,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA) throw new Exceptions.RuntimeArgumentException("Boundary", "Curve should be a valid planar, closed curve and parallel to the input view.", loop); } - loops = loops.Select(x => Curve.ProjectToPlane(x, viewPlane)).ToArray(); + loops = loops.Select(x => x.ProjectToPlane(viewPlane)).ToArray(); // Compute region = Reconstruct diff --git a/src/RhinoInside.Revit.GH/Components/Annotations/AddRevisionCloud.cs b/src/RhinoInside.Revit.GH/Components/Annotations/AddRevisionCloud.cs index 62b8e5701..7546b947c 100644 --- a/src/RhinoInside.Revit.GH/Components/Annotations/AddRevisionCloud.cs +++ b/src/RhinoInside.Revit.GH/Components/Annotations/AddRevisionCloud.cs @@ -105,7 +105,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA) throw new Exceptions.RuntimeArgumentException("Boundary", "Curve should be a valid planar, closed curve and perperdicular to the input view.", loop); } - loops = loops.Select(x => Curve.ProjectToPlane(x, viewPlane)).ToArray(); + loops = loops.Select(x => x.ProjectToPlane(viewPlane)).ToArray(); if (revision is null) { diff --git a/src/RhinoInside.Revit.GH/Components/Annotations/Datums/Grids/AddMultiSegmentGrid.cs b/src/RhinoInside.Revit.GH/Components/Annotations/Datums/Grids/AddMultiSegmentGrid.cs index e4ef851c1..d571ed8dc 100644 --- a/src/RhinoInside.Revit.GH/Components/Annotations/Datums/Grids/AddMultiSegmentGrid.cs +++ b/src/RhinoInside.Revit.GH/Components/Annotations/Datums/Grids/AddMultiSegmentGrid.cs @@ -150,7 +150,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA) var tol = GeometryTolerance.Model; var axisPlane = sketchPlane.Location; - curve = Curve.ProjectToPlane(curve, axisPlane); + curve = curve.ProjectToPlane(axisPlane); if (curve is null) throw new RuntimeArgumentException("Curve", "Failed to project Curve on to Work Plane.", curve); curve = curve.ToArcsAndLines(tol.VertexTolerance, 10.0 * tol.AngleTolerance, tol.ShortCurveTolerance, 0.0); diff --git a/src/RhinoInside.Revit.GH/Components/Annotations/ReferenceElements/AddReferenceLine.cs b/src/RhinoInside.Revit.GH/Components/Annotations/ReferenceElements/AddReferenceLine.cs index 521171e09..ae6b800cc 100644 --- a/src/RhinoInside.Revit.GH/Components/Annotations/ReferenceElements/AddReferenceLine.cs +++ b/src/RhinoInside.Revit.GH/Components/Annotations/ReferenceElements/AddReferenceLine.cs @@ -94,7 +94,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA) if (!curve.IsParallelToPlane(plane, tol.VertexTolerance, tol.AngleTolerance)) throw new Exceptions.RuntimeArgumentException("Curve", $"Curve should be planar and parallel to view plane.\nTolerance is {Rhino.RhinoMath.ToDegrees(tol.AngleTolerance):N1}°", curve); - if ((curve = Curve.ProjectToPlane(curve, plane)) is null) + if ((curve = curve.ProjectToPlane(plane)) is null) throw new Exceptions.RuntimeArgumentException("Curve", "Failed to project Curve into 'Work Plane'", curve); if (curve.IsClosed || curve.PointAtStart.DistanceTo(curve.PointAtEnd) < tol.VertexTolerance) diff --git a/src/RhinoInside.Revit.GH/Components/Element/HostObject/BoundaryProfile.cs b/src/RhinoInside.Revit.GH/Components/Element/HostObject/BoundaryProfile.cs index 5daf68c6e..3867de532 100644 --- a/src/RhinoInside.Revit.GH/Components/Element/HostObject/BoundaryProfile.cs +++ b/src/RhinoInside.Revit.GH/Components/Element/HostObject/BoundaryProfile.cs @@ -140,7 +140,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA) foreach (var profile in profiles.OfType()) { - var loop = Curve.ProjectToPlane(profile, projectionPlane); + var loop = profile.ProjectToPlane(projectionPlane); var segments = loop.TryGetPolyCurve(out var polyCurve, tol.AngleTolerance) ? polyCurve.DuplicateSegments() : new Curve[] { loop }; diff --git a/src/RhinoInside.Revit.GH/Components/Element/Opening/AddOpening.cs b/src/RhinoInside.Revit.GH/Components/Element/Opening/AddOpening.cs index 4a8f268a0..3b4734a7f 100755 --- a/src/RhinoInside.Revit.GH/Components/Element/Opening/AddOpening.cs +++ b/src/RhinoInside.Revit.GH/Components/Element/Opening/AddOpening.cs @@ -155,7 +155,7 @@ ARDB.Opening Reconstruct(ARDB.Opening opening, ARDB.Document doc, ARDB.HostObjec { var hostPlane = sketch.SketchPlane.GetPlane().ToPlane(); normal = hostPlane.Normal; - boundary = boundary.Select(x => Curve.ProjectToPlane(x, hostPlane)).ToArray(); + boundary = boundary.Select(x => x.ProjectToPlane(hostPlane)).ToArray(); } } diff --git a/src/RhinoInside.Revit.GH/Components/Element/Railing/ByCurve.cs b/src/RhinoInside.Revit.GH/Components/Element/Railing/ByCurve.cs index 5ff4681fc..f8d481f22 100644 --- a/src/RhinoInside.Revit.GH/Components/Element/Railing/ByCurve.cs +++ b/src/RhinoInside.Revit.GH/Components/Element/Railing/ByCurve.cs @@ -50,7 +50,7 @@ [Optional] bool flipped new Point3d(0.0, 0.0, level.Value.GetElevation() * GeometryDecoder.ModelScaleFactor), Vector3d.ZAxis ); - curve = Curve.ProjectToPlane(curve, levelPlane); + curve = curve.ProjectToPlane(levelPlane); curve = curve.Simplify(CurveSimplifyOptions.All & ~CurveSimplifyOptions.Merge, tol.VertexTolerance, tol.AngleTolerance) ?? curve; // Type diff --git a/src/RhinoInside.Revit.GH/Components/Model/AddModelLine.cs b/src/RhinoInside.Revit.GH/Components/Model/AddModelLine.cs index fc83fd7b9..9327838c5 100644 --- a/src/RhinoInside.Revit.GH/Components/Model/AddModelLine.cs +++ b/src/RhinoInside.Revit.GH/Components/Model/AddModelLine.cs @@ -96,7 +96,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA) var plane = sketchPlane.Location; var tol = GeometryTolerance.Model; - if (Curve.ProjectToPlane(curve.ToNurbsCurve(), plane) is Curve projectedCurve) + if (curve.ProjectToPlane(plane) is Curve projectedCurve) curve = projectedCurve; else throw new Exceptions.RuntimeArgumentException("Curve", "Failed to project 'Curve' into 'Work Plane'", curve); diff --git a/src/RhinoInside.Revit.GH/Components/Structure/AddAnalyticalPanel-Extrusion.cs b/src/RhinoInside.Revit.GH/Components/Structure/AddAnalyticalPanel-Extrusion.cs index 59c56fcfc..5b256c94e 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/AddAnalyticalPanel-Extrusion.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/AddAnalyticalPanel-Extrusion.cs @@ -121,7 +121,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA) var normal = default(ARDB.XYZ); if (plane.HasValue) { - curve = Curve.ProjectToPlane(curve, plane.Value) ?? curve; + curve = curve.ProjectToPlane(plane.Value) ?? curve; normal = plane.Value.Normal.ToXYZ(); } diff --git a/src/RhinoInside.Revit.GH/Components/Structure/AddBeamSystem.cs b/src/RhinoInside.Revit.GH/Components/Structure/AddBeamSystem.cs index 8dc1fed61..540caab31 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/AddBeamSystem.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/AddBeamSystem.cs @@ -140,7 +140,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA) is3D = true; if (!boundary[i].IsInPlane(sketchPlane.Location, tol.VertexTolerance)) - boundary[i] = Curve.ProjectToPlane(boundary[i], sketchPlane.Location); + boundary[i] = boundary[i].ProjectToPlane(sketchPlane.Location); boundaryElevation = Interval.FromUnion(boundaryElevation, new Interval(sketchPlane.Location.OriginZ, sketchPlane.Location.OriginZ)); } diff --git a/src/RhinoInside.Revit.GH/Components/Structure/AddTruss.cs b/src/RhinoInside.Revit.GH/Components/Structure/AddTruss.cs index 25bd5abbc..055bc5cf9 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/AddTruss.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/AddTruss.cs @@ -110,7 +110,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA) var tol = GeometryTolerance.Model; var plane = sketchPlane.Location; - if (Curve.ProjectToPlane(curve.ToNurbsCurve(), plane) is Curve projectedCurve) + if (curve.ProjectToPlane(plane) is Curve projectedCurve) curve = projectedCurve; else throw new Exceptions.RuntimeArgumentException("Curve", "Failed to project 'Curve' into 'Work Plane'", curve); diff --git a/src/RhinoInside.Revit.GH/Components/Topology/AddAreaBoundaryLine.cs b/src/RhinoInside.Revit.GH/Components/Topology/AddAreaBoundaryLine.cs index b4eb4b0bd..103add530 100644 --- a/src/RhinoInside.Revit.GH/Components/Topology/AddAreaBoundaryLine.cs +++ b/src/RhinoInside.Revit.GH/Components/Topology/AddAreaBoundaryLine.cs @@ -121,7 +121,7 @@ bool Reuse(ARDB.ModelCurve modelCurve, ARDB.ViewPlan view, Curve curve) using (var geometryCurve = modelCurve.GeometryCurve) { - using (var projectedCurve = Curve.ProjectToPlane(curve, levelPlane).ToCurve()) + using (var projectedCurve = curve.ProjectToPlane(levelPlane).ToCurve()) { if (!projectedCurve.IsSameKindAs(geometryCurve)) return false; if (!projectedCurve.AlmostEquals(geometryCurve, modelCurve.Document.Application.VertexTolerance)) @@ -137,7 +137,7 @@ ARDB.ModelCurve Create(ARDB.ViewPlan view, Curve curve) if (view.GenLevel is ARDB.Level level) { using (var sketchPlane = level.GetSketchPlane(ensureSketchPlane: true)) - using (var projectedCurve = Curve.ProjectToPlane(curve, sketchPlane.GetPlane().ToPlane())) + using (var projectedCurve = curve.ProjectToPlane(sketchPlane.GetPlane().ToPlane())) return view.Document.Create.NewAreaBoundaryLine(sketchPlane, projectedCurve.ToCurve(), view); } diff --git a/src/RhinoInside.Revit.GH/Components/Topology/AddRoomSeparatorLine.cs b/src/RhinoInside.Revit.GH/Components/Topology/AddRoomSeparatorLine.cs index 81e5802e1..ad635efa3 100644 --- a/src/RhinoInside.Revit.GH/Components/Topology/AddRoomSeparatorLine.cs +++ b/src/RhinoInside.Revit.GH/Components/Topology/AddRoomSeparatorLine.cs @@ -127,7 +127,7 @@ bool Reuse(ARDB.ModelCurve roomSeparator, ARDB.ViewPlan view, Curve curve) using (var geometryCurve = roomSeparator.GeometryCurve) { - using (var projectedCurve = Curve.ProjectToPlane(curve, levelPlane).ToCurve()) + using (var projectedCurve = curve.ProjectToPlane(levelPlane).ToCurve()) { if (!projectedCurve.IsSameKindAs(geometryCurve)) return false; if (!projectedCurve.AlmostEquals(geometryCurve, GeometryTolerance.Internal.VertexTolerance)) @@ -143,7 +143,7 @@ ARDB.ModelCurve Create(ARDB.ViewPlan view, Curve curve) if (view.GenLevel is ARDB.Level level) { using (var sketchPlane = level.GetSketchPlane(ensureSketchPlane: true)) - using (var projectedCurve = Curve.ProjectToPlane(curve, sketchPlane.GetPlane().ToPlane())) + using (var projectedCurve = curve.ProjectToPlane(sketchPlane.GetPlane().ToPlane())) using (var curveArray = new ARDB.CurveArray()) { curveArray.Append(projectedCurve.ToCurve()); diff --git a/src/RhinoInside.Revit.GH/Components/Topology/AddSpaceSeparatorLine.cs b/src/RhinoInside.Revit.GH/Components/Topology/AddSpaceSeparatorLine.cs index 1b9fbdf2e..77d25cb5e 100644 --- a/src/RhinoInside.Revit.GH/Components/Topology/AddSpaceSeparatorLine.cs +++ b/src/RhinoInside.Revit.GH/Components/Topology/AddSpaceSeparatorLine.cs @@ -126,7 +126,7 @@ bool Reuse(ARDB.ModelCurve spaceSeparator, ARDB.ViewPlan view, Curve curve) using (var geometryCurve = spaceSeparator.GeometryCurve) { - using (var projectedCurve = Curve.ProjectToPlane(curve, levelPlane).ToCurve()) + using (var projectedCurve = curve.ProjectToPlane(levelPlane).ToCurve()) { if (!projectedCurve.IsSameKindAs(geometryCurve)) return false; if (!projectedCurve.AlmostEquals(geometryCurve, GeometryTolerance.Internal.VertexTolerance)) @@ -142,7 +142,7 @@ ARDB.ModelCurve Create(ARDB.ViewPlan view, Curve curve) if (view.GenLevel is ARDB.Level level) { using (var sketchPlane = level.GetSketchPlane(ensureSketchPlane: true)) - using (var projectedCurve = Curve.ProjectToPlane(curve, sketchPlane.GetPlane().ToPlane())) + using (var projectedCurve = curve.ProjectToPlane(sketchPlane.GetPlane().ToPlane())) using (var curveArray = new ARDB.CurveArray()) { curveArray.Append(projectedCurve.ToCurve()); diff --git a/src/RhinoInside.Revit.GH/Components/TransactionBaseComponent.cs b/src/RhinoInside.Revit.GH/Components/TransactionBaseComponent.cs index dcefda01f..f69a647e8 100755 --- a/src/RhinoInside.Revit.GH/Components/TransactionBaseComponent.cs +++ b/src/RhinoInside.Revit.GH/Components/TransactionBaseComponent.cs @@ -263,7 +263,7 @@ protected static bool SolveOptionalLevels(ARDB.Document doc, Rhino.Geometry.Curv #region Geometry Conversion public static bool TryGetCurveAtPlane(Curve curve, Plane plane, out ARDB.Curve projected) { - if (Curve.ProjectToPlane(curve, plane) is Curve p) + if (curve.ProjectToPlane(plane) is Curve p) { var tol = GeometryTolerance.Model; diff --git a/src/RhinoInside.Revit.GH/Components/Views/CropRegion.cs b/src/RhinoInside.Revit.GH/Components/Views/CropRegion.cs index caa6b2048..4e6c5bbb9 100644 --- a/src/RhinoInside.Revit.GH/Components/Views/CropRegion.cs +++ b/src/RhinoInside.Revit.GH/Components/Views/CropRegion.cs @@ -129,7 +129,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA) if (Params.GetData(DA, "Crop Region", out Curve cropRegion)) { var viewLocation = view.Location; - var curveLoop = Curve.ProjectToPlane(cropRegion, viewLocation)?.ToCurveLoop(); + var curveLoop = cropRegion.ProjectToPlane(viewLocation)?.ToCurveLoop(); if (curveLoop is null || !cropManager.IsCropRegionShapeValid(curveLoop)) { AddRuntimeMessage diff --git a/src/RhinoInside.Revit.GH/Types/HostObjects/CurtainCell.cs b/src/RhinoInside.Revit.GH/Types/HostObjects/CurtainCell.cs index d85eabc27..b4f5ea716 100644 --- a/src/RhinoInside.Revit.GH/Types/HostObjects/CurtainCell.cs +++ b/src/RhinoInside.Revit.GH/Types/HostObjects/CurtainCell.cs @@ -159,7 +159,7 @@ public Surface Surface var curves = new List(); foreach (var loop in planarCurves) { - var curve = Curve.ProjectToPlane(loop, plane); + var curve = loop.ProjectToPlane(plane); bbox.Union(curve.GetBoundingBox(plane)); curves.Add(curve); } diff --git a/src/RhinoInside.Revit.GH/Types/Sketch.cs b/src/RhinoInside.Revit.GH/Types/Sketch.cs index 34c9662e0..dc30a36b9 100644 --- a/src/RhinoInside.Revit.GH/Types/Sketch.cs +++ b/src/RhinoInside.Revit.GH/Types/Sketch.cs @@ -223,7 +223,7 @@ void RemoveConstraints() var pi = 0; foreach (var boundary in boundaries) { - var profile = Curve.ProjectToPlane(boundary, plane); + var profile = boundary.ProjectToPlane(plane); if ( diff --git a/src/RhinoInside.Revit.GH/Types/Topology/SpatialElement.cs b/src/RhinoInside.Revit.GH/Types/Topology/SpatialElement.cs index 93f77b5e4..ed4064a59 100755 --- a/src/RhinoInside.Revit.GH/Types/Topology/SpatialElement.cs +++ b/src/RhinoInside.Revit.GH/Types/Topology/SpatialElement.cs @@ -64,7 +64,7 @@ public Curve[] Boundaries var segments = spatial.GetBoundarySegments(options); _Boundaries = segments.Select ( - loop => Curve.JoinCurves(loop.Select(x => Curve.ProjectToPlane(x.GetCurve().ToCurve(), plane)), tol.VertexTolerance, preserveDirection: false)[0] + loop => Curve.JoinCurves(loop.Select(x => x.GetCurve().ToCurve().ProjectToPlane(plane)), tol.VertexTolerance, preserveDirection: false)[0] ).ToArray(); } }