From e7f2299f0518f8f0e6550edc63e2830ee2caae7f Mon Sep 17 00:00:00 2001 From: Egor Date: Sat, 18 Jan 2025 20:48:23 +0700 Subject: [PATCH 1/2] Relax precision for issue 655. Add test, move code for readability --- src/math/ExtendedTriangle.js | 16 +++++++------- test/Math.TriangleIntersections.test.js | 28 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/math/ExtendedTriangle.js b/src/math/ExtendedTriangle.js index 55e28ba9b..d27e0843d 100644 --- a/src/math/ExtendedTriangle.js +++ b/src/math/ExtendedTriangle.js @@ -2,7 +2,7 @@ import { Triangle, Vector3, Line3, Sphere, Plane } from 'three'; import { SeparatingAxisBounds } from './SeparatingAxisBounds.js'; import { closestPointsSegmentToSegment, sphereIntersectTriangle } from './MathUtilities.js'; -const ZERO_EPSILON = 1e-15; +const ZERO_EPSILON = 1e-14; function isNearZero( value ) { return Math.abs( value ) < ZERO_EPSILON; @@ -192,6 +192,13 @@ ExtendedTriangle.prototype.intersectsTriangle = ( function () { } + count ++; + if ( count === 2 && startPointIntersection === - 1 ) { + + break; + + } + } else if ( count >= 2 ) { // if we're here that means that there must have been one point that had @@ -203,13 +210,6 @@ ExtendedTriangle.prototype.intersectsTriangle = ( function () { } - count ++; - if ( count === 2 && startPointIntersection === - 1 ) { - - break; - - } - } } diff --git a/test/Math.TriangleIntersections.test.js b/test/Math.TriangleIntersections.test.js index 0271b7c74..60fa87560 100644 --- a/test/Math.TriangleIntersections.test.js +++ b/test/Math.TriangleIntersections.test.js @@ -159,6 +159,34 @@ describe( 'Triangle Intersections', () => { } ); + it( 'triangles should return a correct intersection (issue #655)', () => { + + t1.a.set( 32.22699737548828, 1.2630000114440918, -11.8149995803833 ); + t1.b.set( 31.316997528076172, 1.2630000114440918, -11.739999771118164 ); + t1.c.set( 32.22699737548828, 1.2630000114440918, -11.739999771118164 ); + t1.needsUpdate = true; + + t2.a.set( 31.316997528076172, 1.933000087738037, -7.585000038146973 ); + t2.b.set( 31.316997528076172, -0.8669999837875366, -7.295000076293945 ); + t2.c.set( 31.316997528076172, -0.8669999837875366, -7.585000038146973 ); + t2.needsUpdate = true; + + expect( t1.intersectsTriangle( t2 ) ).toBe( false ); + + t2.a.set( 32.22699737548828, 1.2630000114440918, -11.8149995803833 ); + t2.b.set( 31.316997528076172, 1.2630000114440918, -11.739999771118164 ); + t2.c.set( 32.22699737548828, 1.2630000114440918, -11.739999771118164 ); + t2.needsUpdate = true; + + t1.a.set( 31.316997528076172, 1.933000087738037, -7.585000038146973 ); + t1.b.set( 31.316997528076172, -0.8669999837875366, -7.295000076293945 ); + t1.c.set( 31.316997528076172, -0.8669999837875366, -7.585000038146973 ); + t1.needsUpdate = true; + + expect( t1.intersectsTriangle( t2 ) ).toBe( false ); + + } ); + } ); describe( 'Triangle Intersection line', () => { From 4dc6dabad7a54e2803ab63e24d0653ff0be4c7e9 Mon Sep 17 00:00:00 2001 From: Egor Date: Thu, 23 Jan 2025 23:19:56 +0700 Subject: [PATCH 2/2] Fix eslint issues --- test/Math.TriangleIntersections.test.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/Math.TriangleIntersections.test.js b/test/Math.TriangleIntersections.test.js index 60fa87560..bfc984a28 100644 --- a/test/Math.TriangleIntersections.test.js +++ b/test/Math.TriangleIntersections.test.js @@ -161,26 +161,26 @@ describe( 'Triangle Intersections', () => { it( 'triangles should return a correct intersection (issue #655)', () => { - t1.a.set( 32.22699737548828, 1.2630000114440918, -11.8149995803833 ); - t1.b.set( 31.316997528076172, 1.2630000114440918, -11.739999771118164 ); - t1.c.set( 32.22699737548828, 1.2630000114440918, -11.739999771118164 ); + t1.a.set( 32.22699737548828, 1.2630000114440918, - 11.8149995803833 ); + t1.b.set( 31.316997528076172, 1.2630000114440918, - 11.739999771118164 ); + t1.c.set( 32.22699737548828, 1.2630000114440918, - 11.739999771118164 ); t1.needsUpdate = true; - t2.a.set( 31.316997528076172, 1.933000087738037, -7.585000038146973 ); - t2.b.set( 31.316997528076172, -0.8669999837875366, -7.295000076293945 ); - t2.c.set( 31.316997528076172, -0.8669999837875366, -7.585000038146973 ); + t2.a.set( 31.316997528076172, 1.933000087738037, - 7.585000038146973 ); + t2.b.set( 31.316997528076172, - 0.8669999837875366, - 7.295000076293945 ); + t2.c.set( 31.316997528076172, - 0.8669999837875366, - 7.585000038146973 ); t2.needsUpdate = true; expect( t1.intersectsTriangle( t2 ) ).toBe( false ); - t2.a.set( 32.22699737548828, 1.2630000114440918, -11.8149995803833 ); - t2.b.set( 31.316997528076172, 1.2630000114440918, -11.739999771118164 ); - t2.c.set( 32.22699737548828, 1.2630000114440918, -11.739999771118164 ); + t2.a.set( 32.22699737548828, 1.2630000114440918, - 11.8149995803833 ); + t2.b.set( 31.316997528076172, 1.2630000114440918, - 11.739999771118164 ); + t2.c.set( 32.22699737548828, 1.2630000114440918, - 11.739999771118164 ); t2.needsUpdate = true; - t1.a.set( 31.316997528076172, 1.933000087738037, -7.585000038146973 ); - t1.b.set( 31.316997528076172, -0.8669999837875366, -7.295000076293945 ); - t1.c.set( 31.316997528076172, -0.8669999837875366, -7.585000038146973 ); + t1.a.set( 31.316997528076172, 1.933000087738037, - 7.585000038146973 ); + t1.b.set( 31.316997528076172, - 0.8669999837875366, - 7.295000076293945 ); + t1.c.set( 31.316997528076172, - 0.8669999837875366, - 7.585000038146973 ); t1.needsUpdate = true; expect( t1.intersectsTriangle( t2 ) ).toBe( false );