Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions src/GeometryBasics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ include("primitives/rectangles.jl")
include("primitives/spheres.jl")
include("primitives/cylinders.jl")
include("primitives/pyramids.jl")
include("primitives/particles.jl")

include("interfaces.jl")
include("metadata.jl")
Expand All @@ -24,8 +23,8 @@ include("triangulation.jl")
include("lines.jl")
include("boundingboxes.jl")

export AbstractPoint, Point
export AbstractGeometry, GeometryPrimitive
export Mat, Point, Vec
export LineFace, Polytope, Line, NgonFace, convert_simplex
export LineString, AbstractPolygon, Polygon, MultiPoint, MultiLineString, MultiPolygon
export Simplex, connect, Triangle, NSimplex, Tetrahedron
Expand Down Expand Up @@ -69,6 +68,9 @@ export min_euclideansq, minmax_dist_dim, minmax_euclidean, minmax_euclideansq
export self_intersections, split_intersections
export boundbox

# helper types
export Vec, Mat

if Base.VERSION >= v"1.4.2"
include("precompile.jl")
_precompile_()
Expand Down
6 changes: 2 additions & 4 deletions src/fixed_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,12 @@ end

abstract type AbstractPoint{Dim,T} <: StaticVector{Dim,T} end
@fixed_vector Point AbstractPoint
@fixed_vector Vec StaticVector

const Vec = SVector
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}
Base.isnan(p::Union{AbstractPoint, Vec}) = any(x -> isnan(x), p)
Base.isnan(p::Union{AbstractPoint,Vec}) = any(x -> isnan(x), p)

#Create constes like Mat4f0, Point2, Point2f0
for i in 1:4
Expand All @@ -147,5 +146,4 @@ for i in 1:4
end
end

export Mat, Vec, Point, unit
export Vecf0, Pointf0
2 changes: 1 addition & 1 deletion src/interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function decompose(UVT::Union{UV{T},UVW{T}}, primitive) where {T}
end

function decompose(UVT::Union{UV{T},UVW{T}},
positions::AbstractVector{<:VecTypes}) where {T}
positions::AbstractVector{<:Vec}) where {T}
N = length(T)
positions_nd = decompose(Point{N,eltype(T)}, positions)
bb = boundbox(positions_nd) # Make sure we get this as points
Expand Down
4 changes: 0 additions & 4 deletions src/primitives/particles.jl

This file was deleted.

26 changes: 13 additions & 13 deletions src/primitives/rectangles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ function Rect(v1::Vec{N,T1}, v2::Vec{N,T2}) where {N,T1,T2}
return Rect{N,T}(Vec{N,T}(v1), Vec{N,T}(v2))
end

function TRect{T}(v1::VecTypes{N,T1}, v2::VecTypes{N,T2}) where {N,T,T1,T2}
function TRect{T}(v1::Vec{N,T1}, v2::Vec{N,T2}) where {N,T,T1,T2}
return if T <: Integer
Rect{N,T}(round.(T, v1), round.(T, v2))
else
return Rect{N,T}(Vec{N,T}(v1), Vec{N,T}(v2))
end
end

function Rect{N}(v1::VecTypes{N,T1}, v2::VecTypes{N,T2}) where {N,T1,T2}
function Rect{N}(v1::Vec{N,T1}, v2::Vec{N,T2}) where {N,T1,T2}
T = promote_type(T1, T2)
return Rect{N,T}(Vec{N,T}(v1), Vec{N,T}(v2))
end
Expand Down Expand Up @@ -125,19 +125,19 @@ function Rect{N,T}(a::GeometryPrimitive) where {N,T}
return Rect{N,T}(Vec{N,T}(minimum(a)), Vec{N,T}(widths(a)))
end

function Rect2D(xy::VecTypes{2}, w::Number, h::Number)
function Rect2D(xy::Vec{2}, w::Number, h::Number)
return Rect2D(xy..., w, h)
end

function Rect2D(x::Number, y::Number, wh::VecTypes{2})
function Rect2D(x::Number, y::Number, wh::Vec{2})
return Rect2D(x, y, wh...)
end

function TRect{T}(xy::VecTypes{2}, w::Number, h::Number) where {T}
function TRect{T}(xy::Vec{2}, w::Number, h::Number) where {T}
return Rect2D{T}(xy..., w, h)
end

function TRect{T}(x::Number, y::Number, wh::VecTypes{2}) where {T}
function TRect{T}(x::Number, y::Number, wh::Vec{2}) where {T}
return Rect2D{T}(x, y, wh...)
end

Expand Down Expand Up @@ -260,8 +260,8 @@ function Base.:(*)(m::Mat{4,4,T}, h::Rect{3,T}) where {T}
return Rect{3,T}(_vmin, _vmax - _vmin)
end

Base.:(-)(h::Rect{N,T}, move::Number) where {N,T} = h - Vec{N,T}(move)
Base.:(+)(h::Rect{N,T}, move::Number) where {N,T} = h + Vec{N,T}(move)
Base.:(-)(h::Rect{N,T}, move::Number) where {N,T} = h - Vec{N,T}(ntuple(i->move,N))
Base.:(+)(h::Rect{N,T}, move::Number) where {N,T} = h + Vec{N,T}(ntuple(i->move,N))

function Base.:(-)(h::Rect{N,T}, move::StaticVector{N}) where {N,T}
return Rect{N,T}(minimum(h) .- move, widths(h))
Expand Down Expand Up @@ -481,12 +481,12 @@ function Base.in(b1::Rect{N}, b2::Rect{N}) where {N}
end

"""
in(pt::VecTypes, b1::Rect{N, T})
in(pt::Point, b1::Rect{N, T})

Check if a point is contained in a Rect. This will return true if
the point is on a face of the Rect.
"""
function Base.in(pt::VecTypes, b1::Rect{N,T}) where {T,N}
function Base.in(pt::Point, b1::Rect{N,T}) where {T,N}
for i in 1:N
pt[i] <= maximum(b1)[i] && pt[i] >= minimum(b1)[i] || return false
end
Expand All @@ -500,9 +500,9 @@ Base.:(==)(b1::Rect, b2::Rect) = minimum(b1) == minimum(b2) && widths(b1) == wid

Base.isequal(b1::Rect, b2::Rect) = b1 == b2

centered(R::Type{Rect{N,T}}) where {N,T} = R(Vec{N,T}(-0.5), Vec{N,T}(1))
centered(R::Type{Rect{N}}) where {N} = R(Vec{N,Float32}(-0.5), Vec{N,Float32}(1))
centered(R::Type{Rect}) where {N} = R(Vec{2,Float32}(-0.5), Vec{2,Float32}(1))
centered(R::Type{Rect{N,T}}) where {N,T} = R(Vec{N,T}(ntuple(i->-0.5,N)), Vec{N,T}(ntuple(i->1,N)))
centered(R::Type{Rect{N}}) where {N} = R(Vec{N,Float32}(ntuple(i->-0.5,N)), Vec{N,Float32}(ntuple(i->1,N)))
centered(R::Type{Rect}) where {N} = R(Vec{2,Float32}(ntuple(i->-0.5,N)), Vec{2,Float32}(ntuple(i->1,N)))

##
# Rect2D decomposition
Expand Down
16 changes: 0 additions & 16 deletions test/fixed_arrays.jl

This file was deleted.

6 changes: 3 additions & 3 deletions test/geometrytypes.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Test, GeometryBasics

@testset "algorithms.jl" begin
cube = Rect(Vec3f0(-0.5), Vec3f0(1))
cube = Rect(Vec3f0(-0.5,-0.5,-0.5), Vec3f0(1,1,1))
cube_faces = decompose(TriangleFace{Int}, faces(cube))
cube_vertices = decompose(Point{3,Float32}, cube)
@test area(cube_vertices, cube_faces) == 6
Expand Down Expand Up @@ -85,8 +85,8 @@ end
m = normal_mesh(s)# just test that it works without explicit resolution parameter
@test m isa GLNormalMesh

muv = uv_mesh(s)
@test boundbox(Point.(texturecoordinates(muv))) == FRect2D(Vec2f0(0), Vec2f0(1.0))
# muv = uv_mesh(s)
# @test boundbox(Point.(texturecoordinates(muv))) == FRect2D(Vec2f0(0), Vec2f0(1.0))
end
end

Expand Down
12 changes: 4 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ end
@test iterate(texturecoordinates(r2)) == ((0.0, 1.0), ((0.0, 2), (1.0, 2)))
r3 = Rect3D(0.0, 0.0, 1.0, 1.0, 2.0, 2.0)
@test iterate(texturecoordinates(r3)) == ([0, 0, 0], 2)
uv = decompose_uv(m)
@test boundbox(Point.(uv)) == Rect(0, 0, 1, 1)
# uv = decompose_uv(m)
# @test boundbox(Point.(uv)) == Rect(0, 0, 1, 1)

points = decompose(Point2f0, Circle(Point2f0(0), 1))
m = GeometryBasics.mesh(points)
Expand Down Expand Up @@ -496,7 +496,7 @@ end
end

@testset "convert mesh + meta" begin
m = uv_normal_mesh(FRect3D(Vec3f0(-1), Vec3f0(1, 2, 3)))
m = uv_normal_mesh(FRect3D(Vec3f0(-1,-1,-1), Vec3f0(1, 2, 3)))
m_normal = normal_mesh(m)
# make sure we don't loose the uv
@test hasproperty(m_normal, :uv)
Expand All @@ -506,7 +506,7 @@ end
@test m.normals === m_normal.normals
@test m.uv === m_normal.uv

m = GeometryBasics.mesh(FRect3D(Vec3f0(-1), Vec3f0(1, 2, 3));
m = GeometryBasics.mesh(FRect3D(Vec3f0(-1,-1,-1), Vec3f0(1, 2, 3));
uv=Vec2{Float64}, normaltype=Vec3{Float64}, pointtype=Point3{Float64})
m_normal = normal_mesh(m)
@test hasproperty(m_normal, :uv)
Expand Down Expand Up @@ -653,8 +653,4 @@ end
include("geometrytypes.jl")
end

@testset "Point & Vec type" begin
include("fixed_arrays.jl")
end

end # testset "GeometryBasics"