-
Notifications
You must be signed in to change notification settings - Fork 78
/
plane.jl
25 lines (19 loc) · 901 Bytes
/
plane.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# ------------------------------------------------------------------
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------
"""
PlanePartition(normal; tol=1e-6)
A method for partitioning spatial objects into a family of hyperplanes
defined by a `normal` direction. Two points `x` and `y` belong to the same
hyperplane when `(x - y) ⋅ normal < tol`.
"""
struct PlanePartition{Dim,T} <: SPredicatePartitionMethod
normal::Vec{Dim,T}
tol::Float64
function PlanePartition{Dim,T}(normal, tol) where {Dim,T}
new(normalize(normal), tol)
end
end
PlanePartition(normal::Vec{Dim,T}; tol=1e-6) where {Dim,T} = PlanePartition{Dim,T}(normal, tol)
PlanePartition(normal::NTuple{Dim,T}; tol=1e-6) where {Dim,T} = PlanePartition(Vec(normal), tol=tol)
(p::PlanePartition)(x, y) = abs((x - y) ⋅ p.normal) < p.tol