Skip to content

Commit 404e397

Browse files
authored
'Torus': Rename 'normal' to 'direction' (#1065)
1 parent 6683da6 commit 404e397

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

src/Meshes.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export
192192
sides,
193193
diagonal,
194194
focallength,
195+
direction,
195196

196197
# polytopes
197198
Polytope,

src/geometries/primitives/torus.jl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,27 @@
33
# ------------------------------------------------------------------
44

55
"""
6-
Torus(center, normal, major, minor)
6+
Torus(center, direction, major, minor)
77
88
A torus centered at `center` with axis of revolution directed by
9-
`normal` and with radii `major` and `minor`.
9+
`direction` and with radii `major` and `minor`.
1010
1111
"""
1212
struct Torus{C<:CRS,Mₚ<:Manifold,V<:Vec{3},ℒ<:Len} <: Primitive{𝔼{3},C}
1313
center::Point{Mₚ,C}
14-
normal::V
14+
direction::V
1515
major::ℒ
1616
minor::ℒ
17-
Torus(center::Point{Mₚ,C}, normal::V, major::ℒ, minor::ℒ) where {C<:CRS,Mₚ<:Manifold,V<:Vec{3},ℒ<:Len} =
18-
new{C,Mₚ,V,float(ℒ)}(center, normal, major, minor)
17+
Torus(center::Point{Mₚ,C}, direction::V, major::ℒ, minor::ℒ) where {C<:CRS,Mₚ<:Manifold,V<:Vec{3},ℒ<:Len} =
18+
new{C,Mₚ,V,float(ℒ)}(center, direction, major, minor)
1919
end
2020

21-
Torus(center::Point, normal::Vec, major::Len, minor::Len) = Torus(center, normal, promote(major, minor)...)
21+
Torus(center::Point, direction::Vec, major::Len, minor::Len) = Torus(center, direction, promote(major, minor)...)
2222

23-
Torus(center::Point, normal::Vec, major, minor) = Torus(center, normal, addunit(major, u"m"), addunit(minor, u"m"))
23+
Torus(center::Point, direction::Vec, major, minor) =
24+
Torus(center, direction, addunit(major, u"m"), addunit(minor, u"m"))
2425

25-
Torus(center::Tuple, normal::Tuple, major, minor) = Torus(Point(center), Vec(normal), major, minor)
26+
Torus(center::Tuple, direction::Tuple, major, minor) = Torus(Point(center), Vec(direction), major, minor)
2627

2728
"""
2829
Torus(p1, p2, p3, minor)
@@ -44,18 +45,18 @@ paramdim(::Type{<:Torus}) = 2
4445

4546
center(t::Torus) = t.center
4647

47-
normal(t::Torus) = t.normal
48+
direction(t::Torus) = t.direction
4849

4950
radii(t::Torus) = (t.major, t.minor)
5051

51-
axis(t::Torus) = Line(t.center, t.center + t.normal)
52+
axis(t::Torus) = Line(t.center, t.center + t.direction)
5253

5354
==(t₁::Torus, t₂::Torus) =
54-
t₁.center == t₂.center && t₁.normal == t₂.normal && t₁.major == t₂.major && t₁.minor == t₂.minor
55+
t₁.center == t₂.center && t₁.direction == t₂.direction && t₁.major == t₂.major && t₁.minor == t₂.minor
5556

5657
Base.isapprox(t₁::Torus, t₂::Torus; atol=atol(lentype(t₁)), kwargs...) =
5758
isapprox(t₁.center, t₂.center; atol, kwargs...) &&
58-
isapprox(t₁.normal, t₂.normal; atol, kwargs...) &&
59+
isapprox(t₁.direction, t₂.direction; atol, kwargs...) &&
5960
isapprox(t₁.major, t₂.major; atol, kwargs...) &&
6061
isapprox(t₁.minor, t₂.minor; atol, kwargs...)
6162

@@ -65,7 +66,7 @@ function (t::Torus)(θ, φ)
6566
if< 0 || θ > 1) ||< 0 || φ > 1)
6667
throw(DomainError((θ, φ), "t(θ, φ) is not defined for θ, φ outside [0, 1]²."))
6768
end
68-
c, n⃗ = t.center, t.normal
69+
c, n⃗ = t.center, t.direction
6970
R, r = t.major, t.minor
7071

7172
Q = urotbetween(Vec(zero(ℒ), zero(ℒ), oneunit(ℒ)), n⃗)

src/predicates/in.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ end
104104
function Base.in(p::Point, t::Torus)
105105
= lentype(p)
106106
R, r = radii(t)
107-
c, n = center(t), normal(t)
107+
c, n = center(t), direction(t)
108108
Q = urotbetween(n, Vec(zero(ℒ), zero(ℒ), oneunit(ℒ)))
109109
x, y, z = Q * (p - c)
110110
(R - (x^2 + y^2))^2 + z^2 r^2

test/primitives.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ end
12701270
@test crs(t) <: Cartesian{NoDatum}
12711271
@test Meshes.lentype(t) ==
12721272
@test center(t) == cart(1, 1, 1)
1273-
@test normal(t) == vector(1, 0, 0)
1273+
@test direction(t) == vector(1, 0, 0)
12741274
@test radii(t) == (T(2) * u"m", T(1) * u"m")
12751275
@test axis(t) == Line(cart(1, 1, 1), cart(2, 1, 1))
12761276
@test measure(t) 8 * T(π)^2 * u"m^2"
@@ -1305,19 +1305,19 @@ end
13051305

13061306
t = Torus(cart(1, 1, 1), vector(1, 0, 0), T(2), T(1))
13071307
@test sprint(show, t) ==
1308-
"Torus(center: (x: 1.0 m, y: 1.0 m, z: 1.0 m), normal: (1.0 m, 0.0 m, 0.0 m), major: 2.0 m, minor: 1.0 m)"
1308+
"Torus(center: (x: 1.0 m, y: 1.0 m, z: 1.0 m), direction: (1.0 m, 0.0 m, 0.0 m), major: 2.0 m, minor: 1.0 m)"
13091309
if T === Float32
13101310
@test sprint(show, MIME("text/plain"), t) == """
13111311
Torus
13121312
├─ center: Point(x: 1.0f0 m, y: 1.0f0 m, z: 1.0f0 m)
1313-
├─ normal: Vec(1.0f0 m, 0.0f0 m, 0.0f0 m)
1313+
├─ direction: Vec(1.0f0 m, 0.0f0 m, 0.0f0 m)
13141314
├─ major: 2.0f0 m
13151315
└─ minor: 1.0f0 m"""
13161316
else
13171317
@test sprint(show, MIME("text/plain"), t) == """
13181318
Torus
13191319
├─ center: Point(x: 1.0 m, y: 1.0 m, z: 1.0 m)
1320-
├─ normal: Vec(1.0 m, 0.0 m, 0.0 m)
1320+
├─ direction: Vec(1.0 m, 0.0 m, 0.0 m)
13211321
├─ major: 2.0 m
13221322
└─ minor: 1.0 m"""
13231323
end

0 commit comments

Comments
 (0)