From 46a811d8b9fbff8800d1c7cb77acec22aefc3992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Hoffimann?= Date: Wed, 20 Nov 2024 09:53:54 -0300 Subject: [PATCH] Fix isapprox for Line (#1141) --- src/geometries/primitives/line.jl | 3 ++- src/geometries/primitives/plane.jl | 4 ++-- test/primitives.jl | 12 ++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/geometries/primitives/line.jl b/src/geometries/primitives/line.jl index 14e895c60..97fbd8c1f 100644 --- a/src/geometries/primitives/line.jl +++ b/src/geometries/primitives/line.jl @@ -21,6 +21,7 @@ paramdim(::Type{<:Line}) = 1 ==(l₁::Line, l₂::Line) = l₁.a ∈ l₂ && l₁.b ∈ l₂ && l₂.a ∈ l₁ && l₂.b ∈ l₁ Base.isapprox(l₁::Line, l₂::Line; atol=atol(lentype(l₁)), kwargs...) = - isapprox(l₁.a, l₂.a; atol, kwargs...) && isapprox(l₁.b, l₂.b; atol, kwargs...) + isapproxzero(norm(ucross(l₁.b - l₁.a, l₂.b - l₂.a)); atol, kwargs...) && + isapproxzero(norm(ucross(l₁.b - l₂.a, l₂.b - l₂.a)); atol, kwargs...) (l::Line)(t) = coordsum((l.a, l.b), weights=((1 - t), t)) diff --git a/src/geometries/primitives/plane.jl b/src/geometries/primitives/plane.jl index 1c539a4f2..0be6b6434 100644 --- a/src/geometries/primitives/plane.jl +++ b/src/geometries/primitives/plane.jl @@ -44,8 +44,8 @@ normal(p::Plane) = unormalize(ucross(p.u, p.v)) p₁(0, 0) ∈ p₂ && p₁(1, 0) ∈ p₂ && p₁(0, 1) ∈ p₂ && p₂(0, 0) ∈ p₁ && p₂(1, 0) ∈ p₁ && p₂(0, 1) ∈ p₁ Base.isapprox(p₁::Plane, p₂::Plane; atol=atol(lentype(p₁)), kwargs...) = + isapproxzero(norm(ucross(normal(p₁), normal(p₂))); atol, kwargs...) && isapproxzero(udot(p₁(0, 0) - p₂(0, 0), normal(p₂)); atol, kwargs...) && - isapproxzero(udot(p₂(0, 0) - p₁(0, 0), normal(p₁)); atol, kwargs...) && - isapproxzero(norm(ucross(normal(p₁), normal(p₂))); atol, kwargs...) + isapproxzero(udot(p₂(0, 0) - p₁(0, 0), normal(p₁)); atol, kwargs...) (p::Plane)(u, v) = p.p + u * p.u + v * p.v diff --git a/test/primitives.jl b/test/primitives.jl index bc3c36d58..1ef66b29d 100644 --- a/test/primitives.jl +++ b/test/primitives.jl @@ -276,6 +276,18 @@ end @test l(T(0.75)) == latlon(45, 67.5) @test l(T(1)) == latlon(45, 90) + # https://github.com/JuliaGeometry/Meshes.jl/issues/1138 + l1 = Line(cart(0, 0), cart(1, 0)) + l2 = Line(cart(0, 0), cart(2, 0)) + l3 = Line(cart(0, 0), cart(-1, 0)) + l4 = Line(cart(0, 0), cart(0, 1)) + l5 = Line(cart(0, 0), cart(0, 2)) + l6 = Line(cart(0, 0), cart(0, -1)) + @test l1 == l2 == l3 + @test l1 ≈ l2 ≈ l3 + @test l4 == l5 == l6 + @test l4 ≈ l5 ≈ l6 + l = Line(cart(0, 0), cart(1, 1)) @test sprint(show, l) == "Line(a: (x: 0.0 m, y: 0.0 m), b: (x: 1.0 m, y: 1.0 m))" if T === Float32