Skip to content

Commit 7c87ea9

Browse files
refactor(types): update AbstractShape and part struct definitions and add recast fallbacks
1 parent e88d432 commit 7c87ea9

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

src/cablebuilder/types.jl

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,56 @@
1-
abstract type AbstractLayout end
2-
struct Concentric <: AbstractLayout end
3-
struct SectorShaped <: AbstractLayout end
4-
abstract type AbstractShape{L <: AbstractLayout, T <: Real} end
1+
abstract type AbstractShape{T <: Real} end
52

63
abstract type AbstractCablePart end
74

85
@inline r_ex(p::AbstractCablePart) = r_ex(p.shape)
96

10-
struct ConductorPart{L, T, S <: AbstractShape{L, T}} <: AbstractCablePart
7+
struct ConductorPart{T, S <: AbstractShape{T}} <: AbstractCablePart
118
grp::Symbol
129
shape::S
1310
material::Material{T}
1411
end
1512

1613
@inline function ConductorPart(
1714
grp::Symbol,
18-
shape::AbstractShape{L, S},
15+
shape::AbstractShape{S},
1916
mat::Material{M},
20-
) where {L, S <: Real, M <: Real}
17+
) where {S <: Real, M <: Real}
2118
# 1. Ask the compiler what the safest common type is.
2219
T = promote_type(S, M)
2320

2421
# 2. Let native dispatch handle the translation.
25-
s = convert(AbstractShape{L, T}, shape)
22+
s = convert(AbstractShape{T}, shape)
2623
m = convert(Material{T}, mat)
2724

28-
return ConductorPart{L, T, typeof(s)}(grp, s, m)
25+
return ConductorPart{T, typeof(s)}(grp, s, m)
2926
end
3027

31-
struct InsulatorPart{L, T, S <: AbstractShape{L, T}} <: AbstractCablePart
28+
struct InsulatorPart{T, S <: AbstractShape{T}} <: AbstractCablePart
3229
grp::Symbol
3330
shape::S
3431
material::Material{T}
3532
end
3633

3734
@inline function InsulatorPart(
3835
grp::Symbol,
39-
shape::AbstractShape{L, S},
36+
shape::AbstractShape{S},
4037
mat::Material{M},
41-
) where {L, S <: Real, M <: Real}
38+
) where {S <: Real, M <: Real}
4239
# 1. Ask the compiler what the safest common type is.
4340
T = promote_type(S, M)
4441

4542
# 2. Let native dispatch handle the translation.
46-
s = convert(AbstractShape{L, T}, shape)
43+
s = convert(AbstractShape{T}, shape)
4744
m = convert(Material{T}, mat)
4845

49-
return InsulatorPart{L, T, typeof(s)}(grp, s, m)
46+
return InsulatorPart{T, typeof(s)}(grp, s, m)
5047
end
48+
49+
# ---------------------------------------------------------
50+
# THE GLOBAL RECAST FALLBACKS
51+
# ---------------------------------------------------------
52+
# 1. Reals get standard numeric conversion
53+
@inline recast(::Type{T}, x::Real) where {T} = convert(T, x)
54+
55+
# 2. Everything else (Symbols, Bools, Strings) is ignored and passed through safely
56+
@inline recast(::Type{T}, x) where {T} = x

0 commit comments

Comments
 (0)