mirror of
https://github.com/hannobraun/Fornjot
synced 2025-03-01 02:25:59 +00:00
Ease requirements on Arc
's start/end angles
Don't require `start < end`. The rest of the system doesn't need this, and it makes `Arc` itself simpler.
This commit is contained in:
parent
dc43d54dce
commit
e3eb04422e
@ -119,12 +119,8 @@ impl HalfEdgeBuilder for PartialHalfEdge {
|
|||||||
.write()
|
.write()
|
||||||
.update_as_circle_from_center_and_radius(arc.center, arc.radius);
|
.update_as_circle_from_center_and_radius(arc.center, arc.radius);
|
||||||
|
|
||||||
let [a_curve, b_curve] = if arc.flipped_construction {
|
let [a_curve, b_curve] =
|
||||||
[arc.end_angle, arc.start_angle]
|
[arc.start_angle, arc.end_angle].map(|coord| Point::from([coord]));
|
||||||
} else {
|
|
||||||
[arc.start_angle, arc.end_angle]
|
|
||||||
}
|
|
||||||
.map(|coord| Point::from([coord]));
|
|
||||||
|
|
||||||
for (vertex, point_curve) in
|
for (vertex, point_curve) in
|
||||||
self.vertices.each_mut_ext().zip_ext([a_curve, b_curve])
|
self.vertices.each_mut_ext().zip_ext([a_curve, b_curve])
|
||||||
|
@ -19,9 +19,6 @@ pub struct Arc {
|
|||||||
///
|
///
|
||||||
/// Guaranteed to be greater than `end_angle`.
|
/// Guaranteed to be greater than `end_angle`.
|
||||||
pub end_angle: Scalar,
|
pub end_angle: Scalar,
|
||||||
|
|
||||||
/// True if `start` and `end` were switched to ensure `end_angle` > `start_angle`
|
|
||||||
pub flipped_construction: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arc {
|
impl Arc {
|
||||||
@ -46,17 +43,15 @@ impl Arc {
|
|||||||
let flipped_construction = angle_rad <= Scalar::ZERO;
|
let flipped_construction = angle_rad <= Scalar::ZERO;
|
||||||
let angle_rad = angle_rad.abs();
|
let angle_rad = angle_rad.abs();
|
||||||
|
|
||||||
let [p0, p1] = if flipped_construction {
|
let (mut uv_factor, end_angle_offset) = if angle_rad > Scalar::PI {
|
||||||
[p1, p0]
|
|
||||||
} else {
|
|
||||||
[p0, p1]
|
|
||||||
};
|
|
||||||
|
|
||||||
let (uv_factor, end_angle_offset) = if angle_rad > Scalar::PI {
|
|
||||||
(Scalar::from_f64(-1.), Scalar::TAU)
|
(Scalar::from_f64(-1.), Scalar::TAU)
|
||||||
} else {
|
} else {
|
||||||
(Scalar::ONE, Scalar::ZERO)
|
(Scalar::ONE, Scalar::ZERO)
|
||||||
};
|
};
|
||||||
|
if flipped_construction {
|
||||||
|
uv_factor *= -1.;
|
||||||
|
}
|
||||||
|
|
||||||
let unit_vector_p0_to_p1 =
|
let unit_vector_p0_to_p1 =
|
||||||
(p1 - p0) / distance_between_endpoints * uv_factor;
|
(p1 - p0) / distance_between_endpoints * uv_factor;
|
||||||
let unit_vector_midpoint_to_center =
|
let unit_vector_midpoint_to_center =
|
||||||
@ -78,7 +73,6 @@ impl Arc {
|
|||||||
radius,
|
radius,
|
||||||
start_angle,
|
start_angle,
|
||||||
end_angle,
|
end_angle,
|
||||||
flipped_construction,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,7 +137,6 @@ mod tests {
|
|||||||
|
|
||||||
dbg!(arc.start_angle);
|
dbg!(arc.start_angle);
|
||||||
dbg!(arc.end_angle);
|
dbg!(arc.end_angle);
|
||||||
dbg!(arc.flipped_construction);
|
|
||||||
assert_abs_diff_eq!(arc.center, center, epsilon = epsilon);
|
assert_abs_diff_eq!(arc.center, center, epsilon = epsilon);
|
||||||
assert_abs_diff_eq!(
|
assert_abs_diff_eq!(
|
||||||
arc.radius,
|
arc.radius,
|
||||||
@ -151,30 +144,11 @@ mod tests {
|
|||||||
epsilon = epsilon
|
epsilon = epsilon
|
||||||
);
|
);
|
||||||
|
|
||||||
if a0 < a1 {
|
|
||||||
assert!(!arc.flipped_construction);
|
|
||||||
assert_abs_diff_eq!(
|
assert_abs_diff_eq!(
|
||||||
arc.start_angle,
|
arc.start_angle,
|
||||||
Scalar::from(a0),
|
Scalar::from(a0),
|
||||||
epsilon = epsilon
|
epsilon = epsilon
|
||||||
);
|
);
|
||||||
assert_abs_diff_eq!(
|
assert_abs_diff_eq!(arc.end_angle, Scalar::from(a1), epsilon = epsilon);
|
||||||
arc.end_angle,
|
|
||||||
Scalar::from(a1),
|
|
||||||
epsilon = epsilon
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
assert!(arc.flipped_construction);
|
|
||||||
assert_abs_diff_eq!(
|
|
||||||
arc.end_angle,
|
|
||||||
Scalar::from(a0),
|
|
||||||
epsilon = epsilon
|
|
||||||
);
|
|
||||||
assert_abs_diff_eq!(
|
|
||||||
arc.start_angle,
|
|
||||||
Scalar::from(a1),
|
|
||||||
epsilon = epsilon
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user