Skip to content

Commit 46a811d

Browse files
authored
Fix isapprox for Line (#1141)
1 parent d763d2a commit 46a811d

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/geometries/primitives/line.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ paramdim(::Type{<:Line}) = 1
2121
==(l₁::Line, l₂::Line) = l₁.a l₂ && l₁.b l₂ && l₂.a l₁ && l₂.b l₁
2222

2323
Base.isapprox(l₁::Line, l₂::Line; atol=atol(lentype(l₁)), kwargs...) =
24-
isapprox(l₁.a, l₂.a; atol, kwargs...) && isapprox(l₁.b, l₂.b; atol, kwargs...)
24+
isapproxzero(norm(ucross(l₁.b - l₁.a, l₂.b - l₂.a)); atol, kwargs...) &&
25+
isapproxzero(norm(ucross(l₁.b - l₂.a, l₂.b - l₂.a)); atol, kwargs...)
2526

2627
(l::Line)(t) = coordsum((l.a, l.b), weights=((1 - t), t))

src/geometries/primitives/plane.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ normal(p::Plane) = unormalize(ucross(p.u, p.v))
4444
p₁(0, 0) p₂ && p₁(1, 0) p₂ && p₁(0, 1) p₂ && p₂(0, 0) p₁ && p₂(1, 0) p₁ && p₂(0, 1) p₁
4545

4646
Base.isapprox(p₁::Plane, p₂::Plane; atol=atol(lentype(p₁)), kwargs...) =
47+
isapproxzero(norm(ucross(normal(p₁), normal(p₂))); atol, kwargs...) &&
4748
isapproxzero(udot(p₁(0, 0) - p₂(0, 0), normal(p₂)); atol, kwargs...) &&
48-
isapproxzero(udot(p₂(0, 0) - p₁(0, 0), normal(p₁)); atol, kwargs...) &&
49-
isapproxzero(norm(ucross(normal(p₁), normal(p₂))); atol, kwargs...)
49+
isapproxzero(udot(p₂(0, 0) - p₁(0, 0), normal(p₁)); atol, kwargs...)
5050

5151
(p::Plane)(u, v) = p.p + u * p.u + v * p.v

test/primitives.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ end
276276
@test l(T(0.75)) == latlon(45, 67.5)
277277
@test l(T(1)) == latlon(45, 90)
278278

279+
# https://github.com/JuliaGeometry/Meshes.jl/issues/1138
280+
l1 = Line(cart(0, 0), cart(1, 0))
281+
l2 = Line(cart(0, 0), cart(2, 0))
282+
l3 = Line(cart(0, 0), cart(-1, 0))
283+
l4 = Line(cart(0, 0), cart(0, 1))
284+
l5 = Line(cart(0, 0), cart(0, 2))
285+
l6 = Line(cart(0, 0), cart(0, -1))
286+
@test l1 == l2 == l3
287+
@test l1 l2 l3
288+
@test l4 == l5 == l6
289+
@test l4 l5 l6
290+
279291
l = Line(cart(0, 0), cart(1, 1))
280292
@test sprint(show, l) == "Line(a: (x: 0.0 m, y: 0.0 m), b: (x: 1.0 m, y: 1.0 m))"
281293
if T === Float32

0 commit comments

Comments
 (0)