diff --git a/src/GeometryBasics.jl b/src/GeometryBasics.jl index c375acc7..d9a740d3 100644 --- a/src/GeometryBasics.jl +++ b/src/GeometryBasics.jl @@ -7,6 +7,8 @@ using EarCut_jll using Base: @propagate_inbounds +include("utils.jl") + include("fixed_arrays.jl") include("offsetintegers.jl") include("basic_types.jl") diff --git a/src/fixed_arrays.jl b/src/fixed_arrays.jl index c312b829..e1dc8668 100644 --- a/src/fixed_arrays.jl +++ b/src/fixed_arrays.jl @@ -121,21 +121,12 @@ abstract type AbstractPoint{Dim,T} <: StaticVector{Dim,T} end const Mat = SMatrix const VecTypes{N,T} = Union{StaticVector{N,T},NTuple{N,T}} -const Vecf{N} = Vec{N,Float32} -const Pointf{N} = Point{N,Float32} Base.isnan(p::Union{AbstractPoint,Vec}) = any(x -> isnan(x), p) +@alias(Point,1:4,Float32) +@alias(Vec,1:4,Float32) + for i in 1:4 - for T in [:Point, :Vec] - name = Symbol("$T$i") - namef = Symbol("$T$(i)f") - @eval begin - const $name = $T{$i} - const $namef = $T{$i,Float32} - export $name - export $namef - end - end name = Symbol("Mat$i") namef = Symbol("Mat$(i)f") @eval begin diff --git a/src/primitives/cylinders.jl b/src/primitives/cylinders.jl index 9804cf53..2e16726b 100644 --- a/src/primitives/cylinders.jl +++ b/src/primitives/cylinders.jl @@ -17,8 +17,9 @@ end A `Cylinder2` or `Cylinder3` is a 2D/3D cylinder defined by its origin point, its extremity and a radius. `origin`, `extremity` and `r`, must be specified. """ -const Cylinder2{T} = Cylinder{2,T} -const Cylinder3{T} = Cylinder{3,T} +Cylinder2, Cylinder3 + +@alias(Cylinder,2:3) origin(c::Cylinder{N,T}) where {N,T} = c.origin extremity(c::Cylinder{N,T}) where {N,T} = c.extremity diff --git a/src/primitives/rectangles.jl b/src/primitives/rectangles.jl index 5e8677af..968456c4 100644 --- a/src/primitives/rectangles.jl +++ b/src/primitives/rectangles.jl @@ -31,17 +31,8 @@ There is an additional unexported alias `RectT` that simply reverses the order o Rect, Rect2, Rect3, RectT, Rectf, Rect2f, Rect3f, Recti, Rect2i, Rect3i const Rect{N,T} = HyperRectangle{N,T} -const Rect2{T} = Rect{2,T} -const Rect3{T} = Rect{3,T} const RectT{T} = Rect{N,T} where {N} - -const Rectf{N} = Rect{N,Float32} -const Rect2f = Rect2{Float32} -const Rect3f = Rect3{Float32} - -const Recti{N} = HyperRectangle{N,Int} -const Rect2i = Rect2{Int} -const Rect3i = Rect3{Int} +@alias(Rect,2:3,Int,Float32) Rect() = Rect{2,Float32}() diff --git a/src/utils.jl b/src/utils.jl new file mode 100644 index 00000000..dcf92df3 --- /dev/null +++ b/src/utils.jl @@ -0,0 +1,27 @@ +const typesuffix = Dict(Float32=>"f", Int=>"i") + +macro alias(T, dims, types...) + for i in eval(dims) + name = Symbol("$T$i") + @eval begin + const $name = $T{$i} + export $name + end + end + for t in eval(types) + name = Symbol("$T$(typesuffix[eval(t)])") + @eval begin + const $name{N} = $T{N,$t} + export $name + end + end + for i in eval(dims) + for t in eval(types) + name = Symbol("$T$(i)$(typesuffix[eval(t)])") + @eval begin + const $name = $T{$i,$t} + export $name + end + end + end +end \ No newline at end of file