Skip to content

Commit 17fe9e8

Browse files
authored
Merge pull request #97 from knuesel/replace-f0-f
Replace f0 type suffix with f, rename Rect types
2 parents 798ddaa + e2dd42d commit 17fe9e8

File tree

12 files changed

+201
-170
lines changed

12 files changed

+201
-170
lines changed

docs/src/decomposition.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ This can be done for any arbitrary primitive, by overloading the following inter
99

1010
```julia
1111

12-
function GeometryBasics.coordinates(rect::Rect2D, nvertices=(2,2))
12+
function GeometryBasics.coordinates(rect::Rect2, nvertices=(2,2))
1313
mini, maxi = extrema(rect)
1414
xrange, yrange = LinRange.(mini, maxi, nvertices)
1515
return ivec(((x,y) for x in xrange, y in yrange))
1616
end
1717

18-
function GeometryBasics.faces(rect::Rect2D, nvertices=(2, 2))
18+
function GeometryBasics.faces(rect::Rect2, nvertices=(2, 2))
1919
w, h = nvertices
2020
idx = LinearIndices(nvertices)
2121
quad(i, j) = QuadFace{Int}(idx[i, j], idx[i+1, j], idx[i+1, j+1], idx[i, j+1])
@@ -29,7 +29,7 @@ can also return any `AbstractArray`.
2929
With these methods defined, this constructor will magically work:
3030

3131
```julia
32-
rect = Rect2D(0.0, 0.0, 1.0, 1.0)
32+
rect = Rect2(0.0, 0.0, 1.0, 1.0)
3333
m = GeometryBasics.mesh(rect)
3434
```
3535
If you want to set the `nvertices` argument, you need to wrap your primitive in a `Tesselation`
@@ -48,7 +48,7 @@ But will actually not be an iterator anymore. Instead, the mesh constructor uses
4848
the `decompose` function, that will collect the result of coordinates and will
4949
convert it to a concrete element type:
5050
```julia
51-
decompose(Point2f0, rect) == convert(Vector{Point2f0}, collect(coordinates(rect)))
51+
decompose(Point2f, rect) == convert(Vector{Point2f}, collect(coordinates(rect)))
5252
```
5353
The element conversion is handled by `simplex_convert`, which also handles convert
5454
between different face types:
@@ -65,12 +65,12 @@ decompose(Point, rect) isa Vector{Point{2, Float64}}
6565
```
6666
You can also pass the element type to `mesh`:
6767
```julia
68-
m = GeometryBasics.mesh(rect, pointtype=Point2f0, facetype=QuadFace{Int})
68+
m = GeometryBasics.mesh(rect, pointtype=Point2f, facetype=QuadFace{Int})
6969
```
7070
You can also set the uv and normal type for the mesh constructor, which will then
7171
calculate them for you, with the requested element type:
7272
```julia
73-
m = GeometryBasics.mesh(rect, uv=Vec2f0, normaltype=Vec3f0)
73+
m = GeometryBasics.mesh(rect, uv=Vec2f, normaltype=Vec3f)
7474
```
7575

7676
As you can see, the normals are automatically calculated,
@@ -79,11 +79,11 @@ the same is true for texture coordinates. You can overload this behavior by over
7979
`decompose` works a bit different for normals/texturecoordinates, since they dont have their own element type.
8080
Instead, you can use `decompose` like this:
8181
```julia
82-
decompose(UV(Vec2f0), rect)
83-
decompose(Normal(Vec3f0), rect)
82+
decompose(UV(Vec2f), rect)
83+
decompose(Normal(Vec3f), rect)
8484
# the short form for the above:
8585
decompose_uv(rect)
8686
decompose_normals(rect)
8787
```
8888
You can also use `triangle_mesh`, `normal_mesh` and `uv_normal_mesh` to call the
89-
`mesh` constructor with predefined element types (Point2/3f0, Vec2/3f0), and the requested attributes.
89+
`mesh` constructor with predefined element types (Point2/3f, Vec2/3f), and the requested attributes.

src/GeometryBasics.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ include("triangulation.jl")
2424
include("lines.jl")
2525
include("boundingboxes.jl")
2626

27+
include("deprecated.jl")
28+
2729
export AbstractGeometry, GeometryPrimitive
2830
export Mat, Point, Vec
2931
export LineFace, Polytope, Line, NgonFace, convert_simplex
@@ -61,7 +63,7 @@ export uv_mesh, normal_mesh, uv_normal_mesh
6163
export height, origin, radius, width, widths, xwidth, yheight
6264
export HyperSphere, Circle, Sphere
6365
export Cylinder, Cylinder2, Cylinder3, Pyramid, extremity
64-
export HyperRectangle, Rect, Rect2D, Rect3D, IRect, IRect2D, IRect3D, FRect, FRect2D, FRect3D
66+
export HyperRectangle, Rect, Rect2, Rect3, Recti, Rect2i, Rect3i, Rectf, Rect2f, Rect3f
6567
export before, during, isinside, isoutside, meets, overlaps, intersects, finishes
6668
export centered, direction, area, volume, update
6769
export max_dist_dim, max_euclidean, max_euclideansq, min_dist_dim, min_euclidean

src/deprecated.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Base: @deprecate_binding
2+
3+
# Types ...f0 renamed to ...f
4+
@deprecate_binding Vecf0 Vecf
5+
@deprecate_binding Pointf0 Pointf
6+
for i in 1:4
7+
for T in [:Point, :Vec]
8+
oldname = Symbol("$T$(i)f0")
9+
newname = Symbol("$T$(i)f")
10+
@eval begin
11+
@deprecate_binding $oldname $newname
12+
end
13+
end
14+
oldname = Symbol("Mat$(i)f0")
15+
newname = Symbol("Mat$(i)f")
16+
@eval begin
17+
@deprecate_binding $oldname $newname
18+
end
19+
end
20+
21+
# Rect types
22+
@deprecate_binding Rect2D Rect2
23+
@deprecate_binding Rect3D Rect3
24+
@deprecate_binding FRect Rectf
25+
@deprecate_binding FRect2D Rect2f
26+
@deprecate_binding FRect3D Rect3f
27+
@deprecate_binding IRect Recti
28+
@deprecate_binding IRect2D Rect2i
29+
@deprecate_binding IRect3D Rect3i
30+
@deprecate_binding TRect RectT

src/fixed_arrays.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,31 +121,30 @@ abstract type AbstractPoint{Dim,T} <: StaticVector{Dim,T} end
121121

122122
const Mat = SMatrix
123123
const VecTypes{N,T} = Union{StaticVector{N,T},NTuple{N,T}}
124-
const Vecf0{N} = Vec{N,Float32}
125-
const Pointf0{N} = Point{N,Float32}
124+
const Vecf{N} = Vec{N,Float32}
125+
const Pointf{N} = Point{N,Float32}
126126
Base.isnan(p::Union{AbstractPoint,Vec}) = any(x -> isnan(x), p)
127127

128-
# Create constes like Mat4f0, Point2, Point2f0
129128
for i in 1:4
130129
for T in [:Point, :Vec]
131130
name = Symbol("$T$i")
132-
namef0 = Symbol("$T$(i)f0")
131+
namef = Symbol("$T$(i)f")
133132
@eval begin
134133
const $name = $T{$i}
135-
const $namef0 = $T{$i,Float32}
134+
const $namef = $T{$i,Float32}
136135
export $name
137-
export $namef0
136+
export $namef
138137
end
139138
end
140139
name = Symbol("Mat$i")
141-
namef0 = Symbol("Mat$(i)f0")
140+
namef = Symbol("Mat$(i)f")
142141
@eval begin
143142
const $name{T} = $Mat{$i,$i,T,$(i * i)}
144-
const $namef0 = $name{Float32}
143+
const $namef = $name{Float32}
145144
export $name
146-
export $namef0
145+
export $namef
147146
end
148147
end
149148

150149
export Mat, Vec, Point, unit
151-
export Vecf0, Pointf0
150+
export Vecf, Pointf

src/interfaces.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ To transport this information to the various decompose methods, you can wrap it
4343
in the Tesselation object e.g. like this:
4444
4545
```julia
46-
sphere = Sphere(Point3f0(0), 1)
46+
sphere = Sphere(Point3f(0), 1)
4747
m1 = mesh(sphere) # uses a default value for tesselation
4848
m2 = mesh(Tesselation(sphere, 64)) # uses 64 for tesselation
4949
length(coordinates(m1)) != length(coordinates(m2))
5050
```
5151
For grid based tesselation, you can also use a tuple:
5252
```julia
53-
rect = Rect2D(0, 0, 1, 1)
53+
rect = Rect2(0, 0, 1, 1)
5454
Tesselation(rect, (5, 5))
5555
"""
5656
struct Tesselation{Dim,T,Primitive,NGrid}
@@ -81,7 +81,7 @@ function texturecoordinates(tesselation::Tesselation)
8181
end
8282

8383
## Decompose methods
84-
# Dispatch type to make `decompose(UV{Vec2f0}, primitive)` work
84+
# Dispatch type to make `decompose(UV{Vec2f}, primitive)` work
8585
# and to pass through tesselation information
8686

8787
# Types that can be converted to a mesh via the functions below
@@ -91,13 +91,13 @@ const Meshable{Dim,T} = Union{Tesselation{Dim,T},Mesh{Dim,T},AbstractPolygon{Dim
9191

9292
struct UV{T} end
9393
UV(::Type{T}) where {T} = UV{T}()
94-
UV() = UV(Vec2f0)
94+
UV() = UV(Vec2f)
9595
struct UVW{T} end
9696
UVW(::Type{T}) where {T} = UVW{T}()
97-
UVW() = UVW(Vec3f0)
97+
UVW() = UVW(Vec3f)
9898
struct Normal{T} end
9999
Normal(::Type{T}) where {T} = Normal{T}()
100-
Normal() = Normal(Vec3f0)
100+
Normal() = Normal(Vec3f)
101101

102102
function decompose(::Type{F}, primitive) where {F<:AbstractFace}
103103
f = faces(primitive)

src/meshes.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const GLPlainMesh3D = GLPlainMesh{3}
4444
UVMesh{Dim, T}
4545
4646
PlainMesh with texture coordinates meta at each point.
47-
`uvmesh.uv isa AbstractVector{Vec2f0}`
47+
`uvmesh.uv isa AbstractVector{Vec2f}`
4848
"""
4949
const UVMesh{Dim,T} = TriangleMesh{Dim,T,PointWithUV{Dim,T}}
5050
const GLUVMesh{Dim} = UVMesh{Dim,Float32}
@@ -55,7 +55,7 @@ const GLUVMesh3D = UVMesh{3}
5555
NormalMesh{Dim, T}
5656
5757
PlainMesh with normals meta at each point.
58-
`normalmesh.normals isa AbstractVector{Vec3f0}`
58+
`normalmesh.normals isa AbstractVector{Vec3f}`
5959
"""
6060
const NormalMesh{Dim,T} = TriangleMesh{Dim,T,PointWithNormal{Dim,T}}
6161
const GLNormalMesh{Dim} = NormalMesh{Dim,Float32}
@@ -66,8 +66,8 @@ const GLNormalMesh3D = GLNormalMesh{3}
6666
NormalUVMesh{Dim, T}
6767
6868
PlainMesh with normals and uv meta at each point.
69-
`normalmesh.normals isa AbstractVector{Vec3f0}`
70-
`normalmesh.uv isa AbstractVector{Vec2f0}`
69+
`normalmesh.normals isa AbstractVector{Vec3f}`
70+
`normalmesh.uv isa AbstractVector{Vec2f}`
7171
"""
7272
const NormalUVMesh{Dim,T} = TriangleMesh{Dim,T,PointWithUVNormal{Dim,T}}
7373
const GLNormalUVMesh{Dim} = NormalUVMesh{Dim,Float32}
@@ -78,8 +78,8 @@ const GLNormalUVMesh3D = GLNormalUVMesh{3}
7878
NormalUVWMesh{Dim, T}
7979
8080
PlainMesh with normals and uvw (texture coordinates in 3D) meta at each point.
81-
`normalmesh.normals isa AbstractVector{Vec3f0}`
82-
`normalmesh.uvw isa AbstractVector{Vec3f0}`
81+
`normalmesh.normals isa AbstractVector{Vec3f}`
82+
`normalmesh.uvw isa AbstractVector{Vec3f}`
8383
"""
8484
const NormalUVWMesh{Dim,T} = TriangleMesh{Dim,T,PointWithUVWNormal{Dim,T}}
8585
const GLNormalUVWMesh{Dim} = NormalUVWMesh{Dim,Float32}
@@ -176,17 +176,17 @@ function triangle_mesh(primitive::Meshable{N}; nvertices=nothing) where {N}
176176
end
177177

178178
function uv_mesh(primitive::Meshable{N,T}) where {N,T}
179-
return mesh(primitive; pointtype=Point{N,Float32}, uv=Vec2f0, facetype=GLTriangleFace)
179+
return mesh(primitive; pointtype=Point{N,Float32}, uv=Vec2f, facetype=GLTriangleFace)
180180
end
181181

182182
function uv_normal_mesh(primitive::Meshable{N}) where {N}
183-
return mesh(primitive; pointtype=Point{N,Float32}, uv=Vec2f0, normaltype=Vec3f0,
183+
return mesh(primitive; pointtype=Point{N,Float32}, uv=Vec2f, normaltype=Vec3f,
184184
facetype=GLTriangleFace)
185185
end
186186

187187
function normal_mesh(points::AbstractVector{<:AbstractPoint},
188188
faces::AbstractVector{<:AbstractFace})
189-
_points = decompose(Point3f0, points)
189+
_points = decompose(Point3f, points)
190190
_faces = decompose(GLTriangleFace, faces)
191191
return Mesh(meta(_points; normals=normals(_points, _faces)), _faces)
192192
end
@@ -196,7 +196,7 @@ function normal_mesh(primitive::Meshable{N}; nvertices=nothing) where {N}
196196
@warn("nvertices argument deprecated. Wrap primitive in `Tesselation(primitive, nvertices)`")
197197
primitive = Tesselation(primitive, nvertices)
198198
end
199-
return mesh(primitive; pointtype=Point{N,Float32}, normaltype=Vec3f0,
199+
return mesh(primitive; pointtype=Point{N,Float32}, normaltype=Vec3f,
200200
facetype=GLTriangleFace)
201201
end
202202

src/precompile.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ function _precompile_()
2222
@warnpcfail precompile(Tuple{typeof(decompose),Type{Point{2, Float32}},HyperRectangle{2, Float32}}) # time: 0.026609203
2323
@warnpcfail precompile(Tuple{Type{HyperRectangle{3, Float32}},HyperRectangle{2, Float32}}) # time: 0.023717888
2424
@warnpcfail precompile(Tuple{typeof(+),HyperRectangle{3, Float32},Point{3, Float32}}) # time: 0.006633118
25-
@warnpcfail precompile(Tuple{Type{Rect2D{T} where T},Float32,Float32,Float32,Float32}) # time: 0.001636267
25+
@warnpcfail precompile(Tuple{Type{Rect2{T} where T},Float32,Float32,Float32,Float32}) # time: 0.001636267
2626
@warnpcfail precompile(Tuple{typeof(*),HyperRectangle{2, Float32},Float32}) # time: 0.001057589
2727

2828
if Base.VERSION >= v"1.6.0-DEV.1083"
29-
@warnpcfail precompile(triangle_mesh, (Polygon{2, Float32, Point2f0, LineString{2, Float32, Point2f0,
30-
Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f0, Point2f0}, TupleView{Tuple{Point2f0, Point2f0}, 2, 1, Vector{Point2f0}}, false}},
31-
Vector{LineString{2, Float32, Point2f0, Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f0, Point2f0}, TupleView{Tuple{Point2f0, Point2f0}, 2, 1, Vector{Point2f0}}, false}}}},))
29+
@warnpcfail precompile(triangle_mesh, (Polygon{2, Float32, Point2f, LineString{2, Float32, Point2f,
30+
Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f, Point2f}, TupleView{Tuple{Point2f, Point2f}, 2, 1, Vector{Point2f}}, false}},
31+
Vector{LineString{2, Float32, Point2f, Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f, Point2f}, TupleView{Tuple{Point2f, Point2f}, 2, 1, Vector{Point2f}}, false}}}},))
3232
else
33-
@warnpcfail precompile(triangle_mesh, (Polygon{2, Float32, Point2f0, LineString{2, Float32, Point2f0,
34-
Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f0, Point2f0}, TupleView{Tuple{Point2f0, Point2f0}, 2, 1, Vector{Point2f0}}}},
35-
Vector{LineString{2, Float32, Point2f0, Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f0, Point2f0}, TupleView{Tuple{Point2f0, Point2f0}, 2, 1, Vector{Point2f0}}}}}},))
33+
@warnpcfail precompile(triangle_mesh, (Polygon{2, Float32, Point2f, LineString{2, Float32, Point2f,
34+
Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f, Point2f}, TupleView{Tuple{Point2f, Point2f}, 2, 1, Vector{Point2f}}}},
35+
Vector{LineString{2, Float32, Point2f, Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f, Point2f}, TupleView{Tuple{Point2f, Point2f}, 2, 1, Vector{Point2f}}}}}},))
3636
end
3737

38-
@warnpcfail precompile(split_intersections, (Vector{Point2f0},))
38+
@warnpcfail precompile(split_intersections, (Vector{Point2f},))
3939
end

0 commit comments

Comments
 (0)