public static PlanarSurface RoundCoordinates(this PlanarSurface planarSurface, int decimalPlaces = 6) { Vector normal = planarSurface.FitPlane().Normal; //If the PlanarSurface is aligned with one of the main coordinate system's planes then rounded element will get projected on this plane to keep it's planarity. if (Math.Abs(Math.Abs(normal.X) - 1) < Tolerance.Angle || Math.Abs(Math.Abs(normal.Y) - 1) < Tolerance.Angle || Math.Abs(Math.Abs(normal.Z) - 1) < Tolerance.Angle) { Plane plane = new Plane() { Origin = planarSurface.ExternalBoundary.IStartPoint().RoundCoordinates(decimalPlaces), Normal = normal.RoundCoordinates(0) }; ICurve externalBoundary = planarSurface.ExternalBoundary.IProject(plane).IRoundCoordinates(decimalPlaces); List <ICurve> internalBoundaries = planarSurface.InternalBoundaries.Select(x => x.IProject(plane).IRoundCoordinates(decimalPlaces)).ToList(); return(Create.PlanarSurface(externalBoundary, internalBoundaries)); } else { ICurve externalBoundary = planarSurface.ExternalBoundary.IRoundCoordinates(decimalPlaces); List <ICurve> internalBoundaries = planarSurface.InternalBoundaries.Select(x => x.IRoundCoordinates(decimalPlaces)).ToList(); PlanarSurface newSurface = Create.PlanarSurface(externalBoundary, internalBoundaries); if (newSurface != null) { return(newSurface); } } Reflection.Compute.RecordWarning("Rounding the coordinates of a planar surface couldn't be achieved without losing planarity. No action has been taken."); return(planarSurface); }
public static PlanarSurface RoundCoordinates(this PlanarSurface planarSurface, int decimalPlaces = 6) { Vector normal = planarSurface.Normal().Normalise(); if (Math.Abs(Math.Abs(normal.X) - 1) < Tolerance.Angle || Math.Abs(Math.Abs(normal.Y) - 1) < Tolerance.Angle || Math.Abs(Math.Abs(normal.Z) - 1) < Tolerance.Angle) { Plane plane = new Plane() { Origin = planarSurface.ExternalBoundary.IStartPoint().RoundCoordinates(decimalPlaces), Normal = normal.RoundCoordinates(0) }; ICurve externalBoundary = planarSurface.ExternalBoundary.IProject(plane).IRoundCoordinates(decimalPlaces); List <ICurve> internalBoundaries = planarSurface.InternalBoundaries.Select(x => x.IProject(plane).IRoundCoordinates(decimalPlaces)).ToList(); return(Create.PlanarSurface(externalBoundary, internalBoundaries)); } Reflection.Compute.RecordWarning("Rounding the coordinates of a planar surface that is not aligned with the global coordinate system cannot be achieved without risk of losing planarity. No action has been taken."); return(planarSurface); }