diff --git a/src/GeometryBasics.jl b/src/GeometryBasics.jl index 34596a08..2bfbba91 100644 --- a/src/GeometryBasics.jl +++ b/src/GeometryBasics.jl @@ -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") @@ -24,8 +23,11 @@ include("triangulation.jl") include("lines.jl") include("boundingboxes.jl") +# points +export AbstractPoint, Point, PointMeta, PointWithUV + +# geometries 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 @@ -35,7 +37,6 @@ export Triangle, TriangleP export AbstractFace, TriangleFace, QuadFace, GLTriangleFace export OffsetInteger, ZeroIndex, OneIndex, GLIndex export FaceView, SimpleFaceView -export AbstractPoint, PointMeta, PointWithUV export PolygonMeta, MultiPointMeta, MultiLineStringMeta, MeshMeta, LineStringMeta, MultiPolygonMeta export decompose, coordinates, faces, normals, decompose_uv, decompose_normals, @@ -46,18 +47,18 @@ export AbstractMesh, Mesh, TriangleMesh export GLNormalMesh2D, PlainTriangleMesh export MetaT, meta_table -# all the different predefined mesh types -# Note: meshes can contain arbitrary meta information, +# meshes export AbstractMesh, TriangleMesh, PlainMesh, GLPlainMesh, GLPlainMesh2D, GLPlainMesh3D export UVMesh, GLUVMesh, GLUVMesh2D, GLUVMesh3D export NormalMesh, GLNormalMesh, GLNormalMesh2D, GLNormalMesh3D export NormalUVMesh, GLNormalUVMesh, GLNormalUVMesh2D, GLNormalUVMesh3D export NormalUVWMesh, GLNormalUVWMesh, GLNormalUVWMesh2D, GLNormalUVWMesh3D -# mesh creation functions +# mesh creation export triangle_mesh, triangle_mesh, uv_mesh export uv_mesh, normal_mesh, uv_normal_mesh +# primitives export height, origin, radius, width, widths, xwidth, yheight export HyperSphere, Circle, Sphere export Cylinder, Cylinder2, Cylinder3, Pyramid, extremity @@ -67,8 +68,13 @@ export centered, direction, area, update export max_dist_dim, max_euclidean, max_euclideansq, min_dist_dim, min_euclidean export min_euclideansq, minmax_dist_dim, minmax_euclidean, minmax_euclideansq export self_intersections, split_intersections + +# bounding boxes export boundbox +# helper types +export Vec, Mat + if Base.VERSION >= v"1.4.2" include("precompile.jl") _precompile_() diff --git a/src/fixed_arrays.jl b/src/fixed_arrays.jl index 09a4dc0a..81cb9f8b 100644 --- a/src/fixed_arrays.jl +++ b/src/fixed_arrays.jl @@ -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 @@ -147,5 +146,4 @@ for i in 1:4 end end -export Mat, Vec, Point, unit export Vecf0, Pointf0 diff --git a/src/interfaces.jl b/src/interfaces.jl index e3024a2e..b0b8500f 100644 --- a/src/interfaces.jl +++ b/src/interfaces.jl @@ -149,11 +149,10 @@ 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{<:Point}) where {T} N = length(T) - positions_nd = decompose(Point{N,eltype(T)}, positions) - bb = boundbox(positions_nd) # Make sure we get this as points - return map(positions_nd) do p + bb = boundbox(positions) # Make sure we get this as points + return map(positions) do p return (p .- minimum(bb)) ./ widths(bb) end end diff --git a/src/primitives/particles.jl b/src/primitives/particles.jl deleted file mode 100644 index e3d80357..00000000 --- a/src/primitives/particles.jl +++ /dev/null @@ -1,4 +0,0 @@ -struct Particle{N,T} <: GeometryPrimitive{N,T} - position::Point{N,T} - velocity::Vec{N,T} -end diff --git a/src/primitives/rectangles.jl b/src/primitives/rectangles.jl index fa0ab6a2..619beba0 100644 --- a/src/primitives/rectangles.jl +++ b/src/primitives/rectangles.jl @@ -48,7 +48,7 @@ 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 @@ -56,7 +56,7 @@ function TRect{T}(v1::VecTypes{N,T1}, v2::VecTypes{N,T2}) where {N,T,T1,T2} 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 @@ -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 @@ -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)) @@ -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 @@ -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 diff --git a/test/fixed_arrays.jl b/test/fixed_arrays.jl deleted file mode 100644 index 497ee829..00000000 --- a/test/fixed_arrays.jl +++ /dev/null @@ -1,16 +0,0 @@ -using Test - -@testset "conversion" begin - @test convert(Point, (2, 3)) === Point(2, 3) - @test convert(Point, (2.0, 3)) === Point(2.0, 3.0) -end - -@testset "broadcast" begin - @testset for T in (Vec, Point) - x = [T(2, 3), T(7, 3)] - - @test [T(4, 9), T(14, 9)] == x .* T(2, 3) - @test [T(4, 6), T(9, 6)] == x .+ T(2, 3) - @test [T(0, 0), T(5, 0)] == x .- T(2, 3) - end -end diff --git a/test/geometrytypes.jl b/test/geometrytypes.jl index c30fb710..81eaea78 100644 --- a/test/geometrytypes.jl +++ b/test/geometrytypes.jl @@ -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 @@ -86,7 +86,7 @@ end @test m isa GLNormalMesh muv = uv_mesh(s) - @test boundbox(Point.(texturecoordinates(muv))) == FRect2D(Vec2f0(0), Vec2f0(1.0)) + @test boundbox(Point.(texturecoordinates(muv))) == Rect(0.0f0, 0.0f0, 0.0f0, 1.0f0, 1.0f0, 1.0f0) end end diff --git a/test/runtests.jl b/test/runtests.jl index b60cbe1f..4f017281 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -465,7 +465,7 @@ end 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) + @test boundbox(Point.(uv)) == Rect(0, 0, 0, 1, 1, 1) points = decompose(Point2f0, Circle(Point2f0(0), 1)) m = GeometryBasics.mesh(points) @@ -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) @@ -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) @@ -653,8 +653,4 @@ end include("geometrytypes.jl") end -@testset "Point & Vec type" begin - include("fixed_arrays.jl") -end - end # testset "GeometryBasics"