Skip to content

Commit

Permalink
Add clamp-like behavoiur when the parameter is not provided (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
amakhno authored Nov 24, 2023
1 parent 16f4f82 commit 67c6966
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions mesh_ops/MergeCoincidentEdges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MergeCoincidentEdges
{
public DMesh3 Mesh;

public double MergeDistance = MathUtil.ZeroTolerancef;
public double? MergeDistance = null;

public bool OnlyUniquePairs = false;

Expand All @@ -32,7 +32,6 @@ public MergeCoincidentEdges(DMesh3 mesh)
public virtual bool Apply()
{
_mergeEdgesInfos.Clear();
merge_r2 = MergeDistance * MergeDistance;

// construct hash table for edge midpoints
MeshBoundaryEdgeMidpoints pointset = new MeshBoundaryEdgeMidpoints(Mesh);
Expand All @@ -41,7 +40,15 @@ public virtual bool Apply()
if (Mesh.TriangleCount > 100000) hashN = 128;
if (Mesh.TriangleCount > 1000000) hashN = 256;
hash.Build(hashN);

// If the MergeDistance is larger than CellSize, we get an error.
double mergeDistance = MergeDistance is null
? MathUtil.ZeroTolerancef : MergeDistance.Value;
if (MergeDistance is null
&& mergeDistance > hash.CellSize)
// If the distance hasn't been provided,
// we choose the maximum possible ball size
mergeDistance = hash.CellSize;
merge_r2 = mergeDistance * mergeDistance;
Vector3d a = Vector3d.Zero, b = Vector3d.Zero;
Vector3d c = Vector3d.Zero, d = Vector3d.Zero;

Expand All @@ -54,7 +61,7 @@ public virtual bool Apply()
{
Vector3d midpt = Mesh.GetEdgePoint(eid, 0.5);
int N;
while (hash.FindInBall(midpt, MergeDistance, buffer, out N) == false)
while (hash.FindInBall(midpt, mergeDistance, buffer, out N) == false)
buffer = new int[buffer.Length];
if (N == 1 && buffer[0] != eid)
throw new Exception("MergeCoincidentEdges.Apply: how could this happen?!");
Expand Down
2 changes: 1 addition & 1 deletion spatial/PointSetHashtable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class PointSetHashtable
ShiftGridIndexer3 indexF;

Vector3d Origin;
double CellSize;
public double CellSize { get; private set; }

public PointSetHashtable(IPointSet points)
{
Expand Down

0 comments on commit 67c6966

Please sign in to comment.