"""Spline-backed airfoil schema dataclasses."""
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Literal
from buffalo_core.schema import SchemaChoice, SchemaField
from .common import Point2DSpec
from .constants import POINT2D_TUPLE_LENGTH
type SplineAirfoilProvenanceSpec = dict[str, object]
[docs]
@dataclass(slots=True)
class SplineSurfaceSpec:
"""
Bezier-backed spline control data for one airfoil surface.
Notes
-----
The current spline schema supports only the Bezier subtype.
Control points are stored as planar ``[x, y]`` pairs ordered from
leading edge to trailing edge.
"""
#: Surface control points ordered from leading edge to trailing edge.
control_points: list[Point2DSpec] = field(
default_factory=list,
metadata=SchemaField(
value_kind="list",
required=False,
label="Control Points",
order=10,
short_help="Bezier control points from leading to trailing edge.",
min_items=2,
item_kind="Point2DSpec",
tuple_length=POINT2D_TUPLE_LENGTH,
format_hint="[(x, y), ...]",
).to_metadata(),
)
[docs]
@dataclass(slots=True)
class SplineAirfoilSpec:
"""
Spline-backed airfoil definition.
Notes
-----
The first implemented spline schema supports only
``representation="bezier"``.
Upper and lower surfaces are stored independently in their natural
leading-edge-to-trailing-edge order.
Optional provenance metadata records how the spline was obtained, but
the spline control data remains the authoritative geometry.
"""
#: Schema discriminator for a spline-backed airfoil.
type: Literal["spline"] = field(
default="spline",
metadata=SchemaField(
value_kind="enum",
required=False,
label="Type",
order=10,
short_help="Schema discriminator for spline-backed airfoils.",
default="spline",
choices=("spline",),
).to_metadata(),
)
#: Supported spline representation subtype.
representation: Literal["bezier"] = field(
default="bezier",
metadata=SchemaField(
value_kind="enum",
required=False,
label="Representation",
order=20,
short_help="Spline representation subtype.",
default="bezier",
choices=(SchemaChoice(value="bezier", label="Bezier"),),
).to_metadata(),
)
#: Upper-surface spline control data.
upper: SplineSurfaceSpec = field(
default_factory=SplineSurfaceSpec,
metadata=SchemaField(
value_kind="object",
required=False,
label="Upper Surface",
order=30,
short_help="Upper-surface spline control polygon.",
item_kind="SplineSurfaceSpec",
).to_metadata(),
)
#: Lower-surface spline control data.
lower: SplineSurfaceSpec = field(
default_factory=SplineSurfaceSpec,
metadata=SchemaField(
value_kind="object",
required=False,
label="Lower Surface",
order=40,
short_help="Lower-surface spline control polygon.",
item_kind="SplineSurfaceSpec",
).to_metadata(),
)
#: Optional provenance metadata for derived spline airfoils.
provenance: SplineAirfoilProvenanceSpec | None = field(
default=None,
metadata=SchemaField(
value_kind="mapping",
required=False,
label="Provenance",
order=50,
short_help="Optional metadata describing how the spline was made.",
advanced=True,
notes=(
"Informational only; upper and lower spline data remain "
"authoritative."
),
).to_metadata(),
)