Skip to content

Commit 95ea715

Browse files
committed
improve Sphere test coverage
1 parent fb756da commit 95ea715

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/primitives/spheres.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ function Base.in(x::Point, c::HyperSphere)
3636
return norm(origin(c) - x) radius(c)
3737
end
3838

39-
centered(S::Type{HyperSphere{N,T}}) where {N,T} = S(Vec{N,T}(0), T(0.5))
40-
function centered(::Type{T}) where {T<:HyperSphere}
41-
return centered(HyperSphere{ndims_or(T, 3),eltype_or(T, Float32)})
42-
end
39+
centered(S::Type{HyperSphere{N,T}}) where {N,T} = S(Point{N,T}(0), T(0.5))
40+
centered(S::Type{<: HyperSphere{N}}) where {N} = S(Point{N,Float32}(0), 0.5f0)
41+
centered(S::Type{<: HyperSphere}) = S(Point3f(0), 0.5f0)
4342

4443
function coordinates(s::Circle, nvertices=64)
4544
r = radius(s); o = origin(s)
@@ -52,7 +51,7 @@ function texturecoordinates(::Circle, nvertices=64)
5251
return coordinates(Circle(Point2f(0.5), 0.5f0), nvertices)
5352
end
5453

55-
# TODO: Consider generating meshes for circles with a point in the center so
54+
# TODO: Consider generating meshes for circles with a point in the center so
5655
# that the triangles are more regular
5756
# function faces(::Circle, nvertices=64)
5857
# return [GLTriangleFace(nvertices+1, i, mod1(i+1, nvertices)) for i in 1:nvertices]

test/geometrytypes.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,39 @@ end
317317
face_target = TriangleFace{Int}[[1, 2, 5], [1, 5, 4], [2, 3, 6], [2, 6, 5], [4, 5, 8],
318318
[4, 8, 7], [5, 6, 9], [5, 9, 8]]
319319
@test f == face_target
320+
321+
uv = decompose_uv(Tesselation(sphere, 3))
322+
uv_target = Vec{2, Float32}[[0.0, 1.0], [0.0, 0.5], [0.0, 0.0], [0.5, 1.0], [0.5, 0.5],
323+
[0.5, 0.0], [1.0, 1.0], [1.0, 0.5], [1.0, 0.0]]
324+
@test uv == uv_target
325+
326+
@test minimum(sphere) == Point3f(-1)
327+
@test maximum(sphere) == Point3f(1)
328+
@test origin(sphere) == Point3f(0)
329+
@test widths(sphere) == Vec3f(2)
330+
@test radius(sphere) == 1f0
331+
@test !(Point3f(1) in sphere)
332+
@test Point3f(0.5) in sphere
333+
@test centered(HyperSphere) == Sphere(Point3f(0), 0.5f0)
334+
@test centered(Sphere) == Sphere(Point3f(0), 0.5f0)
335+
@test centered(Sphere{Float64}) == Sphere(Point3(0.0), 0.5)
336+
320337
circle = Circle(Point2f(0), 1.0f0)
321338
points = decompose(Point2f, Tessellation(circle, 20))
322339
@test length(points) == 20
323340
tess_circle = Tessellation(circle, 32)
324341
mesh = triangle_mesh(tess_circle)
325342
@test decompose(Point2f, mesh) decompose(Point2f, tess_circle)
343+
344+
@test minimum(circle) == Point2f(-1)
345+
@test maximum(circle) == Point2f(1)
346+
@test origin(circle) == Point2f(0)
347+
@test widths(circle) == Vec2f(2)
348+
@test radius(circle) == 1f0
349+
@test !(Point2f(-1) in circle)
350+
@test Point2f(-0.5) in circle
351+
@test centered(Circle) == Circle(Point2f(0), 0.5f0)
352+
@test centered(Circle{Float64}) == Circle(Point2(0.0), 0.5)
326353
end
327354

328355
@testset "Rectangles" begin

0 commit comments

Comments
 (0)