-
Notifications
You must be signed in to change notification settings - Fork 101
[SOLVE]: constraint freedom visualisation #9573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
126338a
inital constraint freedom
Irev-Dev e8b9891
fix conflict bugs
Irev-Dev 6c99112
make CI happy
Irev-Dev 4349586
make CI happier
Irev-Dev 8d995af
make CI happiest
Irev-Dev 1c5af13
make CI galaxy brain happy
Irev-Dev e22fd11
tidy up
Irev-Dev d96de89
make CI happy
Irev-Dev 915e74f
CI
Irev-Dev 08c2a98
Merge remote-tracking branch 'origin' into kurt-9281
Irev-Dev 686a1f0
The Fix
Irev-Dev 5d0d4c3
Merge remote-tracking branch 'origin' into kurt-9281
Irev-Dev 30b6dbc
comment update
Irev-Dev 8515d52
clippy
Irev-Dev 39b6b00
fix test
Irev-Dev 23f0289
fix issues
Irev-Dev b856930
Merge remote-tracking branch 'origin' into kurt-9281
Irev-Dev ff0b897
Jon's feedback
Irev-Dev 81f014a
fix all conflict state when dragging
Irev-Dev ff6e942
Merge remote-tracking branch 'origin' into kurt-9281
Irev-Dev b31b237
Jon's nits
Irev-Dev 0e1f291
clippy
Irev-Dev 90eb426
Merge remote-tracking branch 'origin' into kurt-9281
Irev-Dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| #[cfg(test)] | ||
| #[cfg(feature = "artifact-graph")] | ||
| mod test { | ||
| use std::sync::Arc; | ||
|
|
||
| use crate::{ | ||
| ExecutorContext, ExecutorSettings, | ||
| engine::conn_mock::EngineConnection, | ||
| execution::{ContextType, MockConfig}, | ||
| front::{Freedom, ObjectKind}, | ||
| frontend::api::ObjectId, | ||
| }; | ||
|
|
||
| async fn run_with_freedom_analysis(kcl: &str) -> Vec<(ObjectId, Freedom)> { | ||
| let program = crate::Program::parse_no_errs(kcl).unwrap(); | ||
|
|
||
| let exec_ctxt = ExecutorContext { | ||
| engine: Arc::new(Box::new(EngineConnection::new().unwrap())), | ||
| fs: Arc::new(crate::fs::FileManager::new()), | ||
| settings: ExecutorSettings::default(), | ||
| context_type: ContextType::Mock, | ||
| }; | ||
|
|
||
| let mock_config = MockConfig { | ||
| freedom_analysis: true, | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| let outcome = exec_ctxt.run_mock(&program, &mock_config).await.unwrap(); | ||
|
|
||
| let mut point_freedoms = Vec::new(); | ||
| for obj in &outcome.scene_objects { | ||
| if let ObjectKind::Segment { | ||
| segment: crate::front::Segment::Point(point), | ||
| } = &obj.kind | ||
| { | ||
| point_freedoms.push((obj.id, point.freedom)); | ||
| } | ||
| } | ||
| // Sort by object ID for consistent ordering | ||
| point_freedoms.sort_by_key(|(id, _)| id.0); | ||
| point_freedoms | ||
| } | ||
Irev-Dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn test_freedom_analysis_with_conflicts() { | ||
| let kcl = r#" | ||
| @settings(experimentalFeatures = allow) | ||
|
|
||
| sketch(on = YZ) { | ||
| line1 = sketch2::line(start = [var 2mm, var 8mm], end = [var 5mm, var 7mm]) | ||
| line1.start.at[0] == 2 | ||
| line1.start.at[1] == 8 | ||
| line1.end.at[0] == 5 | ||
| line1.end.at[1] == 7 | ||
|
|
||
|
|
||
| line2 = sketch2::line(start = [var 2mm, var 1mm], end = [var -4.75mm, var -0.88mm]) | ||
| line2.start.at[0] == 2 | ||
| line2.start.at[1] == 1 | ||
|
|
||
| line3 = sketch2::line(start = [var -2.591mm, var -7.081mm], end = [var 1.331mm, var -3.979mm]) | ||
| sketch2::distance([line3.start, line3.end]) == 4mm | ||
| sketch2::distance([line3.start, line3.end]) == 6mm | ||
| } | ||
| "#; | ||
|
|
||
| let point_freedoms = run_with_freedom_analysis(kcl).await; | ||
|
|
||
| // Expected: line1 has both ends constrained -> Fixed, Fixed | ||
| // line2 has one end constrained -> Fixed, Free (but currently shows Fixed, Conflict - bug) | ||
| // line3 has conflicting distance constraints -> Conflict, Conflict (but currently shows Free, Free - bug) | ||
| // Note: IDs skip every third because segments don't get freedom values | ||
| // Format: (ObjectId, Freedom) | ||
|
|
||
| println!("Point freedoms: {:?}", point_freedoms); | ||
Irev-Dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| let expected = vec![ | ||
| (ObjectId(1), Freedom::Fixed), | ||
| (ObjectId(2), Freedom::Fixed), | ||
| (ObjectId(4), Freedom::Fixed), | ||
| (ObjectId(5), Freedom::Free), | ||
| (ObjectId(7), Freedom::Conflict), | ||
| (ObjectId(8), Freedom::Conflict), | ||
| ]; | ||
|
|
||
| // This assertion will fail until the bug is fixed | ||
| assert_eq!( | ||
| point_freedoms, expected, | ||
| "Point freedoms should match expected values. Current behavior shows bugs with conflicts and reordered lines." | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn test_freedom_analysis_without_conflicts() { | ||
| let kcl = r#" | ||
| @settings(experimentalFeatures = allow) | ||
|
|
||
| sketch(on = YZ) { | ||
| line1 = sketch2::line(start = [var 2mm, var 8mm], end = [var 5mm, var 7mm]) | ||
| line1.start.at[0] == 2 | ||
| line1.start.at[1] == 8 | ||
| line1.end.at[0] == 5 | ||
| line1.end.at[1] == 7 | ||
|
|
||
|
|
||
| line2 = sketch2::line(start = [var 2mm, var 1mm], end = [var -4.75mm, var -0.88mm]) | ||
| line2.start.at[0] == 2 | ||
| line2.start.at[1] == 1 | ||
|
|
||
| line3 = sketch2::line(start = [var -2.591mm, var -7.081mm], end = [var 1.331mm, var -3.979mm]) | ||
| sketch2::distance([line3.start, line3.end]) == 4mm | ||
| } | ||
| "#; | ||
|
|
||
| let point_freedoms = run_with_freedom_analysis(kcl).await; | ||
|
|
||
| // Expected: line1 has both ends constrained -> Fixed, Fixed | ||
| // line2 has one end constrained -> Fixed, Free | ||
| // line3 has one distance constraint -> Free, Free (both points can move) | ||
|
|
||
| println!("Point freedoms: {:?}", point_freedoms); | ||
|
|
||
| // Expected: Fixed, Fixed, Fixed, Free, Free, Free | ||
| let expected = vec![ | ||
| (ObjectId(1), Freedom::Fixed), | ||
| (ObjectId(2), Freedom::Fixed), | ||
| (ObjectId(4), Freedom::Fixed), | ||
| (ObjectId(5), Freedom::Free), | ||
| (ObjectId(7), Freedom::Free), | ||
| (ObjectId(8), Freedom::Free), | ||
| ]; | ||
|
|
||
| assert_eq!(point_freedoms, expected, "Point freedoms should match expected values"); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn test_freedom_analysis_reordered_lines() { | ||
| let kcl = r#" | ||
| @settings(experimentalFeatures = allow) | ||
|
|
||
| sketch(on = YZ) { | ||
| line1 = sketch2::line(start = [var 2mm, var 8mm], end = [var 5mm, var 7mm]) | ||
| line1.start.at[0] == 2 | ||
| line1.start.at[1] == 8 | ||
| line1.end.at[0] == 5 | ||
| line1.end.at[1] == 7 | ||
|
|
||
| line3 = sketch2::line(start = [var -2.591mm, var -7.081mm], end = [var 1.331mm, var -3.979mm]) | ||
| sketch2::distance([line3.start, line3.end]) == 4mm | ||
| sketch2::distance([line3.start, line3.end]) == 6mm | ||
|
|
||
| line2 = sketch2::line(start = [var 2mm, var 1mm], end = [var -4.75mm, var -0.88mm]) | ||
| line2.start.at[0] == 2 | ||
| line2.start.at[1] == 1 | ||
|
|
||
| } | ||
| "#; | ||
|
|
||
| let point_freedoms = run_with_freedom_analysis(kcl).await; | ||
|
|
||
| // Expected: line1 has both ends constrained -> Fixed, Fixed | ||
| // line3 has conflicting distance constraints -> Conflict, Conflict (but bug shows one Conflict, one Free) | ||
| // line2 has one end constrained -> Fixed, Free | ||
|
|
||
| println!("Point freedoms: {:?}", point_freedoms); | ||
Irev-Dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| let expected = vec![ | ||
| (ObjectId(1), Freedom::Fixed), | ||
| (ObjectId(2), Freedom::Fixed), | ||
| (ObjectId(4), Freedom::Conflict), | ||
| (ObjectId(5), Freedom::Conflict), | ||
| (ObjectId(9), Freedom::Fixed), | ||
| (ObjectId(10), Freedom::Free), | ||
| ]; | ||
|
|
||
| // This assertion will fail until the bug is fixed | ||
| assert_eq!( | ||
| point_freedoms, expected, | ||
| "Point freedoms should match expected values. Current behavior shows bug where line3.end is Free instead of Conflict." | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added these tests failing before I started working on a fix, now they pass.