Skip to content

Replace f0 type suffix with f, rename Rect types #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2021
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
18 changes: 9 additions & 9 deletions docs/src/decomposition.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ This can be done for any arbitrary primitive, by overloading the following inter

```julia

function GeometryBasics.coordinates(rect::Rect2D, nvertices=(2,2))
function GeometryBasics.coordinates(rect::Rect2, nvertices=(2,2))
mini, maxi = extrema(rect)
xrange, yrange = LinRange.(mini, maxi, nvertices)
return ivec(((x,y) for x in xrange, y in yrange))
end

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

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

As you can see, the normals are automatically calculated,
Expand All @@ -79,11 +79,11 @@ the same is true for texture coordinates. You can overload this behavior by over
`decompose` works a bit different for normals/texturecoordinates, since they dont have their own element type.
Instead, you can use `decompose` like this:
```julia
decompose(UV(Vec2f0), rect)
decompose(Normal(Vec3f0), rect)
decompose(UV(Vec2f), rect)
decompose(Normal(Vec3f), rect)
# the short form for the above:
decompose_uv(rect)
decompose_normals(rect)
```
You can also use `triangle_mesh`, `normal_mesh` and `uv_normal_mesh` to call the
`mesh` constructor with predefined element types (Point2/3f0, Vec2/3f0), and the requested attributes.
`mesh` constructor with predefined element types (Point2/3f, Vec2/3f), and the requested attributes.
4 changes: 3 additions & 1 deletion src/GeometryBasics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ include("triangulation.jl")
include("lines.jl")
include("boundingboxes.jl")

include("deprecated.jl")

export AbstractGeometry, GeometryPrimitive
export Mat, Point, Vec
export LineFace, Polytope, Line, NgonFace, convert_simplex
Expand Down Expand Up @@ -61,7 +63,7 @@ export uv_mesh, normal_mesh, uv_normal_mesh
export height, origin, radius, width, widths, xwidth, yheight
export HyperSphere, Circle, Sphere
export Cylinder, Cylinder2, Cylinder3, Pyramid, extremity
export HyperRectangle, Rect, Rect2D, Rect3D, IRect, IRect2D, IRect3D, FRect, FRect2D, FRect3D
export HyperRectangle, Rect, Rect2, Rect3, Recti, Rect2i, Rect3i, Rectf, Rect2f, Rect3f
export before, during, isinside, isoutside, meets, overlaps, intersects, finishes
export centered, direction, area, volume, update
export max_dist_dim, max_euclidean, max_euclideansq, min_dist_dim, min_euclidean
Expand Down
30 changes: 30 additions & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Base: @deprecate_binding

# Types ...f0 renamed to ...f
@deprecate_binding Vecf0 Vecf
@deprecate_binding Pointf0 Pointf
for i in 1:4
for T in [:Point, :Vec]
oldname = Symbol("$T$(i)f0")
newname = Symbol("$T$(i)f")
@eval begin
@deprecate_binding $oldname $newname
end
end
oldname = Symbol("Mat$(i)f0")
newname = Symbol("Mat$(i)f")
@eval begin
@deprecate_binding $oldname $newname
end
end

# Rect types
@deprecate_binding Rect2D Rect2
@deprecate_binding Rect3D Rect3
@deprecate_binding FRect Rectf
@deprecate_binding FRect2D Rect2f
@deprecate_binding FRect3D Rect3f
@deprecate_binding IRect Recti
@deprecate_binding IRect2D Rect2i
@deprecate_binding IRect3D Rect3i
@deprecate_binding TRect RectT
19 changes: 9 additions & 10 deletions src/fixed_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,31 +121,30 @@ abstract type AbstractPoint{Dim,T} <: StaticVector{Dim,T} end

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

# Create constes like Mat4f0, Point2, Point2f0
for i in 1:4
for T in [:Point, :Vec]
name = Symbol("$T$i")
namef0 = Symbol("$T$(i)f0")
namef = Symbol("$T$(i)f")
@eval begin
const $name = $T{$i}
const $namef0 = $T{$i,Float32}
const $namef = $T{$i,Float32}
export $name
export $namef0
export $namef
end
end
name = Symbol("Mat$i")
namef0 = Symbol("Mat$(i)f0")
namef = Symbol("Mat$(i)f")
@eval begin
const $name{T} = $Mat{$i,$i,T,$(i * i)}
const $namef0 = $name{Float32}
const $namef = $name{Float32}
export $name
export $namef0
export $namef
end
end

export Mat, Vec, Point, unit
export Vecf0, Pointf0
export Vecf, Pointf
12 changes: 6 additions & 6 deletions src/interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ To transport this information to the various decompose methods, you can wrap it
in the Tesselation object e.g. like this:

```julia
sphere = Sphere(Point3f0(0), 1)
sphere = Sphere(Point3f(0), 1)
m1 = mesh(sphere) # uses a default value for tesselation
m2 = mesh(Tesselation(sphere, 64)) # uses 64 for tesselation
length(coordinates(m1)) != length(coordinates(m2))
```
For grid based tesselation, you can also use a tuple:
```julia
rect = Rect2D(0, 0, 1, 1)
rect = Rect2(0, 0, 1, 1)
Tesselation(rect, (5, 5))
"""
struct Tesselation{Dim,T,Primitive,NGrid}
Expand Down Expand Up @@ -81,7 +81,7 @@ function texturecoordinates(tesselation::Tesselation)
end

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

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

struct UV{T} end
UV(::Type{T}) where {T} = UV{T}()
UV() = UV(Vec2f0)
UV() = UV(Vec2f)
struct UVW{T} end
UVW(::Type{T}) where {T} = UVW{T}()
UVW() = UVW(Vec3f0)
UVW() = UVW(Vec3f)
struct Normal{T} end
Normal(::Type{T}) where {T} = Normal{T}()
Normal() = Normal(Vec3f0)
Normal() = Normal(Vec3f)

function decompose(::Type{F}, primitive) where {F<:AbstractFace}
f = faces(primitive)
Expand Down
20 changes: 10 additions & 10 deletions src/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const GLPlainMesh3D = GLPlainMesh{3}
UVMesh{Dim, T}

PlainMesh with texture coordinates meta at each point.
`uvmesh.uv isa AbstractVector{Vec2f0}`
`uvmesh.uv isa AbstractVector{Vec2f}`
"""
const UVMesh{Dim,T} = TriangleMesh{Dim,T,PointWithUV{Dim,T}}
const GLUVMesh{Dim} = UVMesh{Dim,Float32}
Expand All @@ -55,7 +55,7 @@ const GLUVMesh3D = UVMesh{3}
NormalMesh{Dim, T}

PlainMesh with normals meta at each point.
`normalmesh.normals isa AbstractVector{Vec3f0}`
`normalmesh.normals isa AbstractVector{Vec3f}`
"""
const NormalMesh{Dim,T} = TriangleMesh{Dim,T,PointWithNormal{Dim,T}}
const GLNormalMesh{Dim} = NormalMesh{Dim,Float32}
Expand All @@ -66,8 +66,8 @@ const GLNormalMesh3D = GLNormalMesh{3}
NormalUVMesh{Dim, T}

PlainMesh with normals and uv meta at each point.
`normalmesh.normals isa AbstractVector{Vec3f0}`
`normalmesh.uv isa AbstractVector{Vec2f0}`
`normalmesh.normals isa AbstractVector{Vec3f}`
`normalmesh.uv isa AbstractVector{Vec2f}`
"""
const NormalUVMesh{Dim,T} = TriangleMesh{Dim,T,PointWithUVNormal{Dim,T}}
const GLNormalUVMesh{Dim} = NormalUVMesh{Dim,Float32}
Expand All @@ -78,8 +78,8 @@ const GLNormalUVMesh3D = GLNormalUVMesh{3}
NormalUVWMesh{Dim, T}

PlainMesh with normals and uvw (texture coordinates in 3D) meta at each point.
`normalmesh.normals isa AbstractVector{Vec3f0}`
`normalmesh.uvw isa AbstractVector{Vec3f0}`
`normalmesh.normals isa AbstractVector{Vec3f}`
`normalmesh.uvw isa AbstractVector{Vec3f}`
"""
const NormalUVWMesh{Dim,T} = TriangleMesh{Dim,T,PointWithUVWNormal{Dim,T}}
const GLNormalUVWMesh{Dim} = NormalUVWMesh{Dim,Float32}
Expand Down Expand Up @@ -176,17 +176,17 @@ function triangle_mesh(primitive::Meshable{N}; nvertices=nothing) where {N}
end

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

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

function normal_mesh(points::AbstractVector{<:AbstractPoint},
faces::AbstractVector{<:AbstractFace})
_points = decompose(Point3f0, points)
_points = decompose(Point3f, points)
_faces = decompose(GLTriangleFace, faces)
return Mesh(meta(_points; normals=normals(_points, _faces)), _faces)
end
Expand All @@ -196,7 +196,7 @@ function normal_mesh(primitive::Meshable{N}; nvertices=nothing) where {N}
@warn("nvertices argument deprecated. Wrap primitive in `Tesselation(primitive, nvertices)`")
primitive = Tesselation(primitive, nvertices)
end
return mesh(primitive; pointtype=Point{N,Float32}, normaltype=Vec3f0,
return mesh(primitive; pointtype=Point{N,Float32}, normaltype=Vec3f,
facetype=GLTriangleFace)
end

Expand Down
16 changes: 8 additions & 8 deletions src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ function _precompile_()
@warnpcfail precompile(Tuple{typeof(decompose),Type{Point{2, Float32}},HyperRectangle{2, Float32}}) # time: 0.026609203
@warnpcfail precompile(Tuple{Type{HyperRectangle{3, Float32}},HyperRectangle{2, Float32}}) # time: 0.023717888
@warnpcfail precompile(Tuple{typeof(+),HyperRectangle{3, Float32},Point{3, Float32}}) # time: 0.006633118
@warnpcfail precompile(Tuple{Type{Rect2D{T} where T},Float32,Float32,Float32,Float32}) # time: 0.001636267
@warnpcfail precompile(Tuple{Type{Rect2{T} where T},Float32,Float32,Float32,Float32}) # time: 0.001636267
@warnpcfail precompile(Tuple{typeof(*),HyperRectangle{2, Float32},Float32}) # time: 0.001057589

if Base.VERSION >= v"1.6.0-DEV.1083"
@warnpcfail precompile(triangle_mesh, (Polygon{2, Float32, Point2f0, LineString{2, Float32, Point2f0,
Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f0, Point2f0}, TupleView{Tuple{Point2f0, Point2f0}, 2, 1, Vector{Point2f0}}, false}},
Vector{LineString{2, Float32, Point2f0, Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f0, Point2f0}, TupleView{Tuple{Point2f0, Point2f0}, 2, 1, Vector{Point2f0}}, false}}}},))
@warnpcfail precompile(triangle_mesh, (Polygon{2, Float32, Point2f, LineString{2, Float32, Point2f,
Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f, Point2f}, TupleView{Tuple{Point2f, Point2f}, 2, 1, Vector{Point2f}}, false}},
Vector{LineString{2, Float32, Point2f, Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f, Point2f}, TupleView{Tuple{Point2f, Point2f}, 2, 1, Vector{Point2f}}, false}}}},))
else
@warnpcfail precompile(triangle_mesh, (Polygon{2, Float32, Point2f0, LineString{2, Float32, Point2f0,
Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f0, Point2f0}, TupleView{Tuple{Point2f0, Point2f0}, 2, 1, Vector{Point2f0}}}},
Vector{LineString{2, Float32, Point2f0, Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f0, Point2f0}, TupleView{Tuple{Point2f0, Point2f0}, 2, 1, Vector{Point2f0}}}}}},))
@warnpcfail precompile(triangle_mesh, (Polygon{2, Float32, Point2f, LineString{2, Float32, Point2f,
Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f, Point2f}, TupleView{Tuple{Point2f, Point2f}, 2, 1, Vector{Point2f}}}},
Vector{LineString{2, Float32, Point2f, Base.ReinterpretArray{Line{2, Float32}, 1, Tuple{Point2f, Point2f}, TupleView{Tuple{Point2f, Point2f}, 2, 1, Vector{Point2f}}}}}},))
end

@warnpcfail precompile(split_intersections, (Vector{Point2f0},))
@warnpcfail precompile(split_intersections, (Vector{Point2f},))
end
Loading