Skip to content

Commit

Permalink
Merge pull request #240 from GSharker/dev/ceca/#236
Browse files Browse the repository at this point in the history
addressed issue #236
  • Loading branch information
cesarecaoduro authored Aug 9, 2021
2 parents 84a5fb2 + 4501421 commit 7bbb540
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/GShark/Core/GeoSharkMath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public class GeoSharkMath
/// <summary>
/// The default euclidean distance that identifies whether two points are coincident.
/// </summary>
public const double MinTolerance = 1e-3;
public const double MaxTolerance = 1e-3;

/// <summary>
/// The default euclidean distance that identifies whether two points are coincident.
/// </summary>
public const double MaxTolerance = 1e-6;
public const double MinTolerance = 1e-6;

/// <summary>
/// The minimum value to determine whether two floating point numbers are the same.
Expand Down
2 changes: 1 addition & 1 deletion src/GShark/Core/Interval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Interval(double t0, double t1)
/// <summary>
/// Gets the value between the interval's min and max values.
/// </summary>
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;

/// <summary>
/// Gets the length of the interval.<br/>
Expand Down
2 changes: 1 addition & 1 deletion src/GShark/Core/KnotVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public int Span(int n, int degree, double parameter)
/// <returns>The multiplicity of the knot, or 0 if the knot is not part of the knot vector.</returns>
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);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/GShark/Core/Trigonometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static bool ArePointsCoplanar(IList<Point3> points)
/// <param name="pt3">Third point.</param>
/// <param name="tol">Tolerance ser per default as 1e-6</param>
/// <returns>True if the three points are collinear.</returns>
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/
Expand Down
6 changes: 3 additions & 3 deletions src/GShark/Geometry/Arc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/GShark/Geometry/BoundingBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down
4 changes: 2 additions & 2 deletions src/GShark/Geometry/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/GShark/Geometry/ConvexHull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ private void FindInitialHullIndices(List<Point3> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/GShark/Geometry/NurbsCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/GShark/Operation/Analyze.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,12 @@ public static double CurveClosestParameter(ICurve curve, Point3 point)
/// <param name="surface">The surface object.</param>
/// <param name="point">Point to search from.</param>
/// <returns>The closest parameter on the surface.</returns>
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++)
{
Expand Down

0 comments on commit 7bbb540

Please sign in to comment.