Files
vectorcraft/crates/doc/src/symbol_registration.rs
T
Fabio William ConceiçãoandCursor 80090e7623 G5: Symbol Options Registration 9-point grid
Store the registration point with the symbol and place instances so that point lands on (x, y). Symbol Options exposes the same 9-point control as Transform.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-16 04:45:03 +07:00

37 lines
1.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! Symbol Options › Registration: the 9-point grid (0 = top-left … 4 = centre … 8 = bottom-right)
//! that `symbol.place` uses as the point that lands on the click.
use vectorcraft_geom::Vec2;
/// Document unknown key: `{ symbolName: 0..8 }` for each symbol's registration point.
pub const SYMBOL_REGISTRATION: &str = "symbolRegistration";
/// Index on the 9-point grid (row-major, 4 = centre).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct SymbolRegistration(pub u8);
impl Default for SymbolRegistration {
fn default() -> Self {
Self(4)
}
}
impl SymbolRegistration {
pub const CENTER: Self = Self(4);
pub fn from_u64(v: u64) -> Option<Self> {
(v <= 8).then_some(Self(v as u8))
}
pub fn is_center(self) -> bool {
self.0 == 4
}
/// Offset of this registration point from the symbol's centre, in natural-size units
/// (right +, down +).
pub fn offset_from_center(self, w: f64, h: f64) -> Vec2 {
let (col, row) = (self.0 % 3, self.0 / 3);
Vec2::new((f64::from(col) - 1.0) * (w * 0.5), (f64::from(row) - 1.0) * (h * 0.5))
}
}