mirror of
https://github.com/storytold/cadcraft.git
synced 2026-12-02 02:38:30 -06:00
RECTANG: take Rotation as AutoCAD does and show it in the drawing's units
Measured in AutoCAD 2024 with ANGBASE 90 and ANGDIR 1: Rotation 30 turns the rectangle 30 degrees clockwise from +X (ANGBASE aside), and the next RECTANG shows "Current rectangle modes: Rotation=120.00", the rotation from ANGBASE in the ANGDIR sense; the rotation prompt's default reads <120.00>. With AUNITS 1, 30.5 shows as "Rotation=30d30'". The typed rotation is now an amount turned in the ANGDIR sense, and both the modes line and the default use the drawing's angle settings and units. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f126a24c42
commit
d79185ed8d
@@ -7,6 +7,15 @@ use super::{
|
||||
// RECTANG with Area / Dimensions / Rotation / Width / Elevation / Thickness
|
||||
// =====================================================================================
|
||||
|
||||
/// A rectangle's rotation (radians counterclockwise from +X) as AutoCAD 2024 shows it in RECTANG's
|
||||
/// modes and rotation prompt: from ANGBASE in the ANGDIR sense, in the drawing's angle units to
|
||||
/// two places ("Rotation=120.00" for 30 typed with ANGBASE 90 and ANGDIR 1, "30d30'" in
|
||||
/// degrees/minutes/seconds).
|
||||
fn shown_rotation(s: &Session, rotation: f64) -> String {
|
||||
let au = s.angle_settings();
|
||||
crate::units::format_angle(au.shown(rotation), au.aunits, 2)
|
||||
}
|
||||
|
||||
/// RECTANG's corner options, remembered between invocations as AutoCAD remembers them
|
||||
/// ("Current rectangle modes: Fillet=2.0000", "Elevation=7.5000 Thickness=2.2500 Rotation=30.96").
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
@@ -277,7 +286,7 @@ impl Interactive for RectM2 {
|
||||
}
|
||||
let rotation = m.rotation.to_degrees().rem_euclid(360.0);
|
||||
if rotation > 1e-9 && rotation < 360.0 - 1e-9 {
|
||||
on.push(format!("Rotation={rotation:.2}"));
|
||||
on.push(format!("Rotation={}", shown_rotation(s, m.rotation)));
|
||||
}
|
||||
if !on.is_empty() {
|
||||
s.echo(format!("Current rectangle modes: {}", on.join(" ")));
|
||||
@@ -304,7 +313,7 @@ impl Interactive for RectM2 {
|
||||
RAsk::DimW => num("Specify width for rectangles", self.dims.map(|d| d.1).unwrap_or(10.0)),
|
||||
RAsk::Rotation => Prompt::new("Specify rotation angle or", Accept::POINT_OR_NUMBER)
|
||||
.kw(&["Pick points"])
|
||||
.default(format!("{:.0}", self.rotation.to_degrees()))
|
||||
.default(shown_rotation(_s, self.rotation))
|
||||
.base_opt(self.first),
|
||||
RAsk::RotPick1 => Prompt::new("Specify first point", Accept::POINT),
|
||||
RAsk::RotPick2(b) => Prompt::new("Specify second point", Accept::POINT).base(b),
|
||||
@@ -382,7 +391,8 @@ impl Interactive for RectM2 {
|
||||
RAsk::Rotation => match i {
|
||||
Input::Keyword(_) => self.asking = Some(RAsk::RotPick1),
|
||||
Input::Point(p) => self.rotation = self.first.map(|f| f.angle_to(p)).unwrap_or(0.0),
|
||||
Input::Text(t) => self.rotation = s.angle_settings().direction(&t).ok_or_else(|| other("Requires a valid angle."))?,
|
||||
// An amount turned in the ANGDIR sense from +X, ANGBASE aside, as AutoCAD takes it.
|
||||
Input::Text(t) => self.rotation = s.angle_settings().rotation(&t).ok_or_else(|| other("Requires a valid angle."))?,
|
||||
_ => {}
|
||||
},
|
||||
RAsk::RotPick1 => {
|
||||
|
||||
@@ -1245,6 +1245,31 @@ fn rectang_names_the_modes_it_carries_over() {
|
||||
s.cmdline("rectang _E 7.5 _T 2.25 0,0 _R _P 0,0 10,6 10,20").unwrap();
|
||||
s.start("rectang").unwrap();
|
||||
assert_eq!(modes(&s), ["Current rectangle modes: Elevation=7.5000 Thickness=2.2500 Rotation=30.96"]);
|
||||
s.cancel();
|
||||
// With ANGBASE 90 and ANGDIR 1, AutoCAD 2024 turns a rectangle given Rotation 30 clockwise
|
||||
// by 30° from +X (ANGBASE aside), and shows that rotation from ANGBASE: "Rotation=120.00",
|
||||
// and <120.00> as the next rotation default.
|
||||
let mut s = Session::new();
|
||||
s.cmdline("setvar angbase 90").unwrap();
|
||||
s.cmdline("setvar angdir 1").unwrap();
|
||||
s.cmdline("rectang 50,0 _R 30 60,5").unwrap();
|
||||
let e = s.doc().unwrap().model.last().unwrap().clone();
|
||||
let EntityKind::LwPolyline(p) = &e.kind else { panic!("{:?}", e.kind) };
|
||||
let edge = p.vertices[1].p - p.vertices[0].p;
|
||||
assert!((edge.y.atan2(edge.x) + 30f64.to_radians()).abs() < 1e-9, "{p:?}");
|
||||
s.start("rectang").unwrap();
|
||||
assert_eq!(modes(&s), ["Current rectangle modes: Rotation=120.00"]);
|
||||
s.cmdline("50,0").unwrap();
|
||||
s.cmdline("_R").unwrap();
|
||||
assert!(s.prompt_text().contains("<120.00>"), "{}", s.prompt_text());
|
||||
s.cancel();
|
||||
// In degrees/minutes/seconds: "Rotation=30d30'".
|
||||
let mut s = Session::new();
|
||||
s.cmdline("setvar aunits 1").unwrap();
|
||||
s.cmdline("rectang 50,0 _R 30.5 60,5").unwrap();
|
||||
s.start("rectang").unwrap();
|
||||
assert_eq!(modes(&s), ["Current rectangle modes: Rotation=30d30'"]);
|
||||
s.cancel();
|
||||
}
|
||||
|
||||
/// Area allows for cut corners only while they fit: a fillet too large for the resulting sides
|
||||
|
||||
Reference in New Issue
Block a user