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
+62
-39
@@ -107,11 +107,7 @@ impl Camera {
|
||||
/// geometry closer to the eye can grow dramatically. Match the maximum
|
||||
/// projected extent of the model box instead, leaving target, rotation and
|
||||
/// field of view untouched.
|
||||
pub fn set_projection_preserving_frame(
|
||||
&mut self,
|
||||
projection: Projection,
|
||||
aspect: f32,
|
||||
) {
|
||||
pub fn set_projection_preserving_frame(&mut self, projection: Projection, aspect: f32) {
|
||||
if self.projection == projection {
|
||||
return;
|
||||
}
|
||||
@@ -275,9 +271,12 @@ impl Camera {
|
||||
view.w_axis = glam::vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
let proj = match self.projection {
|
||||
Projection::Perspective => {
|
||||
perspective(self.fov_y, aspect, self.distance * 0.001, self.distance * 1000.0)
|
||||
}
|
||||
Projection::Perspective => perspective(
|
||||
self.fov_y,
|
||||
aspect,
|
||||
self.distance * 0.001,
|
||||
self.distance * 1000.0,
|
||||
),
|
||||
Projection::Orthographic => {
|
||||
let h = self.ortho_size();
|
||||
let w = h * aspect;
|
||||
@@ -381,7 +380,6 @@ impl Camera {
|
||||
self.unproject_on_plane(screen, bounds, forward, self.target)
|
||||
}
|
||||
|
||||
|
||||
// ── ViewCube rotation matrix ───────────────────────────────────────────
|
||||
|
||||
/// Returns the rotation matrix for the ViewCube.
|
||||
@@ -397,19 +395,27 @@ impl Camera {
|
||||
/// when a transient UCS is baked into block-local geometry: the contents
|
||||
/// retain their on-screen framing while their canonical coordinates change.
|
||||
pub fn apply_rigid_transform(&mut self, transform: &codec::types::Transform) {
|
||||
let point = codec::types::Vector3::new(
|
||||
self.target.x,
|
||||
self.target.y,
|
||||
self.target.z,
|
||||
);
|
||||
let point = codec::types::Vector3::new(self.target.x, self.target.y, self.target.z);
|
||||
let point = transform.apply(point);
|
||||
self.target = DVec3::new(point.x, point.y, point.z);
|
||||
|
||||
let matrix = &transform.matrix.m;
|
||||
let rotation = glam::Mat3::from_cols(
|
||||
Vec3::new(matrix[0][0] as f32, matrix[1][0] as f32, matrix[2][0] as f32),
|
||||
Vec3::new(matrix[0][1] as f32, matrix[1][1] as f32, matrix[2][1] as f32),
|
||||
Vec3::new(matrix[0][2] as f32, matrix[1][2] as f32, matrix[2][2] as f32),
|
||||
Vec3::new(
|
||||
matrix[0][0] as f32,
|
||||
matrix[1][0] as f32,
|
||||
matrix[2][0] as f32,
|
||||
),
|
||||
Vec3::new(
|
||||
matrix[0][1] as f32,
|
||||
matrix[1][1] as f32,
|
||||
matrix[2][1] as f32,
|
||||
),
|
||||
Vec3::new(
|
||||
matrix[0][2] as f32,
|
||||
matrix[1][2] as f32,
|
||||
matrix[2][2] as f32,
|
||||
),
|
||||
);
|
||||
self.rotation = (Quat::from_mat3(&rotation) * self.rotation).normalize();
|
||||
self.sync_yaw_pitch();
|
||||
@@ -428,11 +434,8 @@ impl Camera {
|
||||
let mut new_min = DVec3::splat(f64::INFINITY);
|
||||
let mut new_max = DVec3::splat(f64::NEG_INFINITY);
|
||||
for corner in corners {
|
||||
let transformed = transform.apply(codec::types::Vector3::new(
|
||||
corner.x,
|
||||
corner.y,
|
||||
corner.z,
|
||||
));
|
||||
let transformed =
|
||||
transform.apply(codec::types::Vector3::new(corner.x, corner.y, corner.z));
|
||||
let transformed = DVec3::new(transformed.x, transformed.y, transformed.z);
|
||||
new_min = new_min.min(transformed);
|
||||
new_max = new_max.max(transformed);
|
||||
@@ -709,7 +712,11 @@ impl Camera {
|
||||
// (upside-down) view inverted.
|
||||
let cur_up = self.rotation * Vec3::Y;
|
||||
let raw_ref = if new_eye.dot(uz).abs() > 0.9 { uy } else { uz };
|
||||
let up_ref = if cur_up.dot(raw_ref) < 0.0 { -raw_ref } else { raw_ref };
|
||||
let up_ref = if cur_up.dot(raw_ref) < 0.0 {
|
||||
-raw_ref
|
||||
} else {
|
||||
raw_ref
|
||||
};
|
||||
let projected = up_ref - new_eye * up_ref.dot(new_eye);
|
||||
let new_up = projected.normalize_or(if new_eye.dot(uz).abs() < 0.99 {
|
||||
(uz - new_eye * uz.dot(new_eye)).normalize()
|
||||
@@ -954,7 +961,10 @@ mod tests {
|
||||
let clip = matrix * glam::vec4(0., 0., -distance, 1.);
|
||||
clip.z / clip.w
|
||||
};
|
||||
assert!(depth(near).abs() < 1e-5, "{projection:?}: near must map to 0");
|
||||
assert!(
|
||||
depth(near).abs() < 1e-5,
|
||||
"{projection:?}: near must map to 0"
|
||||
);
|
||||
assert!(
|
||||
(depth(far) - 1.).abs() < 1e-5,
|
||||
"{projection:?}: far must map to 1"
|
||||
@@ -1078,7 +1088,10 @@ mod rte_tests {
|
||||
let bounds = Rectangle::new(Point::ORIGIN, iced::Size::new(800.0, 600.0));
|
||||
for projection in [Projection::Orthographic, Projection::Perspective] {
|
||||
for distance in [0.01, 60.36, 71.08106, 100_000.0] {
|
||||
for origin in [DVec3::ZERO, DVec3::new(639_792.184_2, 4_517_057.531_7, 12.5)] {
|
||||
for origin in [
|
||||
DVec3::ZERO,
|
||||
DVec3::new(639_792.184_2, 4_517_057.531_7, 12.5),
|
||||
] {
|
||||
let camera = Camera {
|
||||
target: origin,
|
||||
distance,
|
||||
@@ -1087,11 +1100,17 @@ mod rte_tests {
|
||||
};
|
||||
for cursor in [Point::new(400.0, 300.0), Point::new(530.0, 215.0)] {
|
||||
let point = camera.pick_on_target_plane(cursor, bounds);
|
||||
assert_eq!(point.z, origin.z, "{projection:?}, distance={distance}, {point:?}");
|
||||
assert_eq!(
|
||||
point.z, origin.z,
|
||||
"{projection:?}, distance={distance}, {point:?}"
|
||||
);
|
||||
let normal = Vec3::new(0.2, -0.3, 1.0).normalize();
|
||||
let point = camera.pick_on_plane(cursor, bounds, normal, origin);
|
||||
let residual = (point - origin).dot(normal.as_dvec3());
|
||||
assert!(residual.abs() < 1e-9, "plane residual={residual}, {projection:?}, distance={distance}");
|
||||
assert!(
|
||||
residual.abs() < 1e-9,
|
||||
"plane residual={residual}, {projection:?}, distance={distance}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1110,10 +1129,16 @@ mod rte_tests {
|
||||
..Camera::default()
|
||||
};
|
||||
let offset = DVec3::new(639_792.184_2, 4_517_057.531_7, 12.5);
|
||||
let translated = Camera { target: offset, ..camera.clone() };
|
||||
let translated = Camera {
|
||||
target: offset,
|
||||
..camera.clone()
|
||||
};
|
||||
let here = camera.pick_on_target_plane(cursor, bounds);
|
||||
let there = translated.pick_on_target_plane(cursor, bounds) - offset;
|
||||
assert!(here.distance(there) < 1e-9, "{projection:?}: {here:?} vs {there:?}");
|
||||
assert!(
|
||||
here.distance(there) < 1e-9,
|
||||
"{projection:?}: {here:?} vs {there:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1140,7 +1165,11 @@ mod rte_tests {
|
||||
|
||||
let here = at_origin.view_proj_rte(bounds);
|
||||
let there = at_utm.view_proj_rte(bounds);
|
||||
for (a, b) in here.to_cols_array().iter().zip(there.to_cols_array().iter()) {
|
||||
for (a, b) in here
|
||||
.to_cols_array()
|
||||
.iter()
|
||||
.zip(there.to_cols_array().iter())
|
||||
{
|
||||
assert_eq!(a, b, "the camera's position reached the view matrix");
|
||||
}
|
||||
}
|
||||
@@ -1154,19 +1183,13 @@ mod rte_tests {
|
||||
for (yaw, pitch) in [(0.0, 1.2), (0.7, 0.3), (-2.1, -0.9)] {
|
||||
let mut camera = Camera::default();
|
||||
camera.target = glam::DVec3::ZERO;
|
||||
camera.rotation =
|
||||
Quat::from_rotation_z(yaw) * Quat::from_rotation_x(pitch);
|
||||
camera.rotation = Quat::from_rotation_z(yaw) * Quat::from_rotation_x(pitch);
|
||||
let up_dir = camera.rotation * Vec3::Y;
|
||||
|
||||
let mut old = look_at_mat4(
|
||||
camera.eye().as_vec3(),
|
||||
camera.target.as_vec3(),
|
||||
up_dir,
|
||||
);
|
||||
let mut old = look_at_mat4(camera.eye().as_vec3(), camera.target.as_vec3(), up_dir);
|
||||
old.w_axis = glam::vec4(0.0, 0.0, 0.0, 1.0);
|
||||
let new = {
|
||||
let mut view =
|
||||
look_at_mat4(Vec3::ZERO, -(camera.rotation * Vec3::Z), up_dir);
|
||||
let mut view = look_at_mat4(Vec3::ZERO, -(camera.rotation * Vec3::Z), up_dir);
|
||||
view.w_axis = glam::vec4(0.0, 0.0, 0.0, 1.0);
|
||||
view
|
||||
};
|
||||
|
||||
+22
-15
@@ -5,8 +5,8 @@ use codec::{EntityType, Handle};
|
||||
|
||||
use crate::command::EntityTransform;
|
||||
use crate::entities::traits::EntityTypeOps;
|
||||
use crate::scene::model::object::{GripDef, PropSection};
|
||||
use crate::scene::cache::properties;
|
||||
use crate::scene::model::object::{GripDef, PropSection};
|
||||
|
||||
thread_local! {
|
||||
/// Which vertex a multi-vertex entity's Properties panel is focused on
|
||||
@@ -81,11 +81,14 @@ pub fn properties_sectioned(
|
||||
sections.extend(groups);
|
||||
}
|
||||
if let Some(thickness) = entity_thickness(entity) {
|
||||
let already_present = sections.iter().flat_map(|section| §ion.props).any(|property| {
|
||||
property.field == "thickness"
|
||||
|| property.field == "sl_thickness"
|
||||
|| property.label == crate::t!("Thickness").as_ref()
|
||||
});
|
||||
let already_present = sections
|
||||
.iter()
|
||||
.flat_map(|section| §ion.props)
|
||||
.any(|property| {
|
||||
property.field == "thickness"
|
||||
|| property.field == "sl_thickness"
|
||||
|| property.label == crate::t!("Thickness").as_ref()
|
||||
});
|
||||
if !already_present {
|
||||
if let Some(geometry) = sections
|
||||
.iter_mut()
|
||||
@@ -327,7 +330,11 @@ pub fn apply_geom_prop(entity: &mut EntityType, field: &str, value: &str) {
|
||||
EntityTypeOps::apply_geom_prop(entity, field, value);
|
||||
}
|
||||
|
||||
pub fn apply_grip(entity: &mut EntityType, grip_id: usize, apply: crate::scene::model::object::GripApply) {
|
||||
pub fn apply_grip(
|
||||
entity: &mut EntityType,
|
||||
grip_id: usize,
|
||||
apply: crate::scene::model::object::GripApply,
|
||||
) {
|
||||
use crate::scene::model::object::GripApply;
|
||||
// Grip drags arrive in world space; per-entity apply code writes raw
|
||||
// fields, which for planar entities live in OCS — convert first (the
|
||||
@@ -371,11 +378,7 @@ pub fn refit_arc_grips(
|
||||
.collect::<Vec<_>>(),
|
||||
None => edits.to_vec(),
|
||||
};
|
||||
Some(crate::entities::arc::refit_grips(
|
||||
arc,
|
||||
original_arc,
|
||||
&edits,
|
||||
))
|
||||
Some(crate::entities::arc::refit_grips(arc, original_arc, &edits))
|
||||
}
|
||||
|
||||
/// Convert a world-space cursor point into the value expected by an
|
||||
@@ -388,8 +391,7 @@ pub fn grip_menu_point_value(
|
||||
) -> Option<f64> {
|
||||
let point = match planar_ocs_normal(entity) {
|
||||
Some(normal) => {
|
||||
let (x, y, z) =
|
||||
super::transform::wcs_point_to_ocs((point.x, point.y, point.z), normal);
|
||||
let (x, y, z) = super::transform::wcs_point_to_ocs((point.x, point.y, point.z), normal);
|
||||
glam::DVec3::new(x, y, z)
|
||||
}
|
||||
None => point,
|
||||
@@ -418,7 +420,12 @@ mod tests {
|
||||
.any(|property| property.field == "thickness"));
|
||||
let geometry = sections
|
||||
.iter()
|
||||
.find(|section| section.props.iter().any(|property| property.field == "start_x"))
|
||||
.find(|section| {
|
||||
section
|
||||
.props
|
||||
.iter()
|
||||
.any(|property| property.field == "start_x")
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(geometry.props.last().unwrap().field, "thickness");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod camera;
|
||||
pub mod dispatch;
|
||||
pub mod render;
|
||||
pub mod transform;
|
||||
pub mod viewport_pane;
|
||||
pub mod render;
|
||||
pub mod dispatch;
|
||||
+484
-463
File diff suppressed because it is too large.
Load diff
+53
-19
@@ -13,7 +13,10 @@ where
|
||||
T: codec::Entity,
|
||||
{
|
||||
let t = Transform::from_translation(to_v3(-center))
|
||||
.then(&Transform::from_rotation(to_v3(axis.normalize_or(DVec3::Z)), angle_rad))
|
||||
.then(&Transform::from_rotation(
|
||||
to_v3(axis.normalize_or(DVec3::Z)),
|
||||
angle_rad,
|
||||
))
|
||||
.then(&Transform::from_translation(to_v3(center)));
|
||||
entity.apply_transform(&t);
|
||||
}
|
||||
@@ -34,23 +37,24 @@ where
|
||||
{
|
||||
match t {
|
||||
EntityTransform::Translate(d) => entity.translate(to_v3(*d)),
|
||||
EntityTransform::Rotate { center, axis, angle_rad } => {
|
||||
apply_standard_transform(entity, *center, *axis, *angle_rad)
|
||||
}
|
||||
EntityTransform::Rotate {
|
||||
center,
|
||||
axis,
|
||||
angle_rad,
|
||||
} => apply_standard_transform(entity, *center, *axis, *angle_rad),
|
||||
EntityTransform::Scale { center, factor } => apply_standard_scale(entity, *center, *factor),
|
||||
EntityTransform::Mirror {
|
||||
p1,
|
||||
p2,
|
||||
working_normal,
|
||||
} => {
|
||||
if working_normal.normalize_or(DVec3::Z).abs_diff_eq(DVec3::Z, 1e-10) {
|
||||
if working_normal
|
||||
.normalize_or(DVec3::Z)
|
||||
.abs_diff_eq(DVec3::Z, 1e-10)
|
||||
{
|
||||
mirror(entity, *p1, *p2)
|
||||
} else {
|
||||
entity.apply_transform(&reflection_about_working_line(
|
||||
*p1,
|
||||
*p2,
|
||||
*working_normal,
|
||||
));
|
||||
entity.apply_transform(&reflection_about_working_line(*p1, *p2, *working_normal));
|
||||
}
|
||||
}
|
||||
EntityTransform::Affine(transform) => entity.apply_transform(transform),
|
||||
@@ -84,9 +88,24 @@ pub fn reflection_about_working_line(
|
||||
let d = 2.0 * n.dot(p1);
|
||||
Transform::from_matrix(Matrix4 {
|
||||
m: [
|
||||
[1.0 - 2.0 * n.x * n.x, -2.0 * n.x * n.y, -2.0 * n.x * n.z, d * n.x],
|
||||
[-2.0 * n.y * n.x, 1.0 - 2.0 * n.y * n.y, -2.0 * n.y * n.z, d * n.y],
|
||||
[-2.0 * n.z * n.x, -2.0 * n.z * n.y, 1.0 - 2.0 * n.z * n.z, d * n.z],
|
||||
[
|
||||
1.0 - 2.0 * n.x * n.x,
|
||||
-2.0 * n.x * n.y,
|
||||
-2.0 * n.x * n.z,
|
||||
d * n.x,
|
||||
],
|
||||
[
|
||||
-2.0 * n.y * n.x,
|
||||
1.0 - 2.0 * n.y * n.y,
|
||||
-2.0 * n.y * n.z,
|
||||
d * n.y,
|
||||
],
|
||||
[
|
||||
-2.0 * n.z * n.x,
|
||||
-2.0 * n.z * n.y,
|
||||
1.0 - 2.0 * n.z * n.z,
|
||||
d * n.z,
|
||||
],
|
||||
[0.0, 0.0, 0.0, 1.0],
|
||||
],
|
||||
})
|
||||
@@ -151,7 +170,10 @@ pub fn transform_ellipse_geometry(
|
||||
};
|
||||
ellipse.apply_transform(transform);
|
||||
let values = [ellipse.center, ellipse.major_axis, ellipse.normal];
|
||||
if values.iter().any(|v| !(v.x.is_finite() && v.y.is_finite() && v.z.is_finite())) {
|
||||
if values
|
||||
.iter()
|
||||
.any(|v| !(v.x.is_finite() && v.y.is_finite() && v.z.is_finite()))
|
||||
{
|
||||
return None;
|
||||
}
|
||||
Some((
|
||||
@@ -308,11 +330,15 @@ mod ocs_axes_142 {
|
||||
#[test]
|
||||
fn x_normal_axes_nonzero() {
|
||||
let (ax, ay) = super::ocs_axes((-1.0, 0.0, 0.0));
|
||||
let nz = |v: (f64,f64,f64)| v.0.abs()+v.1.abs()+v.2.abs();
|
||||
let nz = |v: (f64, f64, f64)| v.0.abs() + v.1.abs() + v.2.abs();
|
||||
assert!(nz(ax) > 0.5, "ax collapsed: {:?}", ax);
|
||||
assert!(nz(ay) > 0.5, "ay collapsed: {:?}", ay);
|
||||
let p = super::ocs_point_to_wcs((-25.0, 90.0, 0.0), (-1.0,0.0,0.0));
|
||||
assert!(p.0.abs()+p.1.abs()+p.2.abs() > 1.0, "point collapsed: {:?}", p);
|
||||
let p = super::ocs_point_to_wcs((-25.0, 90.0, 0.0), (-1.0, 0.0, 0.0));
|
||||
assert!(
|
||||
p.0.abs() + p.1.abs() + p.2.abs() > 1.0,
|
||||
"point collapsed: {:?}",
|
||||
p
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,7 +347,13 @@ mod ellipse_transform_tests {
|
||||
use super::*;
|
||||
use std::f64::consts::{FRAC_PI_2, FRAC_PI_4};
|
||||
|
||||
fn sample_point(center: Vector3, major: Vector3, normal: Vector3, ratio: f64, t: f64) -> Vector3 {
|
||||
fn sample_point(
|
||||
center: Vector3,
|
||||
major: Vector3,
|
||||
normal: Vector3,
|
||||
ratio: f64,
|
||||
t: f64,
|
||||
) -> Vector3 {
|
||||
let u = major;
|
||||
let v = normal.normalize().cross(&major) * ratio;
|
||||
center + u * t.cos() + v * t.sin()
|
||||
@@ -341,7 +373,9 @@ mod ellipse_transform_tests {
|
||||
let rot_rad = -FRAC_PI_4;
|
||||
let transform = Transform::from_scaling(Vector3::new(-1.0, -1.0, 1.0))
|
||||
.then(&Transform::from_rotation(Vector3::UNIT_Z, rot_rad))
|
||||
.then(&Transform::from_translation(Vector3::new(100.0, 200.0, 0.0)));
|
||||
.then(&Transform::from_translation(Vector3::new(
|
||||
100.0, 200.0, 0.0,
|
||||
)));
|
||||
|
||||
let (c, m, n, r, s, e) = transform_ellipse_geometry(
|
||||
center,
|
||||
|
||||
Reference in new issue
Block a user