Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/line equality #119

Merged
merged 5 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/primitives/line.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ Line(a::Tuple, b::Tuple) = Line(Point(a), Point(b))
paramdim(::Type{<:Line}) = 1

(l::Line)(t) = l.a + t * (l.b - l.a)

function Base.in(p::Point, l::Line)
w = norm(l.b-l.a)
d = evaluate(Euclidean(), p, l)
# d ≈ 0.0 will be too precise, and d < atol{T} can't scale.
d+w ≈ w
juliohm marked this conversation as resolved.
Show resolved Hide resolved
end

==(l1::Line, l2::Line) = l1.a ∈ l2 && l1.b ∈ l2 && l2.a ∈ l1 && l2.b ∈ l1
4 changes: 2 additions & 2 deletions test/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

l1 = Line(P2(0,0), P2(1,0))
l2 = Line(P2(1,0), P2(2,0))
@test_broken l1 == l2
@test_broken l1 ∩ l2 == l2 ∩ l1 == l1
@test l1 == l2
@test l1 ∩ l2 == l2 ∩ l1 == l1
juliohm marked this conversation as resolved.
Show resolved Hide resolved
end

@testset "Rays" begin
Expand Down