use super::{Entity, EntityCommon};
use crate::types::{BoundingBox3D, Color, Handle, LineWeight, Transform, Transparency, Vector3};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ViewBorder {
pub common: EntityCommon,
pub version: i16,
pub min: [f64; 2],
pub max: [f64; 2],
pub center: [f64; 2],
pub scale: f64,
pub rotation_angle: f64,
pub active_viewport: Handle,
pub scale_handle: Handle,
}
impl ViewBorder {
pub fn new() -> Self {
ViewBorder {
common: EntityCommon::new(),
version: 0,
min: [0.0; 2],
max: [0.0; 2],
center: [0.0; 2],
scale: 1.0,
rotation_angle: 0.0,
active_viewport: Handle::NULL,
scale_handle: Handle::NULL,
}
}
}
impl Default for ViewBorder {
fn default() -> Self {
Self::new()
}
}
impl Entity for ViewBorder {
fn handle(&self) -> Handle {
self.common.handle
}
fn set_handle(&mut self, handle: Handle) {
self.common.handle = handle;
}
fn layer(&self) -> &str {
&self.common.layer
}
fn set_layer(&mut self, layer: String) {
self.common.layer = layer;
}
fn color(&self) -> Color {
self.common.color
}
fn set_color(&mut self, color: Color) {
self.common.color = color;
}
fn line_weight(&self) -> LineWeight {
self.common.line_weight
}
fn set_line_weight(&mut self, weight: LineWeight) {
self.common.line_weight = weight;
}
fn transparency(&self) -> Transparency {
self.common.transparency
}
fn set_transparency(&mut self, transparency: Transparency) {
self.common.transparency = transparency;
}
fn is_invisible(&self) -> bool {
self.common.invisible
}
fn set_invisible(&mut self, invisible: bool) {
self.common.invisible = invisible;
}
fn bounding_box(&self) -> BoundingBox3D {
BoundingBox3D {
min: Vector3::new(self.min[0], self.min[1], 0.0),
max: Vector3::new(self.max[0], self.max[1], 0.0),
}
}
fn translate(&mut self, offset: Vector3) {
self.min[0] += offset.x;
self.min[1] += offset.y;
self.max[0] += offset.x;
self.max[1] += offset.y;
self.center[0] += offset.x;
self.center[1] += offset.y;
}
fn entity_type(&self) -> &'static str {
"DRAWINGVIEW"
}
fn apply_transform(&mut self, transform: &Transform) {
self.common.raw_record = None;
let corners = [
Vector3::new(self.min[0], self.min[1], 0.0),
Vector3::new(self.max[0], self.min[1], 0.0),
Vector3::new(self.max[0], self.max[1], 0.0),
Vector3::new(self.min[0], self.max[1], 0.0),
]
.map(|point| transform.apply(point));
let mut min = [f64::INFINITY; 2];
let mut max = [f64::NEG_INFINITY; 2];
for point in corners {
min[0] = min[0].min(point.x);
min[1] = min[1].min(point.y);
max[0] = max[0].max(point.x);
max[1] = max[1].max(point.y);
}
let center = transform.apply(Vector3::new(self.center[0], self.center[1], 0.0));
self.min = min;
self.max = max;
self.center = [center.x, center.y];
super::transform::rotate_stored_angle(&mut self.rotation_angle, transform);
}
}