forked from 1b-agent/opencadstudio-upstream
fix(rect): harden rectangle behavior
Reject invalid trim geometry instead of silently changing dimensions.\nRegister XData application IDs so rectangle metadata survives saves.
This commit is contained in:
1 parent
8dc9803c02
commit
27cae9467a
26 files changed
+542
-113
No files matched your search
@@ -432,6 +432,11 @@ pub fn parse_direction(text: &str) -> Option<f64> {
|
||||
Some(relative + ctx.angbase)
|
||||
}
|
||||
|
||||
/// Read a direction typed at a command prompt, accepting a decimal comma.
|
||||
pub fn parse_typed_direction(text: &str) -> Option<f64> {
|
||||
parse_direction(&text.replace(',', "."))
|
||||
}
|
||||
|
||||
/// Two interior triangles covering a quad (flat list, 6 vertices) — the
|
||||
/// click-anywhere pick surface for frame-like entities (image, OLE frame,
|
||||
/// underlay, wipeout). Corners in ring order.
|
||||
|
||||
@@ -824,11 +824,11 @@ pub(crate) fn is_rectangle(pline: &LwPolyline) -> bool {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let edges: Vec<glam::DVec2> = (0..4)
|
||||
let edges: Vec<Vec2> = (0..4)
|
||||
.map(|index| {
|
||||
let from = pline.vertices[index].location;
|
||||
let to = pline.vertices[(index + 1) % 4].location;
|
||||
glam::DVec2::new(to.x - from.x, to.y - from.y)
|
||||
Vec2::new(to.x - from.x, to.y - from.y)
|
||||
})
|
||||
.collect();
|
||||
let lengths: Vec<f64> = edges.iter().map(|edge| edge.length()).collect();
|
||||
@@ -837,8 +837,8 @@ pub(crate) fn is_rectangle(pline: &LwPolyline) -> bool {
|
||||
}
|
||||
let tolerance = 1.0e-9;
|
||||
edges[0].dot(edges[1]).abs() <= tolerance * lengths[0] * lengths[1]
|
||||
&& edges[0].perp_dot(edges[2]).abs() <= tolerance * lengths[0] * lengths[2]
|
||||
&& edges[1].perp_dot(edges[3]).abs() <= tolerance * lengths[1] * lengths[3]
|
||||
&& edges[0].cross(edges[2]).abs() <= tolerance * lengths[0] * lengths[2]
|
||||
&& edges[1].cross(edges[3]).abs() <= tolerance * lengths[1] * lengths[3]
|
||||
}
|
||||
|
||||
fn properties(pline: &LwPolyline) -> Vec<PropSection> {
|
||||
@@ -986,8 +986,10 @@ fn apply_geom_prop(pline: &mut LwPolyline, field: &str, value: &str) {
|
||||
}
|
||||
}
|
||||
"bulge" => {
|
||||
if let Some(vtx) = pline.vertices.get_mut(vi) {
|
||||
vtx.bulge = v.clamp(-1.0e6, 1.0e6);
|
||||
if v.is_finite() {
|
||||
if let Some(vtx) = pline.vertices.get_mut(vi) {
|
||||
vtx.bulge = v.clamp(-1.0e6, 1.0e6);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
||||
Reference in new issue
Block a user