mirror of
https://github.com/storytold/cadcraft.git
synced 2026-12-01 18:25:32 -06:00
- #2584: a tilted LWPOLYLINE/HATCH run is flattened to at most a million vertices, then its arcs stay chords (a hostile file of arcs asked for gigabytes; austin62jake). The file-format-parity.md hunk is dropped: maintainers update the parity docs. - #2471: another program's proxy objects are in the DWG loss report as its proxy entities are (left out before 2013, or when their class can't be named); they went silently. - #1626: a drawing saved at a view keeps it in the desktop app and when it has xrefs: the app's first frame and the xref pass both fitted the extents over it. OPEN's result says `saved_view`; one `view::saved_view` replaces the copy of `usable_view` in files.rs. A misplaced doc comment goes back to its test. - #2028: a plot rotation (73) outside 0-3 is written back as 0, not as read. - #1026: the binary code-page retry drops the first pass's tags before it runs (the peak doubled near the tag limit); a float spelling of an integer group clamps to what the width holds unsigned too, so 65535.0 reads as 65535 does, not 32767. - #2658: the reference names Undo by the last command ("Undo Group of commands"); Undo matched nothing and went to the end of Edit. Ordering and its test share one rule. - #2612: its test's Insert gets `clip: None` (XCLIP landed after it was written).
65 lines
2.4 KiB
Rust
65 lines
2.4 KiB
Rust
use cadcraft_geom::Bounds2;
|
|
|
|
use super::{Deserialize, Serialize, Vec2};
|
|
|
|
/// A 2D view of a space: world centre and visible height in drawing units, and the view twist
|
|
/// (VIEWTWIST, DVIEW TWist): how far the view is turned on screen, in radians counterclockwise
|
|
/// (the drawing appears turned by `twist`; 0 is the plain plan view).
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct View {
|
|
pub center: Vec2,
|
|
pub height: f64,
|
|
#[serde(default)]
|
|
pub twist: f64,
|
|
}
|
|
|
|
impl Default for View {
|
|
fn default() -> Self {
|
|
View { center: Vec2::new(6.0, 4.5), height: 10.0, twist: 0.0 }
|
|
}
|
|
}
|
|
|
|
impl View {
|
|
/// Box `b` (world) as a view turned by `twist` shows it: the world centre of the box it
|
|
/// makes on screen, and that box's width and height (`b`'s own when there is no twist).
|
|
pub fn twisted_box(b: Bounds2, twist: f64) -> (Vec2, f64, f64) {
|
|
if twist == 0.0 || !twist.is_finite() {
|
|
return (b.center(), b.width(), b.height());
|
|
}
|
|
let r = Bounds2::from_points(b.corners().map(|p| p.rotate(twist)));
|
|
(r.center().rotate(-twist), r.width(), r.height())
|
|
}
|
|
}
|
|
|
|
pub(crate) fn usable_view(v: &View) -> bool {
|
|
v.center.is_finite() && v.height.is_finite() && v.height > 1e-12 && v.twist.is_finite()
|
|
}
|
|
|
|
/// The view drawing `d` was saved at, when it records a usable one: OPEN opens on it, and nothing
|
|
/// after the open (resolving xrefs, the UI's first frame) fits the extents over it.
|
|
pub(crate) fn saved_view(d: &cadcraft_doc::Drawing) -> Option<View> {
|
|
d.header.saved_view().map(|(center, height)| View { center, height, twist: 0.0 }).filter(usable_view)
|
|
}
|
|
|
|
/// Tiled model viewports (VPORTS): the session side of the drawing's `*Active` configuration.
|
|
#[derive(Clone, Debug, Default, PartialEq)]
|
|
pub struct ModelTiles {
|
|
/// The tile corners these views belong to (when the drawing's tiles change, by VPORTS or
|
|
/// undo, its views take over).
|
|
pub rects: Vec<(Vec2, Vec2)>,
|
|
/// Each tile's view; the current tile shows the model space view itself.
|
|
pub views: Vec<View>,
|
|
/// The current tile.
|
|
pub active: usize,
|
|
}
|
|
|
|
/// One tile of the model space drawing area, for the UI ([`Session::model_tiles`]): its corners
|
|
/// as fractions of the drawing area (0,0 lower left) and its view.
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
pub struct ModelTile {
|
|
pub min: Vec2,
|
|
pub max: Vec2,
|
|
pub view: View,
|
|
pub active: bool,
|
|
}
|