From 956b06f90786fca6a53f453fdb30e06765360ae7 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Fri, 28 Aug 2020 17:26:43 +0200 Subject: [PATCH] csg2d - fix inside tests --- libsrc/geom2d/csg2d.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libsrc/geom2d/csg2d.cpp b/libsrc/geom2d/csg2d.cpp index d3e92c57..5f004349 100644 --- a/libsrc/geom2d/csg2d.cpp +++ b/libsrc/geom2d/csg2d.cpp @@ -24,7 +24,7 @@ void ComputeWeight( Spline & s, Point<2> p ) double A = (p[1]-a[1])*(b[0]-p[0]) - (p[0]-a[0])*(b[1]-p[1]); double B = (p[1]-c[1])*(b[0]-p[0]) - (p[0]-c[0])*(b[1]-p[1]); double det = sqrt(-A*B); - double tt = (B-det)/(A+det); + double tt = fabs(A+det) fabs(v[1]) ? 0 : 1; double weight = fabs(tt*(p[dim]-a[dim])/v[dim] + 1.0/tt*(p[dim]-c[dim])/v[dim]); @@ -1485,12 +1485,12 @@ bool Solid2d :: IsLeftInside( const Vertex & p0 ) { auto s = *p0.spline; auto v = s.GetTangent(0.5); - auto n = Vec<2>{v[1], -v[0]}; + auto n = Vec<2>{-v[1], v[0]}; auto q = s.GetPoint(0.5) + 1e-6*n; return IsInside(q); } auto v = p1-p0; - auto n = Vec<2>{v[1], -v[0]}; + auto n = Vec<2>{-v[1], v[0]}; auto q = p0 + 0.5*v + 1e-6*n; return IsInside(q); @@ -1503,13 +1503,13 @@ bool Solid2d :: IsRightInside( const Vertex & p0 ) { auto s = *p0.spline; auto v = s.GetTangent(0.5); - auto n = Vec<2>{-v[1], v[0]}; + auto n = Vec<2>{v[1], -v[0]}; auto q = s.GetPoint(0.5) + 1e-6*n; return IsInside(q); } auto v = p1-p0; - auto n = Vec<2>{-v[1], v[0]}; + auto n = Vec<2>{v[1], -v[0]}; auto q = p0 + 0.5*v + 1e-6*n; return IsInside(q); } @@ -1643,7 +1643,7 @@ shared_ptr CSG2d :: GenerateSplineGeometry() if(li!=ri) { - if(s.IsLeftInside(p0) == flip) + if(s.IsLeftInside(p0) != flip) ls.left = dom; else ls.right = dom;