acadrust 0.3.4

A pure Rust library for reading and writing CAD files in DXF format (ASCII and Binary) and DWG format (Binary).
Documentation
//! User Coordinate System table entry

use super::TableEntry;
use crate::types::{Handle, Vector3};

/// A User Coordinate System (UCS) table entry
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ucs {
    /// Unique handle
    pub handle: Handle,
    /// UCS name
    pub name: String,
    /// Origin point
    pub origin: Vector3,
    /// X-axis direction
    pub x_axis: Vector3,
    /// Y-axis direction
    pub y_axis: Vector3,
}

impl Ucs {
    /// Create a new UCS
    pub fn new(name: impl Into<String>) -> Self {
        Ucs {
            handle: Handle::NULL,
            name: name.into(),
            origin: Vector3::ZERO,
            x_axis: Vector3::UNIT_X,
            y_axis: Vector3::UNIT_Y,
        }
    }

    /// Create a UCS with specific origin and axes
    pub fn from_origin_axes(
        name: impl Into<String>,
        origin: Vector3,
        x_axis: Vector3,
        y_axis: Vector3,
    ) -> Self {
        Ucs {
            handle: Handle::NULL,
            name: name.into(),
            origin,
            x_axis,
            y_axis,
        }
    }

    /// Get the Z-axis direction (cross product of X and Y)
    pub fn z_axis(&self) -> Vector3 {
        self.x_axis.cross(&self.y_axis)
    }
}

impl TableEntry for Ucs {
    fn handle(&self) -> Handle {
        self.handle
    }

    fn set_handle(&mut self, handle: Handle) {
        self.handle = handle;
    }

    fn name(&self) -> &str {
        &self.name
    }

    fn set_name(&mut self, name: String) {
        self.name = name;
    }
}