Merge pull request #1431 from ramox81:codex/angular-constraint-parity

This commit is contained in:
Hakan Seven committed 2026-09-22 12:28:04 +03:00
commit d37ce4d617
12 files changed
+1278 -205

No files matched your search

+5 -3
View File
@@ -702,12 +702,14 @@ pub fn set_property(
| "dim_alt_precision"
| "dim_tolerance_precision"
| "dim_alt_tolerance_precision" => parse_precision_label(trimmed),
// "On" is text aligned with its dimension line: the horizontal
// flag (DIMTIH/DIMTOH) off.
"dim_text_outside_align" | "dim_text_inside_align" | "dim_line_inside" => {
yes(trimmed).map(|value| i16::from(value == 0))
}
"dim_ext_line_fixed"
| "dim_text_outside_align"
| "dim_text_inside_align"
| "dim_text_inside"
| "dim_line_forced"
| "dim_line_inside"
| "dim_alt_enabled" => yes(trimmed),
"dim_decimal_separator" => trimmed
.chars()
+206 -29
View File
@@ -2143,7 +2143,7 @@ pub fn style_sections(
choice(
t!("Text outside align").as_ref(),
"dim_text_outside_align",
on(int(ov::DIMTOH, s.dimtoh as i16) != 0),
on(int(ov::DIMTOH, s.dimtoh as i16) == 0),
&["On", "Off"],
true,
),
@@ -2178,9 +2178,15 @@ pub fn style_sections(
choice(
t!("Text inside align").as_ref(),
"dim_text_inside_align",
on(int(ov::DIMTIH, s.dimtih as i16) != 0),
on(int(ov::DIMTIH, s.dimtih as i16) == 0),
&["On", "Off"],
dimtix || matches!(dimension, Dimension::LargeRadial(_)),
dimtix
|| matches!(
dimension,
Dimension::LargeRadial(_)
| Dimension::Angular2Ln(_)
| Dimension::Angular3Pt(_)
),
),
property(
t!("Text position X").as_ref(),
@@ -2283,7 +2289,7 @@ pub fn style_sections(
choice(
t!("Dim line inside").as_ref(),
"dim_line_inside",
on(int(ov::DIMSOXD, s.dimsoxd as i16) != 0),
on(int(ov::DIMSOXD, s.dimsoxd as i16) == 0),
&["On", "Off"],
true,
),
@@ -2999,13 +3005,105 @@ pub fn style_sections(
];
}
sections.retain(|section| section.title != t!("Alternate Units").as_ref());
let by_order = |order: &'static [&'static str]| {
move |property: &Property| {
order
.iter()
.position(|field| *field == property.field)
.unwrap_or(order.len())
}
};
if let Some(tolerances) = sections
.iter_mut()
.find(|section| section.title == t!("Tolerances").as_ref())
{
tolerances
.props
.retain(|property| !property.field.starts_with("dim_alt_tolerance_"));
tolerances.props.retain(|property| {
!property.field.starts_with("dim_alt_tolerance_")
&& !matches!(
property.field,
"dim_tolerance_suppress_zero_feet" | "dim_tolerance_suppress_zero_inches"
)
});
tolerances.props.sort_by_key(by_order(&[
"dim_tolerance_alignment",
"dim_tolerance_display",
"dim_tolerance_limit_lower",
"dim_tolerance_limit_upper",
"dim_tolerance_pos_vert",
"dim_tolerance_precision",
"dim_tolerance_suppress_leading_zeros",
"dim_tolerance_suppress_trailing_zeros",
"dim_tolerance_text_height",
]));
}
// An arc has no dimension line extension.
if let Some(lines) = sections
.iter_mut()
.find(|section| section.title == t!("Lines & Arrows").as_ref())
{
lines.props.retain(|property| property.field != "dim_line_ext");
}
if let Some(fit) = sections
.iter_mut()
.find(|section| section.title == t!("Fit").as_ref())
{
fit.props.sort_by_key(by_order(&[
"dim_line_forced",
"dim_line_inside",
"dim_scale_overall",
"dim_fit",
"dim_text_inside",
"dim_text_movement",
]));
}
if let Some(units) = sections
.iter_mut()
.find(|section| section.title == t!("Primary Units").as_ref())
{
units.props.sort_by_key(by_order(&[
"dim_decimal_separator",
"dim_prefix",
"dim_suffix",
"dim_angle_suppress_leading_zeros",
"dim_angle_suppress_trailing_zeros",
"dim_angle_precision",
"dim_angle_units",
]));
}
// The measurement reads at the angular precision, and automatic text
// reports where it is drawn rather than an unset point.
if let Some(text_section) = sections
.iter_mut()
.find(|section| section.title == t!("Text").as_ref())
{
let automatic = stored_text_point(dimension)
.is_none()
.then(|| styled_dimension_text_position(dimension, s, 1.0));
for property in &mut text_section.props {
match property.field {
"measurement" => {
// The row shows the number at the angular precision,
// without the text's degree sign.
let value = format_angular_value(
displayed_measurement(dimension, Some(s)),
Some(s),
);
property.value =
PropValue::ReadOnly(value.trim_end_matches('°').to_string());
}
"text_x" => {
if let Some(position) = automatic {
property.value = PropValue::EditText(format!("{:.4}", position.x));
}
}
"text_y" => {
if let Some(position) = automatic {
property.value = PropValue::EditText(format!("{:.4}", position.y));
}
}
_ => {}
}
}
}
}
@@ -4724,18 +4822,51 @@ fn dimension_geometry(
let (p3, p4) = (lv(d.angle_vertex), lv(d.definition_point));
let arc_point = lv(d.dimension_arc);
match two_line_angle_frame(p1, p2, p3, p4, arc_point) {
Some((vertex, start, end)) => append_angular_dimension(
&mut g,
vertex,
vertex,
vertex,
arc_point,
arrow1,
arrow2,
Some((start, end)),
params,
suppress,
),
Some((vertex, start, end)) => {
// An extension line runs from a side's nearer end out to
// the arc only where the arc lies beyond that side; where
// the arc crosses the side itself there is nothing to add.
let radius = vertex.distance(arc_point);
let side = |angle: f32| -> (Vec3, bool) {
let dir = Vec3::new(angle.cos(), angle.sin(), 0.0);
let deviation =
|a: Vec3, b: Vec3| normalized_or(b - a, dir).cross(dir).length();
let (a, b) = if deviation(p1, p2) <= deviation(p3, p4) {
(p1, p2)
} else {
(p3, p4)
};
let along = |p: Vec3| (p - vertex).dot(dir);
let (lo, hi) = (along(a).min(along(b)), along(a).max(along(b)));
let arc_end = vertex + dir * radius;
let near = if a.distance(arc_end) <= b.distance(arc_end) {
a
} else {
b
};
(near, radius >= lo - 1e-6 && radius <= hi + 1e-6)
};
let (first, first_covered) = side(start);
let (second, second_covered) = side(end);
let suppress = SuppressFlags {
ext1: suppress.ext1 || first_covered,
ext2: suppress.ext2 || second_covered,
dim1: suppress.dim1,
dim2: suppress.dim2,
};
append_angular_dimension(
&mut g,
vertex,
first,
second,
arc_point,
arrow1,
arrow2,
Some((start, end)),
params,
suppress,
)
}
// Parallel lines have no vertex and so no angle to draw; the
// extension lines alone say where the dimension was.
None => {
@@ -4749,14 +4880,14 @@ fn dimension_geometry(
let first = lv(d.first_point);
let second = lv(d.second_point);
let arc_point = lv(d.definition_point);
let explicit_sweep = two_line_angle_frame(
vertex,
first,
vertex,
second,
arc_point,
)
.map(|(_, start, end)| (start, end));
// The sweep starts at whichever ray the arc point says; the
// extension lines swap with it, or they would cross the angle.
let (first, second, explicit_sweep) =
match three_point_frame(vertex, first, second, arc_point) {
Some((start, end, true)) => (second, first, Some((start, end))),
Some((start, end, false)) => (first, second, Some((start, end))),
None => (first, second, None),
};
append_angular_dimension(
&mut g,
vertex,
@@ -5398,6 +5529,35 @@ fn two_line_angle_frame(
Some((vertex, start, end))
}
/// The sweep of a three-point angular dimension: counter-clockwise from the
/// first ray to the second when the arc point lies in that sweep, otherwise
/// the other way round (`swapped`). Rays need no crossing, so a straight
/// angle draws, and a reflex one is kept as picked.
fn three_point_frame(
vertex: Vec3,
first: Vec3,
second: Vec3,
arc_point: Vec3,
) -> Option<(f32, f32, bool)> {
let angle_of = |d: Vec3| d.y.atan2(d.x);
let (r1, r2, at) = (first - vertex, second - vertex, arc_point - vertex);
if r1.length_squared() <= 1e-12 || r2.length_squared() <= 1e-12 || at.length_squared() <= 1e-12
{
return None;
}
let tau = std::f32::consts::TAU;
let (a1, a2) = (angle_of(r1), angle_of(r2));
let sweep = (a2 - a1).rem_euclid(tau);
if sweep <= 1e-6 {
return None;
}
if (angle_of(at) - a1).rem_euclid(tau) <= sweep {
Some((a1, a1 + sweep, false))
} else {
Some((a2, a2 + (tau - sweep), true))
}
}
pub(crate) fn arc_dimension_angles(dimension: &DimensionArc) -> Option<(f32, f32)> {
let raw = dimension.arc_end_parameter - dimension.arc_start_parameter;
let mut sweep = raw.rem_euclid(std::f64::consts::TAU);
@@ -5668,8 +5828,7 @@ fn angular_dimension_frame(dim: &Dimension) -> Option<(Vec3, f32, f32, f32)> {
let first = vec3_local(value.first_point);
let second = vec3_local(value.second_point);
let arc_point = vec3_local(value.definition_point);
let (vertex, start, end) =
two_line_angle_frame(vertex, first, vertex, second, arc_point)?;
let (start, end, _) = three_point_frame(vertex, first, second, arc_point)?;
(vertex, start, end, arc_point)
}
Dimension::Arc(value) => {
@@ -6329,6 +6488,24 @@ pub(crate) fn dynamic_dimension_lock_anchor(
))
}
/// The two ends of an angular dimension's arc, each with the direction
/// pointing away from the arc: where a dynamic angle's triangle grips sit.
pub(crate) fn angular_arc_ends(dim: &Dimension) -> Option<[(glam::DVec3, glam::DVec3); 2]> {
let (vertex, start, end, radius) = angular_dimension_frame(dim)?;
let point = |angle: f32| {
let p = vertex + Vec3::new(angle.cos(), angle.sin(), 0.0) * radius;
glam::DVec3::new(p.x as f64, p.y as f64, p.z as f64)
};
let away = |angle: f32, sign: f32| {
glam::DVec3::new(
(-angle.sin() * sign) as f64,
(angle.cos() * sign) as f64,
0.0,
)
};
Some([(point(start), away(start, -1.0)), (point(end), away(end, 1.0))])
}
fn dimension_text_natural_rotation(dim: &Dimension) -> f64 {
let angle = match dim {
Dimension::Linear(d) => d.rotation,