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
2 changes: 1 addition & 1 deletion src/discretization/maxlength.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct MaxLengthDiscretization{ℒ<:Len} <: DiscretizationMethod
MaxLengthDiscretization(length::ℒ) where {ℒ<:Len} = new{float(ℒ)}(length)
end

MaxLengthDiscretization(length) = MaxLengthDiscretization(addunit(length, u"m"))
MaxLengthDiscretization(length) = MaxLengthDiscretization(aslen(length))

function discretize(box::Box, method::MaxLengthDiscretization)
sizes = ceil.(Int, _sides(box) ./ method.length)
Expand Down
2 changes: 1 addition & 1 deletion src/domains/trajecs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end

CylindricalTrajectory(centroids, radius::Len) = CylindricalTrajectory(collect(centroids), radius)

CylindricalTrajectory(centroids, radius) = CylindricalTrajectory(centroids, addunit(radius, u"m"))
CylindricalTrajectory(centroids, radius) = CylindricalTrajectory(centroids, aslen(radius))

CylindricalTrajectory(centroids::Vector{P}) where {P<:Point} = CylindricalTrajectory(centroids, oneunit(lentype(P)))

Expand Down
2 changes: 1 addition & 1 deletion src/geometries/primitives/ball.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct Ball{M<:Manifold,C<:CRS,ℒ<:Len} <: Primitive{M,C}
Ball(center::Point{M,C}, radius::ℒ) where {M<:Manifold,C<:CRS,ℒ<:Len} = new{M,C,float(ℒ)}(center, radius)
end

Ball(center::Point, radius) = Ball(center, addunit(radius, u"m"))
Ball(center::Point, radius) = Ball(center, aslen(radius))

Ball(center::Tuple, radius) = Ball(Point(center), radius)

Expand Down
2 changes: 1 addition & 1 deletion src/geometries/primitives/circle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct Circle{C<:CRS,P<:Plane{C},ℒ<:Len} <: Primitive{𝔼{3},C}
Circle(plane::P, radius::ℒ) where {C<:CRS,P<:Plane{C},ℒ<:Len} = new{C,P,float(ℒ)}(plane, radius)
end

Circle(plane::Plane, radius) = Circle(plane, addunit(radius, u"m"))
Circle(plane::Plane, radius) = Circle(plane, aslen(radius))

"""
Circle(p1, p2, p3)
Expand Down
2 changes: 1 addition & 1 deletion src/geometries/primitives/cylinder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct Cylinder{C<:CRS,P<:Plane{C},ℒ<:Len} <: Primitive{𝔼{3},C}
Cylinder(bot::P, top::P, radius::ℒ) where {C<:CRS,P<:Plane{C},ℒ<:Len} = new{C,P,float(ℒ)}(bot, top, radius)
end

Cylinder(bot::P, top::P, radius) where {P<:Plane} = Cylinder(bot, top, addunit(radius, u"m"))
Cylinder(bot::P, top::P, radius) where {P<:Plane} = Cylinder(bot, top, aslen(radius))

function Cylinder(start::Point, finish::Point, radius)
dir = finish - start
Expand Down
2 changes: 1 addition & 1 deletion src/geometries/primitives/cylindersurface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct CylinderSurface{C<:CRS,P<:Plane{C},ℒ<:Len} <: Primitive{𝔼{3},C}
CylinderSurface(bot::P, top::P, radius::ℒ) where {C<:CRS,P<:Plane{C},ℒ<:Len} = new{C,P,float(ℒ)}(bot, top, radius)
end

CylinderSurface(bot::P, top::P, radius) where {P<:Plane} = CylinderSurface(bot, top, addunit(radius, u"m"))
CylinderSurface(bot::P, top::P, radius) where {P<:Plane} = CylinderSurface(bot, top, aslen(radius))

function CylinderSurface(start::Point, finish::Point, radius)
dir = finish - start
Expand Down
2 changes: 1 addition & 1 deletion src/geometries/primitives/disk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct Disk{C<:CRS,P<:Plane{C},ℒ<:Len} <: Primitive{𝔼{3},C}
Disk(plane::P, radius::ℒ) where {C<:CRS,P<:Plane{C},ℒ<:Len} = new{C,P,float(ℒ)}(plane, radius)
end

Disk(plane::Plane, radius) = Disk(plane, addunit(radius, u"m"))
Disk(plane::Plane, radius) = Disk(plane, aslen(radius))

paramdim(::Type{<:Disk}) = 2

Expand Down
2 changes: 1 addition & 1 deletion src/geometries/primitives/ellipsoid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct Ellipsoid{C<:CRS,Mₚ<:Manifold,R,ℒ<:Len} <: Primitive{𝔼{3},C}
new{C,Mₚ,R,float(ℒ)}(radii, center, rotation)
end

Ellipsoid(radii::Tuple, center::Point, rotation) = Ellipsoid(addunit.(radii, u"m"), center, rotation)
Ellipsoid(radii::Tuple, center::Point, rotation) = Ellipsoid(aslen.(radii), center, rotation)

Ellipsoid(radii::Tuple, center::Tuple, rotation) = Ellipsoid(radii, Point(center), rotation)

Expand Down
3 changes: 1 addition & 2 deletions src/geometries/primitives/paraboloidsurface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ end

ParaboloidSurface(apex::Point, radius::Len, focallength::Len) = ParaboloidSurface(apex, promote(radius, focallength)...)

ParaboloidSurface(apex::Point, radius, focallength) =
ParaboloidSurface(apex, addunit(radius, u"m"), addunit(focallength, u"m"))
ParaboloidSurface(apex::Point, radius, focallength) = ParaboloidSurface(apex, aslen(radius), aslen(focallength))

ParaboloidSurface(apex::Tuple, radius, focallength) = ParaboloidSurface(Point(apex), radius, focallength)

Expand Down
2 changes: 1 addition & 1 deletion src/geometries/primitives/sphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct Sphere{M<:Manifold,C<:CRS,ℒ<:Len} <: Primitive{M,C}
Sphere(center::Point{M,C}, radius::ℒ) where {M<:Manifold,C<:CRS,ℒ<:Len} = new{M,C,float(ℒ)}(center, radius)
end

Sphere(center::Point, radius) = Sphere(center, addunit(radius, u"m"))
Sphere(center::Point, radius) = Sphere(center, aslen(radius))

Sphere(center::Tuple, radius) = Sphere(Point(center), radius)

Expand Down
5 changes: 2 additions & 3 deletions src/geometries/primitives/torus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ end

Torus(center::Point, direction::Vec, major::Len, minor::Len) = Torus(center, direction, promote(major, minor)...)

Torus(center::Point, direction::Vec, major, minor) =
Torus(center, direction, addunit(major, u"m"), addunit(minor, u"m"))
Torus(center::Point, direction::Vec, major, minor) = Torus(center, direction, aslen(major), aslen(minor))

Torus(center::Tuple, direction::Tuple, major, minor) = Torus(Point(center), Vec(direction), major, minor)

Expand All @@ -37,7 +36,7 @@ function Torus(p1::Point, p2::Point, p3::Point, minor::Len)
Torus(center(c), normal(p), radius(c), minor)
end

Torus(p1::Point, p2::Point, p3::Point, minor) = Torus(p1, p2, p3, addunit(minor, u"m"))
Torus(p1::Point, p2::Point, p3::Point, minor) = Torus(p1, p2, p3, aslen(minor))

Torus(p1::Tuple, p2::Tuple, p3::Tuple, minor) = Torus(Point(p1), Point(p2), Point(p3), minor)

Expand Down
4 changes: 2 additions & 2 deletions src/neighborhoods/metricball.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ end

MetricBall(radii::NTuple{Dim,Len}, rotation=I) where {Dim} = MetricBall(promote(radii...), rotation)

MetricBall(radii::Tuple, rotation=I) = MetricBall(addunit.(radii, u"m"), rotation)
MetricBall(radii::Tuple, rotation=I) = MetricBall(aslen.(radii), rotation)

MetricBall(radius::Len, metric=Euclidean()) = MetricBall((radius,), I, metric)

MetricBall(radius::Number, metric=Euclidean()) = MetricBall(addunit(radius, u"m"), metric)
MetricBall(radius::Number, metric=Euclidean()) = MetricBall(aslen(radius), metric)

"""
hasequalradii(ball)
Expand Down
2 changes: 1 addition & 1 deletion src/partitioning/ball.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct BallPartition{ℒ<:Len,M} <: PointPredicatePartitionMethod
BallPartition(radius::ℒ, metric::M) where {ℒ<:Len,M} = new{float(ℒ),M}(radius, metric)
end

BallPartition(radius, metric) = BallPartition(addunit(radius, u"m"), metric)
BallPartition(radius, metric) = BallPartition(aslen(radius), metric)

BallPartition(radius; metric=Euclidean()) = BallPartition(radius, metric)

Expand Down
2 changes: 1 addition & 1 deletion src/partitioning/block.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end

BlockPartition(sides::NTuple{Dim,Len}; neighbors=false) where {Dim} = BlockPartition(promote(sides...), neighbors)

BlockPartition(sides::Tuple; neighbors=false) = BlockPartition(addunit.(sides, u"m"), neighbors)
BlockPartition(sides::Tuple; neighbors=false) = BlockPartition(aslen.(sides), neighbors)

BlockPartition(sides...; neighbors=false) = BlockPartition(sides; neighbors=neighbors)

Expand Down
2 changes: 1 addition & 1 deletion src/partitioning/direction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct DirectionPartition{V<:Vec,ℒ<:Len} <: PointPredicatePartitionMethod
DirectionPartition(dir::V, tol::ℒ) where {V<:Vec,ℒ<:Len} = new{V,float(ℒ)}(unormalize(dir), tol)
end

DirectionPartition(dir::Vec, tol) = DirectionPartition(dir, addunit(tol, u"m"))
DirectionPartition(dir::Vec, tol) = DirectionPartition(dir, aslen(tol))

DirectionPartition(dir::Vec; tol=atol(eltype(dir))) = DirectionPartition(dir, tol)

Expand Down
2 changes: 1 addition & 1 deletion src/partitioning/plane.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct PlanePartition{V<:Vec,ℒ<:Len} <: PointPredicatePartitionMethod
PlanePartition(normal::V, tol::ℒ) where {V<:Vec,ℒ<:Len} = new{V,float(ℒ)}(unormalize(normal), tol)
end

PlanePartition(normal::Vec, tol) = PlanePartition(normal, addunit(tol, u"m"))
PlanePartition(normal::Vec, tol) = PlanePartition(normal, aslen(tol))

PlanePartition(normal::Vec; tol=atol(eltype(normal))) = PlanePartition(normal, tol)

Expand Down
2 changes: 1 addition & 1 deletion src/sampling/ball.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end

BallSampling(radius::Len; metric=Euclidean(), maxsize=nothing) = BallSampling(radius, metric, maxsize)

BallSampling(radius; kwargs...) = BallSampling(addunit(radius, u"m"); kwargs...)
BallSampling(radius; kwargs...) = BallSampling(aslen(radius); kwargs...)

function sampleinds(rng::AbstractRNG, d::Domain, method::BallSampling)
radius = method.radius
Expand Down
2 changes: 1 addition & 1 deletion src/sampling/block.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end

BlockSampling(sides::NTuple{Dim,Len}) where {Dim} = BlockSampling(promote(sides...))

BlockSampling(sides::Tuple) = BlockSampling(addunit.(sides, u"m"))
BlockSampling(sides::Tuple) = BlockSampling(aslen.(sides))

BlockSampling(sides...) = BlockSampling(sides)

Expand Down
2 changes: 1 addition & 1 deletion src/sampling/mindistance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end

MinDistanceSampling(α::Len, ρ::Len, δ, metric) = MinDistanceSampling(promote(α, ρ)..., δ, metric)

MinDistanceSampling(α, ρ, δ, metric) = MinDistanceSampling(addunit(α, u"m"), addunit(ρ, u"m"), δ, metric)
MinDistanceSampling(α, ρ, δ, metric) = MinDistanceSampling(aslen(α), aslen(ρ), δ, metric)

MinDistanceSampling(α::T; ρ=T(0.65), δ=100, metric=Euclidean()) where {T} = MinDistanceSampling(α, ρ, δ, metric)

Expand Down
2 changes: 1 addition & 1 deletion src/simplification/douglaspeucker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct DouglasPeuckerSimplification{ℒ<:Len} <: SimplificationMethod
DouglasPeuckerSimplification(τ::ℒ) where {ℒ<:Len} = new{float(ℒ)}(τ)
end

DouglasPeuckerSimplification(τ) = DouglasPeuckerSimplification(addunit(τ, u"m"))
DouglasPeuckerSimplification(τ) = DouglasPeuckerSimplification(aslen(τ))

function simplify(chain::Chain, method::DouglasPeuckerSimplification)
verts = _douglaspeucker(vertices(chain), method.τ)
Expand Down
2 changes: 1 addition & 1 deletion src/simplification/selinger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct SelingerSimplification{ℒ<:Len} <: SimplificationMethod
SelingerSimplification(τ::ℒ) where {ℒ<:Len} = new{float(ℒ)}(τ)
end

SelingerSimplification(τ) = SelingerSimplification(addunit(τ, u"m"))
SelingerSimplification(τ) = SelingerSimplification(aslen(τ))

function simplify(chain::Chain, method::SelingerSimplification)
ℒ = lentype(chain)
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/affine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Affine{Dim,M<:StaticMatrix{Dim,Dim},V<:StaticVector{Dim,<:Len}} <: Coordi
end
end

Affine(A::StaticMatrix{Dim,Dim}, b::StaticVector{Dim}) where {Dim} = Affine(A, addunit(b, u"m"))
Affine(A::StaticMatrix{Dim,Dim}, b::StaticVector{Dim}) where {Dim} = Affine(A, aslen.(b))

function Affine(A::AbstractMatrix, b::AbstractVector)
sz = size(A)
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/bridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Bridge{ℒ<:Len} <: GeometricTransform
Bridge(δ::ℒ) where {ℒ<:Len} = new{float(ℒ)}(δ)
end

Bridge(δ) = Bridge(addunit(δ, u"m"))
Bridge(δ) = Bridge(aslen(δ))

Bridge() = Bridge(0.0u"m")

Expand Down
2 changes: 1 addition & 1 deletion src/transforms/translate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ end

Translate(offsets::NTuple{Dim,Len}) where {Dim} = Translate(promote(offsets...))

Translate(offsets::Tuple) = Translate(addunit.(offsets, u"m"))
Translate(offsets::Tuple) = Translate(aslen.(offsets))

Translate(offsets...) = Translate(offsets)

Expand Down
32 changes: 16 additions & 16 deletions src/units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ const Met{T} = Quantity{T,u"𝐋",typeof(u"m")}
const Deg{T} = Quantity{T,NoDims,typeof(u"°")}

"""
addunit(x, u)
aslen(x)

Adds the unit only if the argument is not a quantity, otherwise an error is thrown.
Adds meter unit if the argument is not a quantity
with length unit, otherwise, returns `x` as is.
"""
addunit(x::Number, u) = x * u
addunit(x::AbstractArray{<:Number}, u) = x * u
addunit(::Quantity, _) = throw(ArgumentError("invalid units, please check the documentation"))
addunit(::AbstractArray{<:Quantity}, _) = throw(ArgumentError("invalid units, please check the documentation"))
aslen(x::Len) = x
aslen(x::Number) = x * u"m"
aslen(::Quantity) = throw(ArgumentError("invalid length unit"))

"""
aslentype(T)

If `T` has length unit, return it. If `T` is number, return it with meter unit.
Otherwise, throw an error.
"""
aslentype(::Type{T}) where {T<:Len} = T
aslentype(::Type{T}) where {T<:Number} = Met{T}
aslentype(::Type{<:Quantity}) = throw(ArgumentError("invalid length unit"))

"""
numconvert(T, x)
Expand All @@ -34,13 +44,3 @@ otherwise, converts the unit of `x` to `u`.
"""
withunit(x::Number, u) = x * u
withunit(x::Quantity, u) = uconvert(u, x)

"""
aslentype(T)

If `T` has length unit, return it. If `T` is number, return it with meter unit.
Otherwise, throw an error.
"""
aslentype(::Type{T}) where {T<:Len} = T
aslentype(::Type{T}) where {T<:Number} = Met{T}
aslentype(::Type{<:Quantity}) = throw(ArgumentError("invalid units, please use a valid length unit"))
2 changes: 1 addition & 1 deletion src/vectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ end

Vec(coords::NTuple{Dim,ℒ}) where {Dim,ℒ<:Len} = Vec{Dim,float(ℒ)}(coords)
Vec(coords::NTuple{Dim,Len}) where {Dim} = Vec(promote(coords...))
Vec(coords::NTuple{Dim,Number}) where {Dim} = Vec(addunit.(coords, u"m"))
Vec(coords::NTuple{Dim,Number}) where {Dim} = Vec(aslen.(coords))

Vec(coords::Number...) = Vec(coords)

Expand Down
Loading