Skip to content

Commit 20c0672

Browse files
mikeingoldjuliohm
andauthored
Fix units bug in Disk parametrization function (#1255)
* Add tests for mixed-unit-contructed parametrizations * Bugfix for disk parametrization units * Apply suggestion from @juliohm * Apply suggestion from @juliohm * Apply suggestion from @juliohm * Apply suggestion from @juliohm * Apply suggestion from @juliohm * Apply suggestion from @juliohm * Apply suggestion from @juliohm * Refactor Disk parametrization --------- Co-authored-by: Júlio Hoffimann <[email protected]>
1 parent eeedffa commit 20c0672

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/geometries/primitives/disk.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ function (d::Disk)(ρ, φ)
3737
if< 0 || ρ > 1) ||< 0 || φ > 1)
3838
throw(DomainError((ρ, φ), "d(ρ, φ) is not defined for ρ, φ outside [0, 1]²."))
3939
end
40-
T = numtype(lentype(d))
40+
= lentype(d)
41+
T = numtype(ℒ)
4142
l = T(ρ) * radius(d)
4243
sφ, cφ = sincospi(2 * T(φ))
43-
u = ustrip(l * cφ)
44-
v = ustrip(l * sφ)
44+
u = ustrip(unit(ℒ), l * cφ)
45+
v = ustrip(unit(ℒ), l * sφ)
4546
plane(d)(u, v)
4647
end

test/primitives.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,12 @@ end
798798
@test cart(0, 0, 1) d
799799
@test boundary(d) == Circle(p, T(2))
800800

801+
# ensure mixed-unit construction produces correct parametrization
802+
p = Plane(cart(0, 0, 0), vector(0, 0, 1))
803+
r = T(1) * u"mm"
804+
d = Disk(p, r)
805+
@test norm(d(1, 0) - center(d)) == r
806+
801807
p = Plane(cart(0, 0, 0), vector(0, 0, 1))
802808
d = Disk(p, T(2))
803809
equaltest(d)
@@ -842,6 +848,12 @@ end
842848
equaltest(c)
843849
isapproxtest(c)
844850

851+
# ensure mixed-unit construction produces correct parametrization
852+
p = Plane(cart(0, 0, 0), vector(0, 0, 1))
853+
r = T(1) * u"mm"
854+
c = Circle(p, r)
855+
@test norm(c(0) - center(c)) == r
856+
845857
# 3D circumcircle
846858
p1 = cart(0, 4, 0)
847859
p2 = cart(0, -4, 0)

0 commit comments

Comments
 (0)