Skip to content

Commit 28c2aa7

Browse files
mikeingoldjuliohm
andauthored
New parameterization functions for Cone and ConeSurface (#1020)
* Test change to radius from cos to tan * Drop unneeded type spec * Add new param functions for Cone and ConeSurface * Bugfix - missed name change * Bugfix - updated changed name * Bugfix in point-vector-svector operations * Adjust formatting to match prior style * Add tests for ConeSurface parameterization * Bugfix in test - wrong name * Add DomainError test for Cone param * Bugfix - wrong name in test * Bugfix - wrong name in test * Bugfix - promote tuple to Point for comparison * Add tests for Cone param function * Apply suggestions from code review Co-authored-by: Júlio Hoffimann <[email protected]> * Update test/primitives.jl * Update test/primitives.jl * Rename arguments and internal names, use some abstract API * Update variable name * Rename arguments and internal names, use some abstract APIs * Bugfix - update name * Conversion to abstract methods * Revert test changes to simplify merge * Re-add tests after merge * Final adjustments --------- Co-authored-by: Júlio Hoffimann <[email protected]>
1 parent 443b9bc commit 28c2aa7

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

src/boundingboxes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ end
5555

5656
function boundingbox(c::ConeSurface)
5757
us = (0, 1 / 4, 1 / 2, 3 / 4)
58-
vs = (1,)
58+
vs = (0,)
5959
ps = [c(u, v) for (u, v) in Iterators.product(us, vs)]
6060
boundingbox([ps; apex(c)])
6161
end

src/geometries/primitives/cone.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,12 @@ halfangle(c::Cone) = atan(radius(base(c)), height(c))
3434

3535
Base.isapprox(c₁::Cone, c₂::Cone; atol=atol(lentype(c₁)), kwargs...) =
3636
isapprox(boundary(c₁), boundary(c₂); atol, kwargs...)
37+
38+
function (c::Cone)(r, φ, h)
39+
if (r < 0 || r > 1) ||< 0 || φ > 1) || (h < 0 || h > 1)
40+
throw(DomainError((r, φ, h), "c(r, φ, h) is not defined for r, φ, h outside [0, 1]³."))
41+
end
42+
a = c.apex
43+
b = c.base(r, φ)
44+
Segment(b, a)(h)
45+
end

src/geometries/primitives/conesurface.jl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ function (c::ConeSurface)(φ, h)
3636
if< 0 || φ > 1) || (h < 0 || h > 1)
3737
throw(DomainError((φ, h), "c(φ, h) is not defined for φ, h outside [0, 1]²."))
3838
end
39-
n = -normal(c.base)
40-
v = c.base(T(0), T(0)) - c.apex
41-
l = norm(v)
42-
θ = (n, v)
43-
o = c.apex + T(h) * v
44-
r = T(h) * l * cos(θ)
45-
s = Circle(Plane(o, n), r)
46-
s(T(φ))
39+
a = c.apex
40+
b = c.base(one(T), φ)
41+
Segment(b, a)(h)
4742
end

src/sampling/regular.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ firstoffset(::CylinderSurface) = (n -> zero(n), n -> zero(n))
7575
lastoffset(::CylinderSurface) = (n -> inv(n), n -> zero(n))
7676
extrapoints(c::CylinderSurface, sz) = (bottom(c)(0, 0), top(c)(0, 0))
7777

78-
firstoffset(::ConeSurface) = (n -> zero(n), n -> inv(n))
79-
lastoffset(::ConeSurface) = (n -> inv(n), n -> zero(n))
80-
extrapoints(c::ConeSurface, sz) = (apex(c), base(c)(0, 0))
78+
firstoffset(::ConeSurface) = (n -> zero(n), n -> zero(n))
79+
lastoffset(::ConeSurface) = (n -> inv(n), n -> inv(n))
80+
extrapoints(c::ConeSurface, sz) = (base(c)(0, 0), apex(c))
8181

8282
firstoffset(::FrustumSurface) = (n -> zero(n), n -> zero(n))
8383
lastoffset(::FrustumSurface) = (n -> inv(n), n -> zero(n))

test/primitives.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,15 +1046,19 @@ end
10461046
@test crs(c) <: Cartesian{NoDatum}
10471047
@test Meshes.lentype(c) ==
10481048
@test boundary(c) == ConeSurface(d, a)
1049+
@test_throws DomainError c(T(0), T(0), nextfloat(T(1)))
10491050

10501051
p = Plane(cart(0, 0, 0), vector(0, 0, 1))
10511052
d = Disk(p, T(2))
1052-
a = T.((0, 0, 1))
1053+
a = cart(0, 0, 1)
10531054
c = Cone(d, a)
10541055
@test embeddim(c) == 3
10551056
@test paramdim(c) == 3
10561057
@test crs(c) <: Cartesian{NoDatum}
10571058
@test Meshes.lentype(c) ==
1059+
@test c(T(0), T(0), T(0)) centroid(p)
1060+
@test c(T(0), T(0), T(1)) a
1061+
@test c(T(1.0), T(0.25), T(0.0)) cart(0, 2, 0)
10581062

10591063
p = Plane(cart(0, 0, 0), vector(0, 0, 1))
10601064
d = Disk(p, T(2))
@@ -1120,15 +1124,19 @@ end
11201124
@test crs(s) <: Cartesian{NoDatum}
11211125
@test Meshes.lentype(s) ==
11221126
@test isnothing(boundary(s))
1127+
@test_throws DomainError s(T(0), nextfloat(T(1)))
11231128

11241129
p = Plane(cart(0, 0, 0), vector(0, 0, 1))
11251130
d = Disk(p, T(2))
1126-
a = T.((0, 0, 1))
1131+
a = cart(0, 0, 1)
11271132
c = ConeSurface(d, a)
11281133
@test embeddim(c) == 3
11291134
@test paramdim(c) == 2
11301135
@test crs(c) <: Cartesian{NoDatum}
11311136
@test Meshes.lentype(c) ==
1137+
@test c(T(0), T(0)) cart(2, 0, 0)
1138+
@test c(T(0), T(1)) a
1139+
@test c(T(0.25), T(0)) cart(0, 2, 0)
11321140

11331141
p = Plane(cart(0, 0, 0), vector(0, 0, 1))
11341142
d = Disk(p, T(2))

0 commit comments

Comments
 (0)