diff --git a/src/GShark/Core/GeoSharkMath.cs b/src/GShark/Core/GeoSharkMath.cs index 06c238b3..cdcd15c7 100644 --- a/src/GShark/Core/GeoSharkMath.cs +++ b/src/GShark/Core/GeoSharkMath.cs @@ -11,12 +11,12 @@ public class GeoSharkMath /// /// The default euclidean distance that identifies whether two points are coincident. /// - public const double MinTolerance = 1e-3; + public const double MaxTolerance = 1e-3; /// /// The default euclidean distance that identifies whether two points are coincident. /// - public const double MaxTolerance = 1e-6; + public const double MinTolerance = 1e-6; /// /// The minimum value to determine whether two floating point numbers are the same. diff --git a/src/GShark/Core/Interval.cs b/src/GShark/Core/Interval.cs index 46fc4586..ec7110b5 100644 --- a/src/GShark/Core/Interval.cs +++ b/src/GShark/Core/Interval.cs @@ -32,7 +32,7 @@ public Interval(double t0, double t1) /// /// Gets the value between the interval's min and max values. /// - public double Mid => Math.Abs(T0 - T1) > GeoSharkMath.MaxTolerance ? 0.5 * (T0 + T1) : T0; + public double Mid => Math.Abs(T0 - T1) > GeoSharkMath.MinTolerance ? 0.5 * (T0 + T1) : T0; /// /// Gets the length of the interval.
diff --git a/src/GShark/Core/KnotVector.cs b/src/GShark/Core/KnotVector.cs index 5d669b3d..3ef97c6e 100644 --- a/src/GShark/Core/KnotVector.cs +++ b/src/GShark/Core/KnotVector.cs @@ -219,7 +219,7 @@ public int Span(int n, int degree, double parameter) /// The multiplicity of the knot, or 0 if the knot is not part of the knot vector. public int Multiplicity(double knot) { - return this.Count(x => Math.Abs(x-knot) <= GeoSharkMath.MaxTolerance); + return this.Count(x => Math.Abs(x-knot) <= GeoSharkMath.MinTolerance); } /// diff --git a/src/GShark/Core/Trigonometry.cs b/src/GShark/Core/Trigonometry.cs index 40725308..6d5ac461 100644 --- a/src/GShark/Core/Trigonometry.cs +++ b/src/GShark/Core/Trigonometry.cs @@ -46,7 +46,7 @@ public static bool ArePointsCoplanar(IList points) /// Third point. /// Tolerance ser per default as 1e-6 /// True if the three points are collinear. - public static bool ArePointsCollinear(Point3 pt1, Point3 pt2, Point3 pt3, double tol = GeoSharkMath.MaxTolerance) + public static bool ArePointsCollinear(Point3 pt1, Point3 pt2, Point3 pt3, double tol = GeoSharkMath.MinTolerance) { // Find the area of the triangle without using square root and multiply it for 0.5 // http://www.stumblingrobot.com/2016/05/01/use-cross-product-compute-area-triangles-given-vertices/ diff --git a/src/GShark/Geometry/Arc.cs b/src/GShark/Geometry/Arc.cs index ab05bc1e..85b37020 100644 --- a/src/GShark/Geometry/Arc.cs +++ b/src/GShark/Geometry/Arc.cs @@ -233,7 +233,7 @@ public Point3 ClosestPoint(Point3 pt) double twoPi = 2.0 * Math.PI; (double u, double v) = Plane.ClosestParameters(pt); - if (Math.Abs(u) < GeoSharkMath.MaxTolerance && Math.Abs(v) < GeoSharkMath.MaxTolerance) + if (Math.Abs(u) < GeoSharkMath.MinTolerance && Math.Abs(v) < GeoSharkMath.MinTolerance) { return PointAt(0.0); } @@ -403,8 +403,8 @@ public bool Equals(Arc other) return false; } - return Math.Abs(Radius - other.Radius) < GeoSharkMath.MaxTolerance && - Math.Abs(Angle - other.Angle) < GeoSharkMath.MaxTolerance && + return Math.Abs(Radius - other.Radius) < GeoSharkMath.MinTolerance && + Math.Abs(Angle - other.Angle) < GeoSharkMath.MinTolerance && Plane == other.Plane; } diff --git a/src/GShark/Geometry/BoundingBox.cs b/src/GShark/Geometry/BoundingBox.cs index 1080c685..675b8500 100644 --- a/src/GShark/Geometry/BoundingBox.cs +++ b/src/GShark/Geometry/BoundingBox.cs @@ -151,7 +151,7 @@ public static bool AreOverlapping(BoundingBox bBox1, BoundingBox bBox2, double t return false; } - tol = tol < -0.5 ? GeoSharkMath.MaxTolerance : tol; + tol = tol < -0.5 ? GeoSharkMath.MinTolerance : tol; int count = 0; for (int i = 0; i < 3; i++) { diff --git a/src/GShark/Geometry/Circle.cs b/src/GShark/Geometry/Circle.cs index 5e0edc3b..e652633d 100644 --- a/src/GShark/Geometry/Circle.cs +++ b/src/GShark/Geometry/Circle.cs @@ -174,7 +174,7 @@ public Vector3 TangentAt(double t) public Point3 ClosestPoint(Point3 pt) { (double u, double v) = Plane.ClosestParameters(pt); - if (Math.Abs(u) < GeoSharkMath.MaxTolerance && Math.Abs(v) < GeoSharkMath.MaxTolerance) + if (Math.Abs(u) < GeoSharkMath.MinTolerance && Math.Abs(v) < GeoSharkMath.MinTolerance) { return PointAt(0.0); } @@ -217,7 +217,7 @@ public bool Equals(Circle other) return false; } - return Math.Abs(Radius - other.Radius) < GeoSharkMath.MaxTolerance && Plane == other.Plane; + return Math.Abs(Radius - other.Radius) < GeoSharkMath.MinTolerance && Plane == other.Plane; } /// diff --git a/src/GShark/Geometry/ConvexHull.cs b/src/GShark/Geometry/ConvexHull.cs index e8d388c0..f58deff1 100644 --- a/src/GShark/Geometry/ConvexHull.cs +++ b/src/GShark/Geometry/ConvexHull.cs @@ -503,7 +503,7 @@ private void FindInitialHullIndices(List points, out int b0, out int b1, Vector3 p0 = points[i0]; Vector3 p1 = points[i1]; - if (p0.EpsilonEquals(p1, GeoSharkMath.MaxTolerance)) + if (p0.EpsilonEquals(p1, GeoSharkMath.MinTolerance)) { continue; } diff --git a/src/GShark/Geometry/NurbsCurve.cs b/src/GShark/Geometry/NurbsCurve.cs index dbd0e4a0..f306ef02 100644 --- a/src/GShark/Geometry/NurbsCurve.cs +++ b/src/GShark/Geometry/NurbsCurve.cs @@ -126,7 +126,7 @@ public BoundingBox BoundingBox } pts.Add(curve.LocationPoints[curve.LocationPoints.Count - 1]); - Point3[] removedDuplicate = Point3.CullDuplicates(pts, GeoSharkMath.MaxTolerance); + Point3[] removedDuplicate = Point3.CullDuplicates(pts, GeoSharkMath.MinTolerance); return new BoundingBox(removedDuplicate); } } diff --git a/src/GShark/Operation/Analyze.cs b/src/GShark/Operation/Analyze.cs index 6e795630..4a15546b 100644 --- a/src/GShark/Operation/Analyze.cs +++ b/src/GShark/Operation/Analyze.cs @@ -224,13 +224,12 @@ public static double CurveClosestParameter(ICurve curve, Point3 point) /// The surface object. /// Point to search from. /// The closest parameter on the surface. - public static (double u, double v) SurfaceClosestParameter(NurbsSurface surface, Point3 point) + public static (double u, double v) SurfaceClosestParameter(NurbsSurface surface, Point3 point, int maxIterations = 10) { double minimumDistance = double.PositiveInfinity; (double u, double v) selectedUV = (0D, 0D); NurbsSurface splitSrf = surface; double param = 0.5; - int maxIterations = 6; for (int i = 0; i < maxIterations; i++) {