mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-28 09:21:55 +01:00
Merge pull request #9772 from dotCooCoo/fix/track-cube-untouched-axes-b-verify
Preserve untouched Track Cube rotation angles
This commit is contained in:
4 files changed
+81
-2
No files matched your search
@@ -74,7 +74,8 @@ fn tidy(degrees: f64) -> f64 {
|
||||
|
||||
/// The X, Y and Z angles of rotation `m`. Of the two sets of angles that make it, the one nearest
|
||||
/// `near` (so a turn moves the fields as little as it can); with Y at ±90°, where X and Z turn about
|
||||
/// the same axis, X keeps its value from `near`.
|
||||
/// the same axis, X keeps its value from `near`. An unchanged axis keeps its original precision;
|
||||
/// only an angle that actually turned is tidied to the fields' precision.
|
||||
fn angles_of(m: M3, near: [f64; 3]) -> [f64; 3] {
|
||||
let y = (-m[2][0]).clamp(-1.0, 1.0).asin().to_degrees();
|
||||
let candidates = if m[2][1].hypot(m[2][2]) < 1e-9 {
|
||||
@@ -87,7 +88,11 @@ fn angles_of(m: M3, near: [f64; 3]) -> [f64; 3] {
|
||||
[Some([x, y, z]), Some([x + 180.0, 180.0 - y, z + 180.0])]
|
||||
};
|
||||
let distance = |a: &[f64; 3]| a.iter().zip(near).map(|(a, b)| tidy(a - b).abs()).sum::<f64>();
|
||||
candidates.into_iter().flatten().min_by(|a, b| distance(a).total_cmp(&distance(b))).unwrap_or(near).map(tidy)
|
||||
let chosen = candidates.into_iter().flatten().min_by(|a, b| distance(a).total_cmp(&distance(b))).unwrap_or(near);
|
||||
std::array::from_fn(|i| {
|
||||
let delta = (chosen[i] - near[i] + 180.0).rem_euclid(360.0) - 180.0;
|
||||
if delta.abs() <= 1e-9 { near[i] } else { tidy(chosen[i]) }
|
||||
})
|
||||
}
|
||||
|
||||
/// Where corner `i` of the cube (bit 0 for +X, bit 1 for +Y, bit 2 for +Z) is drawn.
|
||||
@@ -392,6 +397,7 @@ impl Component for TrackCube<'_> {
|
||||
/// The track cube's row on the Rotation page of the 3D (Classic) effects. It reads and writes `rotationX`, `rotationY` and
|
||||
/// `rotationZ` (a missing one reads the effect's default) and only writes an angle that changes; the dialog's preview applies
|
||||
/// them and OK records them as one undo step. Its control's events go to the rows, so a drag previews and Escape restores.
|
||||
/// A screen-plane turn changes Z while retaining the original precision of X and Y.
|
||||
pub(crate) fn row() -> Param {
|
||||
Param::custom("__trackCube", tl!("Track cube"), |ui, fields, cx| {
|
||||
let defaults = vectorcraft_effects::default_params(fields.text("__effect").unwrap_or_default()).unwrap_or(json!({}));
|
||||
@@ -455,3 +461,70 @@ fn paint_cube(painter: &egui::Painter, s: &RowStyle, rect: Rect, m: M3, active:
|
||||
#[cfg(test)]
|
||||
#[path = "tests_track_cube.rs"]
|
||||
mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod precision_tests {
|
||||
use super::*;
|
||||
use crate::VectorcraftApp;
|
||||
use crate::tests::panel_harness::Panel;
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, HostedParamDialog};
|
||||
use egui::{Key, Modifiers};
|
||||
use serde_json::Value;
|
||||
use vectorcraft_effects::CLASSIC_ROTATE;
|
||||
|
||||
fn fields(panel: &Panel) -> DialogFields {
|
||||
panel.app().dialogs().unwrap().with(|host| host.get::<HostedParamDialog>().unwrap().fields().clone())
|
||||
}
|
||||
|
||||
fn stored(panel: &Panel, node: u64) -> Value {
|
||||
panel.app().session.active().unwrap().doc.node(vectorcraft_doc::NodeId(node)).unwrap().appearance.effects[0].params.clone()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn screen_plane_keys_preserve_the_untouched_rotation_axes_through_preview_and_ok() {
|
||||
let initial = [17.234567, 23.456789, 9.06];
|
||||
for (key, z) in [(Key::PageDown, 10.06), (Key::PageUp, 8.06)] {
|
||||
for save in [false, true] {
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
let node = app.run("shape.rectangle", json!({"x": 20, "y": 20, "width": 80, "height": 80})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.set", json!({"ids": [node]})).unwrap();
|
||||
app.run(
|
||||
"effect.apply",
|
||||
json!({"effect": CLASSIC_ROTATE, "ids": [node], "item": null,
|
||||
"params": {"rotationX": initial[0], "rotationY": initial[1], "rotationZ": initial[2]}}),
|
||||
)
|
||||
.unwrap();
|
||||
let original = app.session.active().unwrap().doc.clone();
|
||||
let undo = app.session.active().unwrap().history.undo.len();
|
||||
let mut panel = Panel::new(app, crate::tests::picks::dialogs);
|
||||
panel.room(egui::vec2(1100.0, 1100.0));
|
||||
panel.app().run("effect.dialog", json!({"effect": CLASSIC_ROTATE, "index": 0, "item": null})).unwrap();
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
assert!(panel.app().dialogs().unwrap().with(|host| host.get::<HostedParamDialog>().unwrap().is_previewing()));
|
||||
let read = |value: &DialogFields| ROTATION_KEYS.map(|key| value.number(key).unwrap());
|
||||
assert_eq!(read(&fields(&panel)), initial, "the real dialog opens on the exact fractional rotations");
|
||||
panel.click_role("Track cube", Role::SLIDER);
|
||||
assert_eq!(read(&fields(&panel)), initial, "a click without a drag moves no axis");
|
||||
panel.key(key, Modifiers::NONE);
|
||||
let expected = [initial[0], initial[1], z];
|
||||
assert_eq!(read(&fields(&panel)), expected, "a screen-plane turn changes only Euler Z");
|
||||
let preview = stored(&panel, node);
|
||||
assert_eq!(ROTATION_KEYS.map(|key| preview[key].as_f64().unwrap()), expected);
|
||||
assert_eq!(panel.app().session.active().unwrap().history.undo.len(), undo);
|
||||
panel.click(if save { "OK" } else { "Cancel" });
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
assert!(!panel.app().dialogs().unwrap().with(|host| host.is_open::<HostedParamDialog>()));
|
||||
assert_eq!(panel.app().session.active().unwrap().history.undo.len(), undo + usize::from(save));
|
||||
if save {
|
||||
let applied = stored(&panel, node);
|
||||
assert_eq!(ROTATION_KEYS.map(|key| applied[key].as_f64().unwrap()), expected);
|
||||
panel.app().run("edit.undo", json!({})).unwrap();
|
||||
}
|
||||
assert_eq!(panel.app().session.active().unwrap().doc, original);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5966,6 +5966,8 @@ and No Shading and Diffuse Shading as the only surfaces for an object that uses
|
||||
The defaults and the shading are VectorCraft's own. An unknown parameter (`highlightSize` and `drawHiddenFaces`
|
||||
included), a number out of range, a flag that is not true or false, a surface other than `none` or `diffuse`, or
|
||||
another shading color is refused with an error and the document is not changed.
|
||||
In all three Classic dialogs, the track cube retains untouched rotation components at their original precision;
|
||||
Page Up and Page Down change Z without rounding fractional X and Y values.
|
||||
|
||||
```json
|
||||
{"name":"run_command","arguments":{"command":"effect.apply","params":{"effect":"threeD.classicRotate","item":null,"params":{"rotationX":0,"rotationY":40,"rotationZ":0,"surface":"diffuse","blendSteps":64}}}}
|
||||
|
||||
@@ -373,6 +373,8 @@ presets, drawn at the current X, Y and Z rotation inside a ring
|
||||
The drag changes the effect's `rotationX`, `rotationY` and `rotationZ` and previews live; X, Y and Z and the
|
||||
presets follow it (**Custom** off a preset). OK keeps the change as one undo step. The angles stay between -180°
|
||||
and 180°: of the two sets of angles that give the same turn, the cube writes the one nearest the current values.
|
||||
Untouched axes retain their original precision; only a changed axis is rounded to the fields' precision. Page Up
|
||||
and Page Down change Z while preserving fractional X and Y values.
|
||||
In the 3D and Materials panel, a drag is one undo step when the pointer is released, and the cube is off while the
|
||||
selected effects hold different rotations. The cube's 0.5° per point of drag, Escape during a drag and its keyboard
|
||||
steps are VectorCraft's own.
|
||||
@@ -758,6 +760,7 @@ Release measurements and a repeatable CLI scene are in [3D lighting performance]
|
||||
|
||||
| Date | Change |
|
||||
|---|---|
|
||||
| 2026-11-27 | Classic track cube screen-plane keyboard turns preserve untouched fractional X/Y angles through preview, OK, Cancel and Undo. |
|
||||
| 2026-11-13 | Extrude & Bevel cuts its walls into slices only for a twist. A taper alone keeps each wall flat, so it is one face, without the light ticks at the joints between slices or the light line down a wall (#7019). Inflate still slices its sides for a taper. |
|
||||
| 2026-11-12 | The seams of Extrude & Bevel, Inflate and Rotate under a white light, and of the faces of Extrude & Bevel (Classic), Revolve (Classic) and Rotate (Classic), went from miter to round joins (the seams of Revolve and of colored lights, and 3D (Classic) Wireframe edges, were already round): no thorns on edge-on facets, and facets with no neighbor now have rounded convex corners ([Seams](#seams)). |
|
||||
| 2026-11-08 | Contours that cross, touch or overlap are merged by vectorcraft-pathops before Extrude & Bevel, Inflate and Rotate build a solid, sharing its limits; others are built as drawn. |
|
||||
|
||||
@@ -360,6 +360,7 @@ tools, never checked side by side) isn't captured row by row.
|
||||
| Field precision: 3 decimals for steps; values kept as f64 | done | |
|
||||
| Scrubby labels (beyond Illustrator) | done | #400; the labels that are links (the Control bar's Stroke: and Opacity:, the Properties panel's Stroke) scrub too, and a click on them still opens their panel (#4088) |
|
||||
| 3D Lighting Color picker, preview, reset dot and Reset all | initial | One to ten opaque RGB lights for Revolve, Extrude & Bevel, Inflate and Rotate; select, add or delete a light and edit its settings or gizmo; Standard, Diffuse, Top Left and Right select original rigs, with Custom for manual changes; Cancel restores all lights |
|
||||
| Classic 3D Track Cube preserves untouched rotation precision | done | Editing Z preserves the original fractional X and Y angles. |
|
||||
| Dialogs open with the first field focused and selected; Enter confirms | done | on every open, not only the first (#1367); a first field that starts greyed out takes the focus once enabled (#1395) |
|
||||
| Value fields: selected text readable in every brightness; a focused field follows its value when a slider or preview changes it | partial | #1490, #1457; hover wheel stepping #5949 |
|
||||
| Sliders in dialogs and popups (Save for Web, raster export options, Preferences, the opacity popup) show their rail, filled up to the handle | done | #1483 |
|
||||
|
||||
Reference in new issue
Block a user