Skip to content
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
8 changes: 4 additions & 4 deletions src/primitives/spheres.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ centered(S::Type{<: HyperSphere}) = S(Point3f(0), 0.5f0)

function coordinates(s::Circle, nvertices=64)
r = radius(s); o = origin(s)
ps = [r * Point(cos(phi), sin(phi)) + o for phi in LinRange(0, 2pi, nvertices)]
ps = [r * Point(cospi(phi), sinpi(phi)) + o for phi in LinRange(0, 2, nvertices)]
# ps[end] = o
return ps
end
Expand All @@ -59,9 +59,9 @@ end


function coordinates(s::Sphere, nvertices=24)
θ = LinRange(0, pi, nvertices)
φ = LinRange(0, 2pi, nvertices)
inner(θ, φ) = Point(cos(φ) * sin(θ), sin(φ) * sin(θ), cos(θ)) .* s.r .+ s.center
θ = LinRange(0, 1, nvertices)
φ = LinRange(0, 2, nvertices)
inner(θ, φ) = Point(cospi(φ) * sinpi(θ), sinpi(φ) * sinpi(θ), cospi(θ)) .* s.r .+ s.center
return [inner(θ, φ) for φ in φ for θ in θ]
end

Expand Down
18 changes: 18 additions & 0 deletions test/geometrytypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,24 @@ end
@test Point2f(-0.5) in circle
@test centered(Circle) == Circle(Point2f(0), 0.5f0)
@test centered(Circle{Float64}) == Circle(Point2(0.0), 0.5)

@testset "bit-exact seam and pole vertices" begin
for T in (Float32, Float64)
n = 24
sphere_points = coordinates(Sphere(Point{3,T}(0.2, -0.3, 0.4), T(1.3)), n)
first_meridian = sphere_points[1:n]
last_meridian = sphere_points[(end - n + 1):end]
@test all(map(===, first_meridian, last_meridian))

top_pole = sphere_points[1:n:end]
bottom_pole = sphere_points[n:n:end]
@test all(p === top_pole[1] for p in top_pole)
@test all(p === bottom_pole[1] for p in bottom_pole)

circle_points = coordinates(Circle(Point{2,T}(0.2, -0.3), T(1.3)), n)
@test circle_points[1] === circle_points[end]
end
end
end

@testset "LineStrings" begin
Expand Down
Loading