Skip to content

Commit d3ad3a3

Browse files
refactor(cablebuilder): add inline r_ex for AbstractCablePart; update ConductorPart and InsulatorPart constructors
1 parent 60b1fdc commit d3ad3a3

1 file changed

Lines changed: 14 additions & 20 deletions

File tree

src/cablebuilder/types.jl

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
abstract type AbstractCablePart end
22

3+
@inline r_ex(p::AbstractCablePart) = r_ex(p.shape)
4+
35
struct ConductorPart{L, T, S <: AbstractShape{L, T}} <: AbstractCablePart
46
tag::Symbol
57
shape::S
@@ -10,19 +12,15 @@ function ConductorPart(
1012
tag::Symbol,
1113
shape::AbstractShape{L, T_shape},
1214
mat::Material{T_mat},
13-
) where {L, T_shape, T_mat}
15+
) where {L, T_shape <: Real, T_mat <: Real}
1416
# 1. Ask the compiler what the safest common type is.
15-
T_common = promote_type(T_shape, T_mat)
17+
T = promote_type(T_shape, T_mat)
1618

1719
# 2. Let native dispatch handle the translation.
18-
shape_promoted = convert(AbstractShape{L, T_common}, shape)
19-
mat_promoted = convert(Material{T_common}, mat)
20-
21-
return ConductorPart{L, T_common, typeof(shape_promoted)}(
22-
tag,
23-
shape_promoted,
24-
mat_promoted,
25-
)
20+
s = convert(AbstractShape{L, T}, shape)
21+
m = convert(Material{T}, mat)
22+
23+
return ConductorPart{L, T, typeof(s)}(tag, s, m)
2624
end
2725

2826
struct InsulatorPart{L, T, S <: AbstractShape{L, T}} <: AbstractCablePart
@@ -35,17 +33,13 @@ function InsulatorPart(
3533
tag::Symbol,
3634
shape::AbstractShape{L, T_shape},
3735
mat::Material{T_mat},
38-
) where {L, T_shape, T_mat}
36+
) where {L, T_shape <: Real, T_mat <: Real}
3937
# 1. Ask the compiler what the safest common type is.
40-
T_common = promote_type(T_shape, T_mat)
38+
T = promote_type(T_shape, T_mat)
4139

4240
# 2. Let native dispatch handle the translation.
43-
shape_promoted = convert(AbstractShape{L, T_common}, shape)
44-
mat_promoted = convert(Material{T_common}, mat)
45-
46-
return InsulatorPart{L, T_common, typeof(shape_promoted)}(
47-
tag,
48-
shape_promoted,
49-
mat_promoted,
50-
)
41+
s = convert(AbstractShape{L, T}, shape)
42+
m = convert(Material{T}, mat)
43+
44+
return InsulatorPart{L, T, typeof(s)}(tag, s, m)
5145
end

0 commit comments

Comments
 (0)