mirror of
https://github.com/storytold/cadcraft.git
synced 2026-11-21 20:40:02 +00:00
DXF read: a thick polyline drawn as seen from above keeps the side of Z it extruded toward
This commit is contained in:
@@ -88,6 +88,7 @@ fn lwpolyline(tags: &[Tag], c: &mut Common, t: &T) -> Option<EntityKind> {
|
||||
// In a tilted plane: drawn as seen from above, at the vertices' mean height, its
|
||||
// vertices now plan coordinates.
|
||||
(verts, elevation) = plan_of_tilted(c.extrusion, elevation, &verts, flags & 1 != 0);
|
||||
thickness_along_z(c);
|
||||
c.extrusion = Vec3::Z;
|
||||
} else if c.extrusion.z < 0.0 {
|
||||
for v in &mut verts {
|
||||
@@ -606,6 +607,7 @@ pub(super) fn polyline_entity(recs: &[(String, &[Tag])], i: &mut usize, t: &T) -
|
||||
let mut elevation = t.p(10).z;
|
||||
if tilted(c.extrusion, run_points(&vertices, elevation, closed)) {
|
||||
(vertices, elevation) = plan_of_tilted(c.extrusion, elevation, &vertices, closed);
|
||||
thickness_along_z(&mut c);
|
||||
c.extrusion = Vec3::Z;
|
||||
} else if c.extrusion.z < 0.0 {
|
||||
for v in &mut vertices {
|
||||
@@ -726,3 +728,11 @@ fn helix(tags: &[Tag]) -> Helix {
|
||||
}
|
||||
.sanitized()
|
||||
}
|
||||
|
||||
/// A polyline drawn as seen from above gets the normal +Z: its thickness keeps the side of Z it
|
||||
/// extruded toward, which the normal it is losing said.
|
||||
fn thickness_along_z(c: &mut Common) {
|
||||
if c.extrusion.z < 0.0 {
|
||||
c.thickness = -c.thickness;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2805,6 +2805,20 @@ fn tilted_hatch_turns_its_gradient() {
|
||||
assert!((g.angle - std::f64::consts::PI).abs() < 1e-9, "gradient angle {}", g.angle);
|
||||
}
|
||||
|
||||
/// A tilted polyline with a thickness, its normal pointing partly down Z, still extrudes toward -Z
|
||||
/// once it is drawn as seen from above and saved with no normal.
|
||||
#[test]
|
||||
fn tilted_thick_polyline_keeps_its_extrusion_side() {
|
||||
let text = "0\nSECTION\n2\nENTITIES\n0\nLWPOLYLINE\n8\n0\n90\n2\n70\n0\n39\n5\n210\n0\n220\n0.5\n230\n-0.8660254037844386\n\
|
||||
10\n1\n20\n0\n10\n3\n20\n2\n0\nENDSEC\n0\nEOF\n";
|
||||
let d = read(text.as_bytes(), "p.dxf").unwrap();
|
||||
let e = d.model.iter().next().unwrap();
|
||||
assert_eq!((e.common.thickness, e.common.extrusion), (-5.0, Vec3::Z));
|
||||
let back = roundtrip(&d);
|
||||
let e = back.model.iter().next().unwrap();
|
||||
assert_eq!((e.common.thickness, e.common.extrusion), (-5.0, Vec3::Z), "saved with no normal, it still extrudes toward -Z");
|
||||
}
|
||||
|
||||
/// A straight tilted LWPOLYLINE keeps its vertex widths (groups 40/41) on the projected vertices.
|
||||
#[test]
|
||||
fn tilted_straight_lwpolyline_keeps_its_widths() {
|
||||
|
||||
Reference in New Issue
Block a user