From ca363f3c84379688678dacaaafc769747b33a060 Mon Sep 17 00:00:00 2001 From: Ryan Schmidt Date: Sun, 25 Mar 2018 23:12:19 -0400 Subject: [PATCH] comparison fix, minor additions --- distance/DistRay3Segment3.cs | 2 +- mesh/DMesh3_edge_operators.cs | 8 +++++++- queries/MeshQueries.cs | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/distance/DistRay3Segment3.cs b/distance/DistRay3Segment3.cs index b5a0697c..bc9314b8 100644 --- a/distance/DistRay3Segment3.cs +++ b/distance/DistRay3Segment3.cs @@ -57,7 +57,7 @@ public double Get() { public double GetSquared() { - if (DistanceSquared > 0) + if (DistanceSquared >= 0) return DistanceSquared; Vector3d diff = ray.Origin - segment.Center; diff --git a/mesh/DMesh3_edge_operators.cs b/mesh/DMesh3_edge_operators.cs index d7862393..fdebde8f 100644 --- a/mesh/DMesh3_edge_operators.cs +++ b/mesh/DMesh3_edge_operators.cs @@ -262,6 +262,8 @@ public struct EdgeSplitInfo { public int eNewBN; // new edge [vNew,vB] (original was AB) public int eNewCN; // new edge [vNew,vC] (C is "first" other vtx in ring) public int eNewDN; // new edge [vNew,vD] (D is "second" other, which doesn't exist on bdry) + public int eNewT2; + public int eNewT3; } public MeshResult SplitEdge(int vA, int vB, out EdgeSplitInfo split) { @@ -339,6 +341,8 @@ public MeshResult SplitEdge(int eab, out EdgeSplitInfo split) split.eNewBN = efb; split.eNewCN = efc; split.eNewDN = InvalidID; + split.eNewT2 = t2; + split.eNewT3 = InvalidID; updateTimeStamp(true); return MeshResult.Ok; @@ -403,8 +407,10 @@ public MeshResult SplitEdge(int eab, out EdgeSplitInfo split) split.eNewBN = efb; split.eNewCN = efc; split.eNewDN = edf; + split.eNewT2 = t2; + split.eNewT3 = t3; - updateTimeStamp(true); + updateTimeStamp(true); return MeshResult.Ok; } diff --git a/queries/MeshQueries.cs b/queries/MeshQueries.cs index aff48aea..27ca8f00 100644 --- a/queries/MeshQueries.cs +++ b/queries/MeshQueries.cs @@ -124,7 +124,7 @@ public static bool RayHitPointFrame(DMesh3 mesh, ISpatial spatial, Ray3d ray, ou return false; Vector3d surfPt = ray.PointAt(isect.RayParameter); if (mesh.HasVertexNormals) - hitPosFrame = SurfaceFrame(mesh, tid, surfPt); + hitPosFrame = SurfaceFrame(mesh, tid, surfPt); // TODO isect has bary-coords already!! else hitPosFrame = new Frame3f(surfPt, mesh.GetTriNormal(tid)); return true; @@ -151,7 +151,17 @@ public static Frame3f SurfaceFrame(DMesh3 mesh, int tID, Vector3d point) } - + /// + /// Get barycentric coords of point in triangle + /// + public static Vector3d BaryCoords(DMesh3 mesh, int tID, Vector3d point) + { + if (!mesh.IsTriangle(tID)) + throw new Exception("MeshQueries.SurfaceFrame: triangle " + tID + " does not exist!"); + Triangle3d tri = new Triangle3d(); + mesh.GetTriVertices(tID, ref tri.V0, ref tri.V1, ref tri.V2); + return tri.BarycentricCoords(point); + } ///