Skip to content

Commit

Permalink
Fix isapprox for Line (#1141)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm authored Nov 20, 2024
1 parent d763d2a commit 46a811d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/geometries/primitives/line.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
4 changes: 2 additions & 2 deletions src/geometries/primitives/plane.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions test/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 46a811d

Please sign in to comment.