-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New node: QR Code #3565
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
Open
Sahil-Gupta584
wants to merge
6
commits into
GraphiteEditor:master
Choose a base branch
from
Sahil-Gupta584:qr-code-node
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+180
−0
Open
New node: QR Code #3565
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
64fff00
adding qr node
Sahil-Gupta584 99d8e8b
allow merging adjacent tiles in qr code node
Sahil-Gupta584 ad96061
fix tile merging
Sahil-Gupta584 c9f6cf8
making sqare merging deterministic
Sahil-Gupta584 bb191dd
fixing build
Sahil-Gupta584 198f4f4
Expose Ecc Setting
timon-schelling 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,118 @@ | ||
| use glam::DVec2; | ||
| use graphic_types::Vector; | ||
| use std::collections::VecDeque; | ||
| use vector_types::subpath; | ||
|
|
||
| pub fn merge_qr_squares(qr_code: &qrcodegen::QrCode, vector: &mut Vector) { | ||
| let size = qr_code.size() as usize; | ||
|
|
||
| // 0 = empty | ||
| // 1 = black, unvisited | ||
| // 2 = black, current island | ||
| let mut remaining = vec![vec![0u8; size]; size]; | ||
|
|
||
| for y in 0..size { | ||
| for x in 0..size { | ||
| if qr_code.get_module(x as i32, y as i32) { | ||
| remaining[y][x] = 1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for y in 0..size { | ||
| for x in 0..size { | ||
| if remaining[y][x] != 1 { | ||
| continue; | ||
| } | ||
|
|
||
| // fill island | ||
| let mut island = Vec::new(); | ||
| let mut queue = VecDeque::new(); | ||
| queue.push_back((x, y)); | ||
| remaining[y][x] = 2; | ||
|
|
||
| while let Some((ix, iy)) = queue.pop_front() { | ||
| island.push((ix, iy)); | ||
|
|
||
| for (dx, dy) in [(0, 1), (0, -1), (1, 0), (-1, 0)] { | ||
| let nx = ix as i32 + dx; | ||
| let ny = iy as i32 + dy; | ||
|
|
||
| if nx >= 0 && nx < size as i32 && ny >= 0 && ny < size as i32 && remaining[ny as usize][nx as usize] == 1 { | ||
| remaining[ny as usize][nx as usize] = 2; | ||
| queue.push_back((nx as usize, ny as usize)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // boundary detection | ||
| let mut outbound = vec![vec![0u8; size + 1]; size + 1]; | ||
|
|
||
| for &(ix, iy) in &island { | ||
| if iy == 0 || remaining[iy - 1][ix] != 2 { | ||
| outbound[iy][ix] |= 1 << 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit : consider adding constants here for directions |
||
| } | ||
| if ix == size - 1 || remaining[iy][ix + 1] != 2 { | ||
| outbound[iy][ix + 1] |= 1 << 1; | ||
| } | ||
| if iy == size - 1 || remaining[iy + 1][ix] != 2 { | ||
| outbound[iy + 1][ix + 1] |= 1 << 2; | ||
| } | ||
| if ix == 0 || remaining[iy][ix - 1] != 2 { | ||
| outbound[iy + 1][ix] |= 1 << 3; | ||
| } | ||
| } | ||
|
|
||
| // tracing loops | ||
| for vy in 0..=size { | ||
| for vx in 0..=size { | ||
| while outbound[vy][vx] != 0 { | ||
| let mut dir = outbound[vy][vx].trailing_zeros() as usize; | ||
| let start = (vx, vy); | ||
| let mut current = start; | ||
| let mut points = Vec::new(); | ||
|
|
||
| loop { | ||
| points.push(DVec2::new(current.0 as f64, current.1 as f64)); | ||
| outbound[current.1][current.0] &= !(1 << dir); | ||
|
|
||
| current = match dir { | ||
| 0 => (current.0 + 1, current.1), | ||
| 1 => (current.0, current.1 + 1), | ||
| 2 => (current.0 - 1, current.1), | ||
| 3 => (current.0, current.1 - 1), | ||
| _ => unreachable!(), | ||
| }; | ||
|
|
||
| if current == start { | ||
| break; | ||
| } | ||
| dir = outbound[current.1][current.0].trailing_zeros() as usize; | ||
| } | ||
|
|
||
| if points.len() > 2 { | ||
| let mut simplified = Vec::new(); | ||
| for i in 0..points.len() { | ||
| let prev = points[(i + points.len() - 1) % points.len()]; | ||
| let curr = points[i]; | ||
| let next = points[(i + 1) % points.len()]; | ||
| if (curr - prev).perp_dot(next - curr).abs() > 1e-6 { | ||
| simplified.push(curr); | ||
| } | ||
| } | ||
|
|
||
| if !simplified.is_empty() { | ||
| vector.append_subpath(subpath::Subpath::from_anchors(simplified, true), false); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // marking island as processed | ||
| for &(ix, iy) in &island { | ||
| remaining[iy][ix] = 0; | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
This should be
let ecc = match error_correction.min(3)@TrueDoctor @timon-schelling @Keavon , let me know if I am wrong here , but since the intent here seems to be clamp the input to a valid range of 0 - 3 ,
by using max here , wouldn't it give wrong outputs
User Input: 0 (wants Low)
→ 0.max(3) = 3
User gets HIGH instead of LOW
User Input: 1 (wants Medium) [THE DEFAULT]
→ 1.max(3) = 3
User gets HIGH instead of MEDIUM
User Input: 2 (wants Quartile)
→ 2.max(3) = 3
User gets HIGH instead of QUARTILE
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.
Yes, you are right, the logic is currently wrong