I noticed that there is a discrepancy of points returned by Mesh.GetNakedEdges()
and the actual points in the Mesh.Vertices
collection if double precision vertices are used. It would be nice if that method, which returns Polyline[]
with double-precision vertices, uses the double precision vertices if available.
@dale can you put this in the bug tracker?
For a quick reproduction, see this code
public Result RunCommand(RhinoDoc doc, RunMode mode)
{
Mesh m = new Mesh();
m.Vertices.UseDoublePrecisionVertices = true;
Random r = new Random(12345);
m.Vertices.Add(new Point3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
m.Vertices.Add(new Point3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
m.Vertices.Add(new Point3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
m.Vertices.Add(new Point3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
m.Faces.AddFace(0, 1, 2, 3);
Polyline[] pls = m.GetNakedEdges();
if (null == pls || !pls.Any())
return Result.Failure;
foreach (Polyline pl in pls)
{
foreach (Point3d pt in pl)
{
Point3d closest = Point3d.Unset;
double dist = Double.MaxValue;
for (int i = 0; i < 4; ++i)
{
Point3d meshVertex = m.Vertices.Point3dAt(i);
double d = (meshVertex - pt).SquareLength;
if (d < dist)
{
dist = d;
closest = meshVertex;
}
}
RhinoApp.WriteLine($"Looking for: {pt.X:R} {pt.Y:R} {pt.Z:R}");
RhinoApp.WriteLine($"Closest point: {closest.X:R} {closest.Y:R} {closest.Z:R}");
RhinoApp.WriteLine($"Distance: {pt.DistanceTo(closest):R}");
}
}
return Result.Success;
}
Output: 4x discrepancies O(10^-9)
:
Looking for: 0.066746935248374939 0.070159509778022766 0.774765133857727
Closest point: 0.066746934813795109 0.070159508879370752 0.77476513514982781
Distance: 1.6327766057913135E-09