use crate::entities::*;
use crate::types::{Transform, Vector3};
mod blocks;
mod curves;
mod hatch;
mod leaders;
mod meshes;
mod polylines;
mod primitives;
mod text;
pub(crate) use blocks::*;
pub(crate) use curves::*;
pub(crate) use hatch::*;
pub(crate) use leaders::*;
pub(crate) use meshes::*;
pub(crate) use polylines::*;
pub(crate) use primitives::*;
pub(crate) use text::*;
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct MirrorOptions {
pub mirror_text: bool,
pub mirror_hatch: bool,
pub text_width: Option<f64>,
}
pub(crate) fn valid_transform(transform: &Transform) -> bool {
!transform.is_identity() && transform.matrix.m.iter().flatten().all(|v| v.is_finite())
}
impl EntityType {
pub fn apply_mirror(&mut self, transform: &Transform) {
self.apply_mirror_with_options(transform, MirrorOptions::default());
}
pub fn apply_mirror_with_options(&mut self, transform: &Transform, options: MirrorOptions) {
if !valid_transform(transform) {
return;
}
match self {
EntityType::Arc(e) => mirror_arc(e, transform),
EntityType::Ellipse(e) => mirror_ellipse(e, transform),
EntityType::LwPolyline(e) => mirror_lwpolyline(e, transform),
EntityType::Polyline2D(e) => mirror_polyline2d(e, transform),
EntityType::MLine(e) => mirror_mline(e, transform),
EntityType::Spline(e) => mirror_spline(e, transform),
EntityType::Helix(e) => mirror_helix(e, transform),
EntityType::Face3D(e) => mirror_face3d(e, transform),
EntityType::Solid(e) => mirror_solid(e, transform),
EntityType::Mesh(e) => mirror_mesh(e, transform),
EntityType::PolyfaceMesh(e) => mirror_polyface_mesh(e, transform),
EntityType::PolygonMesh(e) => mirror_polygon_mesh(e, transform),
EntityType::Solid3D(e) => mirror_solid3d(e, transform),
EntityType::Region(e) => mirror_region(e, transform),
EntityType::Body(e) => mirror_body(e, transform),
EntityType::Surface(e) => mirror_surface(e, transform),
EntityType::Text(e) => mirror_text_with_options(e, transform, options),
EntityType::MText(e) => mirror_mtext_with_options(e, transform, options),
EntityType::AttributeDefinition(e) => {
mirror_attribute_definition_with_options(e, transform, options)
}
EntityType::AttributeEntity(e) => {
mirror_attribute_entity_with_options(e, transform, options)
}
EntityType::Insert(e) => mirror_insert_with_options(e, transform, options),
EntityType::Underlay(e) => mirror_underlay(e, transform),
EntityType::Leader(e) => mirror_leader(e, transform),
EntityType::Shape(e) => mirror_shape(e, transform),
EntityType::Hatch(e) => mirror_hatch_with_options(e, transform, options),
_ => self.apply_transform(transform),
}
if super::transform::transform_invalidates_raw_record(self) {
self.common_mut().raw_record = None;
}
}
pub fn mirror_x(&mut self) {
self.apply_mirror(&Transform::from_mirror_x());
}
pub fn mirror_y(&mut self) {
self.apply_mirror(&Transform::from_mirror_y());
}
pub fn mirror_z(&mut self) {
self.apply_mirror(&Transform::from_mirror_z());
}
pub fn mirror_about_line(&mut self, p1: Vector3, p2: Vector3) {
self.mirror(p1, p2);
}
pub fn mirror(&mut self, first: Vector3, second: Vector3) {
self.mirror_with_options(first, second, MirrorOptions::default());
}
pub fn mirror_with_options(&mut self, first: Vector3, second: Vector3, options: MirrorOptions) {
self.apply_mirror_with_options(&Transform::from_mirror_line(first, second), options);
}
pub fn mirror_about_plane(&mut self, point: Vector3, normal: Vector3) {
self.mirror3d(super::mirror3d::MirrorPlane::PointNormal { point, normal });
}
}
#[cfg(test)]
pub(crate) mod tests;