* doc: persistent names read as their structure; joint.inspect splits an edge with a blend face first
`persistent_name::{FaceName, EdgeName}` parse a face or edge name once (blends, inner walls,
copies, pieces, numbered pieces, `~k`) and write it back as the same text, bounded against
hostile input. A suffix after a blend's edge naming a later feature belongs to the blend face.
joint.inspect split an edge at its first `|`, so an edge whose first face is a blend
(`F4:blend:F3:+x|F3:+z#[…]|F5:-y`) came back as a cut-off blend name and a string that is no
face. It now uses `EdgeName::parse`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* doc: persistent names as typed values: features, roles, suffixes, a lexer and errors that say where
`FaceName` is a base (made by a feature in a role, a blend and the edge it rounds, an inner
wall, a body's face by index, other text) and its suffixes (copy, piece, numbered piece).
Roles are typed where the vocabulary is known (top, side:<curve>, +x, face:<k>, …) and kept as
written otherwise. The text form is lexed into tokens and read by the grammar in the module's
doc; a name that doesn't read says where and what was expected.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* names: read what made a face, its kind and its feature ids through persistent_name
The places that took a name apart by hand to find the feature that made a face, whether it is
a blend, a copy, a numbered piece or a wall, or to remap feature ids on copy, now ask the typed
name (`made_by`, `split_feature`, `is_blend`, `is_copy`, `is_numbered_piece`, `is_wall`,
`features`, `map`). A name that doesn't read falls back to the old text check.
- An offset of a face that only names a blend inside it (`F2:top#[F5:blend:…]`) is no longer
taken for a fillet's.
- Copying a component remaps feature ids inside a piece's `#[…]` too.
- A shell's inner wall split by a later cut keeps the qualifier on the wall.
- joint.inspect finds the sketch curve of a copied side (`side:l1@F7.2`).
Finding a face by name (strip_piece, parent_piece) is unchanged: it reads a trailing
qualifier as the whole name's and moves once the text form says where it belongs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* engine: regression tests for press-pull on a wall that only names a fillet and joint.inspect on a copied side
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* names: an edge holds one face or more; made_by reads only the leading token
An open boundary's edge has one face and an edge several faces meet at has more, so an edge name
is a list of faces (a blend's own edge still takes two at most, as before). `made_by` reads just
the leading `F<n>:`, which every name a feature made starts with, so asking it of every face
each frame stays cheap. Names are read up to 1 MiB: a face engraved with text has piece names
past 4 KiB.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* persistent_name: split into lexer, parser, write, text and tests
No code changed; callers' paths stay the same (`pub use text::*`).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
92 lines
3.2 KiB
Rust
92 lines
3.2 KiB
Rust
//! Writing names back as text: `Display`.
|
|
|
|
use std::fmt;
|
|
|
|
use super::*;
|
|
|
|
impl fmt::Display for Role {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Role::Top => f.write_str("top"),
|
|
Role::Bottom => f.write_str("bottom"),
|
|
Role::Start => f.write_str("start"),
|
|
Role::End => f.write_str("end"),
|
|
Role::Base => f.write_str("base"),
|
|
Role::Section => f.write_str("section"),
|
|
Role::Wall => f.write_str("side"),
|
|
Role::Side { profile: Some(k), curve } => write!(f, "side:s{k}.{curve}"),
|
|
Role::Side { profile: None, curve } => write!(f, "side:{curve}"),
|
|
Role::BoxFace { axis, high } => {
|
|
let a = match axis {
|
|
Axis::X => 'x',
|
|
Axis::Y => 'y',
|
|
Axis::Z => 'z',
|
|
};
|
|
write!(f, "{}{a}", if *high { '+' } else { '-' })
|
|
}
|
|
Role::Index(k) => write!(f, "face:{k}"),
|
|
Role::Other(t) => f.write_str(t),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for FaceName {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match &self.base {
|
|
Base::Made { feature, role } => write!(f, "F{}:{role}", feature.0)?,
|
|
Base::Blend { feature, rounds: Rounds::Edge(e) } => write!(f, "F{}:blend:{e}", feature.0)?,
|
|
Base::Blend { feature, rounds: Rounds::Index(k) } => write!(f, "F{}:blend:{k}", feature.0)?,
|
|
Base::Inner { feature, offsets } => write!(f, "F{}:inner:{offsets}", feature.0)?,
|
|
Base::BodyFace { body, index } => write!(f, "{body}:face:{index}")?,
|
|
Base::Other(t) => f.write_str(t)?,
|
|
}
|
|
for s in &self.suffixes {
|
|
match s {
|
|
Suffix::Copy { feature, instance } => write!(f, "@F{}.{instance}", feature.0)?,
|
|
Suffix::Piece(q) => {
|
|
f.write_str("#[")?;
|
|
for (i, a) in q.around.iter().enumerate() {
|
|
if i > 0 {
|
|
f.write_str(",")?;
|
|
}
|
|
write!(f, "{a}")?;
|
|
}
|
|
f.write_str("]")?;
|
|
if let Some(k) = q.tie {
|
|
write!(f, "#{k}")?;
|
|
}
|
|
}
|
|
Suffix::Numbered(k) => write!(f, "#{k}")?,
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for EdgeName {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
for (i, face) in self.faces.iter().enumerate() {
|
|
if i > 0 {
|
|
f.write_str("|")?;
|
|
}
|
|
write!(f, "{face}")?;
|
|
}
|
|
match self.tie {
|
|
Some(k) => write!(f, "~{k}"),
|
|
None => Ok(()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for NameError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
NameError::TooLong => write!(f, "a name is at most {MAX_NAME_LEN} bytes"),
|
|
NameError::TooDeep => write!(f, "a name nests at most {MAX_DEPTH} deep"),
|
|
NameError::Expected { at, what } => write!(f, "expected {what} at byte {at}"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for NameError {}
|