Skip to content

Commit dfab467

Browse files
feat(primitives): add primitives.jl file
1 parent 7c87ea9 commit dfab467

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

src/cablebuilder/primitives.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Shape params define the shape of a primitive, but not its material, group or location/layout.
2+
abstract type AbstractShapeParams{T <: Real} end
3+
4+
@gridspace @relax struct Circular{T <: Real} <: AbstractShapeParams{T}
5+
r::T
6+
end
7+
# # Teach Base how to cast the abstract type down to this specific concrete type
8+
# @inline Base.convert(::Type{AbstractShapeParams{T}}, p::Circular) where {T <: Real} =
9+
# convert(Circular{T}, p)
10+
11+
@inline function validate(p::Circular)
12+
p.r > zero(p.r) || throw(DomainError(p.r, "Circular radius must be strictly positive."))
13+
return p
14+
end
15+
16+
@gridspace @relax struct Rectangular{T <: Real} <: AbstractShapeParams{T}
17+
w::T
18+
h::T
19+
end
20+
# # Teach Base how to cast the abstract type down to this specific concrete type
21+
# @inline Base.convert(::Type{AbstractShapeParams{T}}, p::Rectangular) where {T <: Real} =
22+
# convert(Rectangular{T}, p)
23+
24+
@inline function validate(p::Rectangular)
25+
p.w > zero(p.w) ||
26+
throw(DomainError(p.w, "Rectangular width must be strictly positive."))
27+
p.h > zero(p.h) ||
28+
throw(DomainError(p.h, "Rectangular height must be strictly positive."))
29+
return p
30+
end
31+
32+
# If a specific payload vault doesn't define intrinsic rules, it passes.
33+
@inline validate(params::AbstractShapeParams) = params

0 commit comments

Comments
 (0)