File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments