forked from 1b-agent/opencadstudio-upstream
fix(grips): compute grip positions in f64 so they sit on the wire
Grip markers drew visibly offset from the entity on large-coordinate (UTM-scale) drawings: every Grippable impl cast the f64 entity coordinates to f32 BEFORE the world-offset subtraction, and at 1e7 magnitude an f32 holds ~0.9 drawing units of rounding error. The wires subtract the offset in f64 first (precision-preserving), so the grips landed up to ~1 unit away from the geometry they belong to. GripDef.world is now DVec3: producers fill it straight from the f64 entity data, refresh_selected_grips subtracts the world offset in f64, and only the small offset-local result is cast to f32 for screen-space projection (grips_to_screen / find_hit_grip) and drag state. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
ed29933d87
commit
25715d1b03
33 files changed
+898
-817
No files matched your search
+8
-8
@@ -40,7 +40,7 @@ pub fn grips_to_screen(
|
||||
grips
|
||||
.iter()
|
||||
.map(|g| {
|
||||
let ndc = view_proj.project_point3(g.world);
|
||||
let ndc = view_proj.project_point3(g.world.as_vec3());
|
||||
let screen = Point::new(
|
||||
bounds.x + (ndc.x + 1.0) * 0.5 * bounds.width,
|
||||
bounds.y + (1.0 - ndc.y) * 0.5 * bounds.height,
|
||||
@@ -64,8 +64,8 @@ pub fn grips_to_screen_paper(
|
||||
.iter()
|
||||
.map(|g| {
|
||||
let screen = Point::new(
|
||||
(g.world.x - tx + half_w) / (2.0 * half_w) * bounds.width,
|
||||
(ty + half_h - g.world.y) / (2.0 * half_h) * bounds.height,
|
||||
(g.world.x as f32 - tx + half_w) / (2.0 * half_w) * bounds.width,
|
||||
(ty + half_h - g.world.y as f32) / (2.0 * half_h) * bounds.height,
|
||||
);
|
||||
(g.id, screen, g.is_midpoint, g.shape, g.dir)
|
||||
})
|
||||
@@ -87,15 +87,15 @@ pub fn find_hit_grip_paper(
|
||||
|
||||
for g in grips {
|
||||
let screen = Point::new(
|
||||
(g.world.x - tx + half_w) / (2.0 * half_w) * bounds.width,
|
||||
(ty + half_h - g.world.y) / (2.0 * half_h) * bounds.height,
|
||||
(g.world.x as f32 - tx + half_w) / (2.0 * half_w) * bounds.width,
|
||||
(ty + half_h - g.world.y as f32) / (2.0 * half_h) * bounds.height,
|
||||
);
|
||||
let dx = screen.x - cursor.x;
|
||||
let dy = screen.y - cursor.y;
|
||||
let d = (dx * dx + dy * dy).sqrt();
|
||||
if d < best_dist {
|
||||
best_dist = d;
|
||||
best = Some((g.id, g.is_midpoint, g.world));
|
||||
best = Some((g.id, g.is_midpoint, g.world.as_vec3()));
|
||||
}
|
||||
}
|
||||
best
|
||||
@@ -113,7 +113,7 @@ pub fn find_hit_grip(
|
||||
let mut best: Option<(usize, bool, Vec3)> = None;
|
||||
|
||||
for g in grips {
|
||||
let ndc = view_proj.project_point3(g.world);
|
||||
let ndc = view_proj.project_point3(g.world.as_vec3());
|
||||
let screen = Point::new(
|
||||
(ndc.x + 1.0) * 0.5 * bounds.width,
|
||||
(1.0 - ndc.y) * 0.5 * bounds.height,
|
||||
@@ -123,7 +123,7 @@ pub fn find_hit_grip(
|
||||
let d = (dx * dx + dy * dy).sqrt();
|
||||
if d < best_dist {
|
||||
best_dist = d;
|
||||
best = Some((g.id, g.is_midpoint, g.world));
|
||||
best = Some((g.id, g.is_midpoint, g.world.as_vec3()));
|
||||
}
|
||||
}
|
||||
best
|
||||
|
||||
+6
-2
@@ -75,8 +75,12 @@ pub enum GripShape {
|
||||
pub struct GripDef {
|
||||
/// Object-local identifier (stable index, unique per object instance).
|
||||
pub id: usize,
|
||||
/// World-space position of the grip.
|
||||
pub world: Vec3,
|
||||
/// World-space position of the grip, in f64. Entity coordinates can sit at
|
||||
/// UTM magnitudes (1e7); casting to f32 before the world-offset subtraction
|
||||
/// loses ~1 drawing unit and draws the grip visibly off the wire. Producers
|
||||
/// fill this straight from the f64 entity data; the offset is subtracted in
|
||||
/// f64 and only then cast for screen-space math.
|
||||
pub world: glam::DVec3,
|
||||
/// `true` → midpoint / centre grip (drags the whole shape).
|
||||
/// `false` → endpoint / vertex grip (moves a single point).
|
||||
pub is_midpoint: bool,
|
||||
|
||||
Reference in new issue
Block a user