Skip to content
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
4 changes: 2 additions & 2 deletions src/geometries/primitives/ball.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ center(b::Ball) = b.center

radius(b::Ball) = b.radius

==(b₁::Ball, b₂::Ball) = b₁.center == b₂.center && b₁.radius == b₂.radius
==(b₁::Ball, b₂::Ball) = center(b₁) == center(b₂) && radius(b₁) == radius(b₂)

Base.isapprox(b₁::Ball, b₂::Ball; atol=atol(lentype(b₁)), kwargs...) =
isapprox(b₁.center, b₂.center; atol, kwargs...) && isapprox(b₁.radius, b₂.radius; atol, kwargs...)
isapprox(center(b₁), center(b₂); atol, kwargs...) && isapprox(radius(b₁), radius(b₂); atol, kwargs...)

function (b::Ball{𝔼{2}})(ρ, φ)
if (ρ < 0 || ρ > 1) || (φ < 0 || φ > 1)
Expand Down
28 changes: 14 additions & 14 deletions src/geometries/primitives/bezier.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ ncontrols(b::BezierCurve) = length(b.controls)

degree(b::BezierCurve) = ncontrols(b) - 1

==(b₁::BezierCurve, b₂::BezierCurve) = b₁.controls == b₂.controls
==(b₁::BezierCurve, b₂::BezierCurve) = controls(b₁) == controls(b₂)

Base.isapprox(b₁::BezierCurve, b₂::BezierCurve; atol=atol(lentype(b₁)), kwargs...) =
length(b₁.controls) == length(b₂.controls) &&
all(isapprox(p₁, p₂; atol, kwargs...) for (p₁, p₂) in zip(b₁.controls, b₂.controls))
ncontrols(b₁) == ncontrols(b₂) &&
all(isapprox(p₁, p₂; atol, kwargs...) for (p₁, p₂) in zip(controls(b₁), controls(b₂)))

"""
Evaluation method used to obtain a point along
Expand All @@ -64,15 +64,15 @@ See <https://en.wikipedia.org/wiki/Horner%27s_method>.
"""
struct Horner <: BezierEvalMethod end

(curve::BezierCurve)(t) = curve(t, DeCasteljau())
(b::BezierCurve)(t) = b(t, DeCasteljau())

# Apply DeCasteljau's method
function (curve::BezierCurve)(t, ::DeCasteljau)
function (b::BezierCurve)(t, ::DeCasteljau)
if t < 0 || t > 1
throw(DomainError(t, "b(t) is not defined for t outside [0, 1]."))
end
ss = segments(Rope(curve.controls))
points = [s(t) for s in ss]
rope = Rope(controls(b))
points = [s(t) for s in segments(rope)]
if length(points) == 1
points[1]
else
Expand All @@ -85,14 +85,14 @@ end
# curve, aᵢ = binomial(n, i) * pᵢ * t̄ⁿ⁻ⁱ and t̄ = (1 - t).
# Horner's rule recursively reconstructs B from a sequence bᵢ
# with bₙ = aₙ and bᵢ₋₁ = aᵢ₋₁ + bᵢ * t until b₀ = B.
function (curve::BezierCurve)(t, ::Horner)
function (b::BezierCurve)(t, ::Horner)
if t < 0 || t > 1
throw(DomainError(t, "b(t) is not defined for t outside [0, 1]."))
end
T = numtype(lentype(curve))
cs = curve.controls
T = numtype(lentype(b))
cs = controls(b)
t̄ = one(T) - t
n = degree(curve)
n = degree(b)
pₙ = to(last(cs))
aₙ = pₙ

Expand All @@ -109,7 +109,7 @@ function (curve::BezierCurve)(t, ::Horner)
end

b₀ = bᵢ₋₁
withcrs(curve, b₀)
withcrs(b, b₀)
end

# -----------
Expand All @@ -119,14 +119,14 @@ end
function Base.show(io::IO, b::BezierCurve)
ioctx = IOContext(io, :compact => true)
print(io, "BezierCurve(controls: [")
join(ioctx, b.controls, ", ")
join(ioctx, controls(b), ", ")
print(io, "])")
end

function Base.show(io::IO, ::MIME"text/plain", b::BezierCurve)
summary(io, b)
println(io)
print(io, "└─ controls: [")
join(io, b.controls, ", ")
join(io, controls(b), ", ")
print(io, "]")
end
12 changes: 6 additions & 6 deletions src/geometries/primitives/box.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ Base.minimum(b::Box) = b.min

Base.maximum(b::Box) = b.max

Base.extrema(b::Box) = b.min, b.max
Base.extrema(b::Box) = minimum(b), maximum(b)

diagonal(b::Box{<:𝔼}) = norm(b.max - b.min)
diagonal(b::Box{<:𝔼}) = norm(maximum(b) - minimum(b))

sides(b::Box{<:𝔼}) = Tuple(b.max - b.min)
sides(b::Box{<:𝔼}) = Tuple(maximum(b) - minimum(b))

==(b₁::Box, b₂::Box) = b₁.min == b₂.min && b₁.max == b₂.max
==(b₁::Box, b₂::Box) = minimum(b₁) == minimum(b₂) && maximum(b₁) == maximum(b₂)

Base.isapprox(b₁::Box, b₂::Box; atol=atol(lentype(b₁)), kwargs...) =
isapprox(b₁.min, b₂.min; atol, kwargs...) && isapprox(b₁.max, b₂.max; atol, kwargs...)
isapprox(minimum(b₁), minimum(b₂); atol, kwargs...) && isapprox(maximum(b₁), maximum(b₂); atol, kwargs...)

function (b::Box{<:𝔼})(uv...)
if !all(x -> 0 ≤ x ≤ 1, uv)
throw(DomainError(uv, "b(u, v, ...) is not defined for u, v, ... outside [0, 1]ⁿ."))
end
b.min + uv .* (b.max - b.min)
minimum(b) + uv .* (maximum(b) - minimum(b))
end
5 changes: 2 additions & 3 deletions src/geometries/primitives/disk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ function (d::Disk)(ρ, φ)
throw(DomainError((ρ, φ), "d(ρ, φ) is not defined for ρ, φ outside [0, 1]²."))
end
T = numtype(lentype(d))
r = d.radius
l = T(ρ) * r
l = T(ρ) * radius(d)
sφ, cφ = sincospi(2 * T(φ))
u = ustrip(l * cφ)
v = ustrip(l * sφ)
d.plane(u, v)
plane(d)(u, v)
end
14 changes: 7 additions & 7 deletions src/geometries/primitives/ellipsoid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ center(e::Ellipsoid) = e.center

rotation(e::Ellipsoid) = e.rotation

==(e₁::Ellipsoid, e₂::Ellipsoid) = e₁.radii == e₂.radii && e₁.center == e₂.center && e₁.rotation == e₂.rotation
==(e₁::Ellipsoid, e₂::Ellipsoid) = radii(e₁) == radii(e₂) && center(e₁) == center(e₂) && rotation(e₁) == rotation(e₂)

function Base.isapprox(e₁::Ellipsoid, e₂::Ellipsoid; atol=atol(lentype(e₁)), kwargs...)
u = Unitful.promote_unit(unit(lentype(e₁)), unit(lentype(e₂)))
all(isapprox(r₁, r₂; atol, kwargs...) for (r₁, r₂) in zip(e₁.radii, e₂.radii)) &&
isapprox(e₁.center, e₂.center; atol, kwargs...) &&
isapprox(e₁.rotation, e₂.rotation; atol=ustrip(u, atol), kwargs...)
all(isapprox(r₁, r₂; atol, kwargs...) for (r₁, r₂) in zip(radii(e₁), radii(e₂))) &&
isapprox(center(e₁), center(e₂); atol, kwargs...) &&
isapprox(rotation(e₁), rotation(e₂); atol=ustrip(u, atol), kwargs...)
end

function (e::Ellipsoid)(θ, φ)
if (θ < 0 || θ > 1) || (φ < 0 || φ > 1)
throw(DomainError((θ, φ), "e(θ, φ) is not defined for θ, φ outside [0, 1]²."))
end
T = numtype(lentype(e))
r = e.radii
c = e.center
R = e.rotation
r = radii(e)
c = center(e)
R = rotation(e)
sθ, cθ = sincospi(T(θ))
sφ, cφ = sincospi(2 * T(φ))
x = r[1] * sθ * cφ
Expand Down
8 changes: 4 additions & 4 deletions src/geometries/primitives/paraboloidsurface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ Return the focal axis, connecting the focus with the apex of the paraboloid.
The axis is always aligned with the z direction.
"""
function axis(p::ParaboloidSurface)
f = focallength(p)
a = apex(p)
f = focallength(p)
Line(a, a + Vec(zero(f), zero(f), f))
end

==(p₁::ParaboloidSurface, p₂::ParaboloidSurface) =
p₁.apex == p₂.apex && p₁.radius == p₂.radius && p₁.focallength == p₂.focallength
apex(p₁) == apex(p₂) && radius(p₁) == radius(p₂) && focallength(p₁) == focallength(p₂)

Base.isapprox(p₁::ParaboloidSurface, p₂::ParaboloidSurface; atol=atol(lentype(p₁)), kwargs...) =
isapprox(apex(p₁), apex(p₂); atol, kwargs...) &&
isapprox(focallength(p₁), focallength(p₂); atol, kwargs...) &&
isapprox(radius(p₁), radius(p₂); atol, kwargs...)
isapprox(radius(p₁), radius(p₂); atol, kwargs...) &&
isapprox(focallength(p₁), focallength(p₂); atol, kwargs...)

function (p::ParaboloidSurface)(ρ, θ)
if (ρ < 0 || ρ > 1)
Expand Down
4 changes: 2 additions & 2 deletions src/geometries/primitives/sphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ center(s::Sphere) = s.center

radius(s::Sphere) = s.radius

==(s₁::Sphere, s₂::Sphere) = s₁.center == s₂.center && s₁.radius == s₂.radius
==(s₁::Sphere, s₂::Sphere) = center(s₁) == center(s₂) && radius(s₁) == radius(s₂)

Base.isapprox(s₁::Sphere, s₂::Sphere; atol=atol(lentype(s₁)), kwargs...) =
isapprox(s₁.center, s₂.center; atol, kwargs...) && isapprox(s₁.radius, s₂.radius; atol, kwargs...)
isapprox(center(s₁), center(s₂); atol, kwargs...) && isapprox(radius(s₁), radius(s₂); atol, kwargs...)

(s::Sphere)(uv...) = Ball(center(s), radius(s))(1, uv...)
10 changes: 5 additions & 5 deletions src/geometries/primitives/torus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ direction(t::Torus) = t.direction

radii(t::Torus) = (t.major, t.minor)

axis(t::Torus) = Line(t.center, t.center + t.direction)
axis(t::Torus) = Line(center(t), center(t) + direction(t))

==(t₁::Torus, t₂::Torus) =
t₁.center == t₂.center && t₁.direction == t₂.direction && t₁.major == t₂.major && t₁.minor == t₂.minor
center(t₁) == center(t₂) && direction(t₁) == direction(t₂) && t₁.major == t₂.major && t₁.minor == t₂.minor

Base.isapprox(t₁::Torus, t₂::Torus; atol=atol(lentype(t₁)), kwargs...) =
isapprox(t₁.center, t₂.center; atol, kwargs...) &&
isapprox(t₁.direction, t₂.direction; atol, kwargs...) &&
isapprox(center(t₁), center(t₂); atol, kwargs...) &&
isapprox(direction(t₁), direction(t₂); atol, kwargs...) &&
isapprox(t₁.major, t₂.major; atol, kwargs...) &&
isapprox(t₁.minor, t₂.minor; atol, kwargs...)

Expand All @@ -66,7 +66,7 @@ function (t::Torus)(θ, φ)
if (θ < 0 || θ > 1) || (φ < 0 || φ > 1)
throw(DomainError((θ, φ), "t(θ, φ) is not defined for θ, φ outside [0, 1]²."))
end
c, n⃗ = t.center, t.direction
c, n⃗ = center(t), direction(t)
R, r = t.major, t.minor

Q = urotbetween(Vec(zero(ℒ), zero(ℒ), oneunit(ℒ)), n⃗)
Expand Down
Loading