From 2d8a85053cccc6b94edf90bad18a7662141bae82 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Sat, 20 Apr 2024 15:23:55 -0400 Subject: [PATCH 1/2] Basic predicate skeleton --- Project.toml | 1 + src/GeometryOps.jl | 1 + src/methods/clipping/predicates.jl | 37 ++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/methods/clipping/predicates.jl diff --git a/Project.toml b/Project.toml index 11987eb2d..9a0a9019b 100644 --- a/Project.toml +++ b/Project.toml @@ -5,6 +5,7 @@ version = "0.1.3" [deps] CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298" +ExactPredicates = "429591f6-91af-11e9-00e2-59fbe8cec110" GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f" GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/GeometryOps.jl b/src/GeometryOps.jl index dc52c7d17..50de92d7e 100644 --- a/src/GeometryOps.jl +++ b/src/GeometryOps.jl @@ -26,6 +26,7 @@ include("methods/barycentric.jl") include("methods/centroid.jl") include("methods/distance.jl") include("methods/equals.jl") +include("methods/clipping/predicates.jl") include("methods/clipping/clipping_processor.jl") include("methods/clipping/coverage.jl") include("methods/clipping/cut.jl") diff --git a/src/methods/clipping/predicates.jl b/src/methods/clipping/predicates.jl new file mode 100644 index 000000000..a3dc30f79 --- /dev/null +++ b/src/methods/clipping/predicates.jl @@ -0,0 +1,37 @@ +module Predicates + +using ExactPredicates +using ExactPredicates.Codegen +using ExactPredicates.Codegen: group!, coord, @genpredicate + +using ExactPredicates: ext, inp + +# This is the implementation of r_cross_s from 2 points in the `_intersection_points` file. +@genpredicate function isparallel(a1 :: 2, a2 :: 2, b1 :: 2, b2 :: 2) + r = a2 - a1 + s = b2 - b1 + group!(r...) + group!(s...) + ext(r, s) +end + +@genpredicate function iscollinear(a1::2, a2::2, b1::2, b2::2) + Δqp = b1 - a1 + s = b2 - b1 + group!(Δqp...) + group!(s...) + ext(s, Δqp) +end + +import .Predicates + +# Predicates.r_cross_s(...) + +#= +using MultiFloats +function isparallel_adaptive(a1, a2, b1, b2) + r = Float64x2.(a2) - Float64x2.(a1) + s = Float64x2.(b2) - Float64x2.(b1) + return sign(Predicates.ext(r, s)) +end +=# \ No newline at end of file From f3eaf1750fa3274f96152aa33edd7d516a8f3faa Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Sat, 20 Apr 2024 15:32:59 -0400 Subject: [PATCH 2/2] Add tabs and a comment --- src/methods/clipping/predicates.jl | 48 +++++++++++++++++++----------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/methods/clipping/predicates.jl b/src/methods/clipping/predicates.jl index a3dc30f79..85b912af5 100644 --- a/src/methods/clipping/predicates.jl +++ b/src/methods/clipping/predicates.jl @@ -1,26 +1,30 @@ module Predicates -using ExactPredicates -using ExactPredicates.Codegen -using ExactPredicates.Codegen: group!, coord, @genpredicate + using ExactPredicates + using ExactPredicates.Codegen + using ExactPredicates.Codegen: group!, coord, @genpredicate -using ExactPredicates: ext, inp + using ExactPredicates: ext, inp -# This is the implementation of r_cross_s from 2 points in the `_intersection_points` file. -@genpredicate function isparallel(a1 :: 2, a2 :: 2, b1 :: 2, b2 :: 2) - r = a2 - a1 - s = b2 - b1 - group!(r...) - group!(s...) - ext(r, s) -end + # This is the implementation of r_cross_s from 2 points in the `_intersection_points` file. + # 0 == parallel + @genpredicate function isparallel(a1 :: 2, a2 :: 2, b1 :: 2, b2 :: 2) + r = a2 - a1 + s = b2 - b1 + group!(r...) + group!(s...) + ext(r, s) + end + # This is the implementation of `iscollinear` from `intersection_points`. + # 0 == parallel. + @genpredicate function iscollinear(a1::2, a2::2, b1::2, b2::2) + Δqp = b1 - a1 + s = b2 - b1 + group!(Δqp...) + group!(s...) + ext(s, Δqp) + end -@genpredicate function iscollinear(a1::2, a2::2, b1::2, b2::2) - Δqp = b1 - a1 - s = b2 - b1 - group!(Δqp...) - group!(s...) - ext(s, Δqp) end import .Predicates @@ -28,10 +32,18 @@ import .Predicates # Predicates.r_cross_s(...) #= +# If we want to inject adaptivity, we would do: using MultiFloats function isparallel_adaptive(a1, a2, b1, b2) r = Float64x2.(a2) - Float64x2.(a1) s = Float64x2.(b2) - Float64x2.(b1) return sign(Predicates.ext(r, s)) end +function isparallel(a1, a2, b1, b2) + # try Predicates.isparallel_naive(a1, a2, b1, b2) + # check the error bound there + # then try isparallel_adaptive(a1, a2, b1, b2) + # then try Predicates.isparallel_slow + # then try isparallel +end =# \ No newline at end of file