forked from 1b-agent/opencadstudio-upstream
style: apply cargo fmt across workspace
This commit is contained in:
1 parent
85710e5454
commit
9cf9ff2c5c
531 files changed
+57740
-33906
No files matched your search
+38
-18
@@ -89,9 +89,11 @@ const PLANARITY_TOLERANCE: f64 = 1e-9;
|
||||
pub fn entity_curve(entity: &EntityType) -> Option<PlanarCurve> {
|
||||
match entity {
|
||||
EntityType::Line(line) => straight_curve(line.start, line.end, Straight::Segment),
|
||||
EntityType::Ray(ray) => {
|
||||
straight_curve(ray.base_point, ray.base_point + ray.direction, Straight::Ray)
|
||||
}
|
||||
EntityType::Ray(ray) => straight_curve(
|
||||
ray.base_point,
|
||||
ray.base_point + ray.direction,
|
||||
Straight::Ray,
|
||||
),
|
||||
EntityType::XLine(line) => straight_curve(
|
||||
line.base_point,
|
||||
line.base_point + line.direction,
|
||||
@@ -121,13 +123,18 @@ pub fn entity_spatial_measurement(entity: &EntityType) -> Option<kernel::space::
|
||||
SmoothSurfaceType::None => return None,
|
||||
};
|
||||
let controls: Vec<_> = crate::entities::polyline::polyline3d_controls(polyline)
|
||||
.into_iter().map(|vertex| xyz(vertex.position)).collect();
|
||||
let curve = NurbsCurve3::from_control_polygon(degree, &controls, polyline.is_closed())?;
|
||||
.into_iter()
|
||||
.map(|vertex| xyz(vertex.position))
|
||||
.collect();
|
||||
let curve =
|
||||
NurbsCurve3::from_control_polygon(degree, &controls, polyline.is_closed())?;
|
||||
return ArcLengthCurve3::from_nurbs(curve);
|
||||
}
|
||||
let points: Vec<_> = polyline.vertices.iter().map(|vertex| {
|
||||
[vertex.position.x, vertex.position.y, vertex.position.z]
|
||||
}).collect();
|
||||
let points: Vec<_> = polyline
|
||||
.vertices
|
||||
.iter()
|
||||
.map(|vertex| [vertex.position.x, vertex.position.y, vertex.position.z])
|
||||
.collect();
|
||||
return ArcLengthCurve3::from_polyline(&points, polyline.is_closed());
|
||||
}
|
||||
EntityType::Spline(spline) => {
|
||||
@@ -135,10 +142,18 @@ pub fn entity_spatial_measurement(entity: &EntityType) -> Option<kernel::space::
|
||||
crate::entities::spline::fit_nurbs3(spline)?
|
||||
} else {
|
||||
let controls: Vec<_> = spline.control_points.iter().copied().map(xyz).collect();
|
||||
let weights = if spline.weights.is_empty() { vec![1.0; controls.len()] }
|
||||
else { spline.weights.clone() };
|
||||
NurbsCurve3::new_strict(spline.degree as usize, controls, spline.knots.clone(), weights)?
|
||||
.with_periodicity(spline.flags.periodic)
|
||||
let weights = if spline.weights.is_empty() {
|
||||
vec![1.0; controls.len()]
|
||||
} else {
|
||||
spline.weights.clone()
|
||||
};
|
||||
NurbsCurve3::new_strict(
|
||||
spline.degree as usize,
|
||||
controls,
|
||||
spline.knots.clone(),
|
||||
weights,
|
||||
)?
|
||||
.with_periodicity(spline.flags.periodic)
|
||||
}
|
||||
}
|
||||
_ => return None,
|
||||
@@ -351,8 +366,7 @@ pub fn spline_curve(spline: &SplineEnt) -> Option<PlanarCurve> {
|
||||
for tangent in [spline.begin_tangent, spline.end_tangent] {
|
||||
let tangent = Vec3::from(xyz(tangent));
|
||||
if tangent.length_squared() > 1e-18
|
||||
&& tangent.dot(plane_normal).abs()
|
||||
> PLANARITY_TOLERANCE * tangent.length().max(1.0)
|
||||
&& tangent.dot(plane_normal).abs() > PLANARITY_TOLERANCE * tangent.length().max(1.0)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
@@ -431,8 +445,7 @@ pub fn lwpolyline_world_xy(polyline: &LwPolylineEnt) -> Option<LwPolylineEnt> {
|
||||
if normal.x.abs() > 1e-12 || normal.y.abs() > 1e-12 || normal.z.abs() <= 1e-12 {
|
||||
return None;
|
||||
}
|
||||
let Curve::Polyline(curve) = entity_curve_xy(&EntityType::LwPolyline(polyline.clone()))?
|
||||
else {
|
||||
let Curve::Polyline(curve) = entity_curve_xy(&EntityType::LwPolyline(polyline.clone()))? else {
|
||||
return None;
|
||||
};
|
||||
if curve.vertices.len() != polyline.vertices.len() {
|
||||
@@ -827,7 +840,11 @@ mod tests {
|
||||
polyline.normal = v3(0.0, 0.0, 1.0);
|
||||
let mut bend = LwVertex::from_coords(0.0, 0.0);
|
||||
bend.bulge = 0.9999999999999999;
|
||||
polyline.vertices = vec![LwVertex::from_coords(-20.0, 0.0), bend, LwVertex::from_coords(20.0, 0.0)];
|
||||
polyline.vertices = vec![
|
||||
LwVertex::from_coords(-20.0, 0.0),
|
||||
bend,
|
||||
LwVertex::from_coords(20.0, 0.0),
|
||||
];
|
||||
let snaps = arc_segment_snaps(&EntityType::LwPolyline(polyline));
|
||||
let at = |hint: SnapHint, x: f64, y: f64| {
|
||||
snaps.iter().any(|(p, h)| {
|
||||
@@ -890,7 +907,10 @@ mod tests {
|
||||
assert_eq!(solid.euler_characteristic(), 2);
|
||||
let document = codec::entities::acis::types::SatDocument::new();
|
||||
let (bodies, loss) = kernel::acis::lift(&document);
|
||||
assert!(bodies.is_empty() && loss.is_empty(), "an empty document lifts to nothing");
|
||||
assert!(
|
||||
bodies.is_empty() && loss.is_empty(),
|
||||
"an empty document lifts to nothing"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user