Skip to content

Commit 157a06d

Browse files
committed
Describe a FosterHormannClipping algorithm
Not sure of name (too verbose, maybe Foster()?). Intersection accelerators will come into the picture later (next PR) but we need them now to instantiate the struct.
1 parent f2d90a8 commit 157a06d

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/methods/clipping/clipping_processor.jl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,59 @@
11
# # Polygon clipping helpers
22
# This file contains the shared helper functions for the polygon clipping functionalities.
33

4+
# This file specifically defines helpers for the Foster-Hormann clipping algorithm.
5+
6+
7+
"""
8+
abstract type IntersectionAccelerator
9+
10+
The abstract supertype for all intersection accelerator types.
11+
12+
The idea is that these speed up the edge-edge intersection checking process,
13+
perhaps at the cost of memory.
14+
15+
The naive case is [`NestedLoop`](@ref), which is just a nested loop, running in O(n*m) time.
16+
17+
Then we have [`SingleSTRtree`](@ref), which is a single STRtree, running in O(n*log(m)) time.
18+
19+
Then we have [`DoubleSTRtree`](@ref), which is am simultaneous double-tree traversal of two STRtrees.
20+
21+
Finally, we have [`AutoAccelerator`](@ref), which is an automatic accelerator that chooses the best
22+
accelerator based on the size of the input polygons. This gets materialized in build_a_list for now.
23+
"""
24+
abstract type IntersectionAccelerator end
25+
struct NestedLoop <: IntersectionAccelerator end
26+
struct SingleSTRtree <: IntersectionAccelerator end
27+
struct DoubleSTRtree <: IntersectionAccelerator end
28+
struct SingleNaturalTree <: IntersectionAccelerator end
29+
struct DoubleNaturalTree <: IntersectionAccelerator end
30+
struct ThinnedDoubleNaturalTree <: IntersectionAccelerator end
31+
struct AutoAccelerator <: IntersectionAccelerator end
32+
33+
"""
34+
FosterHormannClipping{M <: Manifold, A <: Union{Nothing, Accelerator}} <: GeometryOpsCore.Algorithm{M}
35+
36+
A type that represents the Foster-Hormann clipping algorithm.
37+
38+
# Arguments
39+
- `manifold::M`: The manifold on which the algorithm operates.
40+
- `accelerator::A`: The accelerator to use for the algorithm. Can be `nothing` for automatic choice, or a custom accelerator.
41+
"""
42+
struct FosterHormannClipping{M <: Manifold, A <: IntersectionAccelerator} <: GeometryOpsCore.Algorithm{M}
43+
manifold::M
44+
accelerator::A
45+
# TODO: add exact flag
46+
# TODO: should exact flag be in the type domain?
47+
end
48+
49+
50+
FosterHormannClipping(; manifold::Manifold = Planar(), accelerator = nothing) = FosterHormannClipping(manifold, isnothing(accelerator) ? AutoAccelerator() : accelerator)
51+
FosterHormannClipping(manifold::Manifold, accelerator::Union{Nothing, IntersectionAccelerator} = nothing) = FosterHormannClipping(manifold, isnothing(accelerator) ? AutoAccelerator() : accelerator)
52+
FosterHormannClipping(accelerator::Union{Nothing, IntersectionAccelerator}) = FosterHormannClipping(Planar(), isnothing(accelerator) ? AutoAccelerator() : accelerator)
53+
# special case for spherical / geodesic manifolds
54+
# since they can't use STRtrees (because those don't work on the sphere)
55+
FosterHormannClipping(manifold::Union{Spherical, Geodesic}, accelerator::Union{Nothing, IntersectionAccelerator} = nothing) = FosterHormannClipping(manifold, isnothing(accelerator) ? NestedLoop() : (accelerator isa AutoAccelerator ? NestedLoop() : accelerator))
56+
457
# This enum defines which side of an edge a point is on
558
@enum PointEdgeSide left=1 right=2 unknown=3
659

0 commit comments

Comments
 (0)