From e71531ffaf37b4a541129a5bbaf9bc03e24dd4b6 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Tue, 13 Apr 2021 22:07:20 +0900 Subject: [PATCH 1/5] add method Base.in(::Point, ::Line) --- src/primitives/line.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/primitives/line.jl b/src/primitives/line.jl index 042934e33..8c6a613f1 100644 --- a/src/primitives/line.jl +++ b/src/primitives/line.jl @@ -19,3 +19,13 @@ 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) + q = p-l.a + w = norm(l.b-l.a) + v = (l.b-l.a)/w + # d is a distance between p and l + d = norm(q - v*dot(q, v)) + # d ≈ 0.0 will be too precise, and d < atol{T} can't scale. + d+w ≈ w +end From f02448f49367898c6489ec311103bb4627c5a00e Mon Sep 17 00:00:00 2001 From: hyrodium Date: Tue, 13 Apr 2021 22:07:54 +0900 Subject: [PATCH 2/5] add method Base.==(::Line, ::Line) --- src/primitives/line.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/primitives/line.jl b/src/primitives/line.jl index 8c6a613f1..a2c55e61e 100644 --- a/src/primitives/line.jl +++ b/src/primitives/line.jl @@ -29,3 +29,7 @@ function Base.in(p::Point, l::Line) # d ≈ 0.0 will be too precise, and d < atol{T} can't scale. d+w ≈ w end + +function Base.:(==)(l1::Line, l2::Line) + l1.a in l2 && l1.b in l2 && l2.a in l1 && l2.b in l1 +end From 9d6ba34c5274924ed73a916fdd87c57421de776c Mon Sep 17 00:00:00 2001 From: hyrodium Date: Tue, 13 Apr 2021 22:21:29 +0900 Subject: [PATCH 3/5] update tests for Base.==(::Line, ::Line) --- test/primitives.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/primitives.jl b/test/primitives.jl index 88d9ba6e9..798fad83d 100644 --- a/test/primitives.jl +++ b/test/primitives.jl @@ -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 end @testset "Rays" begin From 6a1310236072d608ce5d4b5dfd94b4f7cc986a14 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Tue, 13 Apr 2021 22:27:19 +0900 Subject: [PATCH 4/5] update Base.in(::Point, ::Line) to use evaluate --- src/primitives/line.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/primitives/line.jl b/src/primitives/line.jl index a2c55e61e..1cd21bce1 100644 --- a/src/primitives/line.jl +++ b/src/primitives/line.jl @@ -21,11 +21,8 @@ paramdim(::Type{<:Line}) = 1 (l::Line)(t) = l.a + t * (l.b - l.a) function Base.in(p::Point, l::Line) - q = p-l.a w = norm(l.b-l.a) - v = (l.b-l.a)/w - # d is a distance between p and l - d = norm(q - v*dot(q, v)) + d = evaluate(Euclidean(), p, l) # d ≈ 0.0 will be too precise, and d < atol{T} can't scale. d+w ≈ w end From 6ff944989434fe5591b326f2bded3c52c2cdf8b5 Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Tue, 13 Apr 2021 23:43:18 +0900 Subject: [PATCH 5/5] Update src/primitives/line.jl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Júlio Hoffimann --- src/primitives/line.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/primitives/line.jl b/src/primitives/line.jl index 1cd21bce1..b58d041f8 100644 --- a/src/primitives/line.jl +++ b/src/primitives/line.jl @@ -27,6 +27,4 @@ function Base.in(p::Point, l::Line) d+w ≈ w end -function Base.:(==)(l1::Line, l2::Line) - l1.a in l2 && l1.b in l2 && l2.a in l1 && l2.b in l1 -end +==(l1::Line, l2::Line) = l1.a ∈ l2 && l1.b ∈ l2 && l2.a ∈ l1 && l2.b ∈ l1