Repository navigation
Conversation
… dont want that added to repo
…is rejected, test missing file is rejected
…nuing to improve loader.py.
…justments on test.
…interpret all stickers as continuous, connecting around the outline.
…raphical or easy representation for him tues.
… but that would be cool. moving to proper algo rewrite.
…ill do more in a moment
…s refined through me getting better svg models honestly
…en-Source-Sticker-Micro-Business into feature/algorithm-development
…, and if the stickers are actually there or not
There was a problem hiding this comment.
Hey, I apologize for how long its taken me to get this review done. I walked through it with Claude Code and apart from the comments I made in the comment I have some more comments/suggestions below:
- Include a README giving a quick overview of the algorithm, how each version works, and how to run them alongside their tests. Include all your dependencies in a requirements.txt.
- Is
algo_doc.mdup to date? It can be a living document where you have a changelog at the top so its easy to tell when the last time it was updated was. - You should add a function that generates both a PDF and HPGL file from the same sticker placement. Basically a function one can hit run on and see the entire workflow completed. And that needs error handling too. For example, an HPGL file succeeds but PDF fails.
- Claude found this while reviewing the branch. The new test in
tests/test_svg_input.py: test_svg_y_axis_is_flipped_to_point_upconfirms it by currently failing. SVG y-values increase going down, but the rest of the app (packer, HPGL, PDF) treats y as increasing going up.load_sticker_svgcopies the SVG coordinates without converting them, so every sticker comes out ofapp/svg/loader.pymirrored top-to-bottom. Claude recommends addingfrom shapely.affinity import scaletoloader.pyand changing line 175 toreturn scale(Polygon(geometry.exterior), xfact=1, yfact=-1, origin="center")so the loader flips the sticker when it returns. - The current packing algorithms don't ingest the size of a sticker. They need to be modified to accept a sticker size (height and width) and ensure they pack using that sticker size.
| assert "PU10,0;" in content | ||
| assert "PD10,5,0,5,0,0;" in content | ||
| assert "PU;" in content | ||
| assert "SP0;" in content |
There was a problem hiding this comment.
A closed sticker outline would have to return to 10,0 since that's where you started (line 19). I think you're missing that in this test.
| commands.append(f"PU{start_x},{start_y};") | ||
|
|
||
| #lower pen | ||
| remaining_points = points[1:-1] |
There was a problem hiding this comment.
We need all the remaining points for the plotter to return to its starting point. By returning -1 we'd be missing the final edge of the sticker. Is there something I'm missing?
There was a problem hiding this comment.
for array indexing, -1 is the last point in the array. it's not just reporting the int -1.
There was a problem hiding this comment.
The [1:-1] means that we are returning a slice of the original array from the second element to the second to last element. The -1 means we do not include the final element of the array. Why did you chose to not include the final element of the array?
There was a problem hiding this comment.
That is incorrect, like I had said. It slices the second element to the last element of the array. What are you saying?
There was a problem hiding this comment.
The last element in the array is the starting point. It will already include the last element by nature of starting there.
There was a problem hiding this comment.
I think the sticker-business/packing-algorithm/ should be the only home for the algorithm. Is there a need to keep the original root level algorithm folder?
There was a problem hiding this comment.
No, there's not, but it has some of my important code and pieces and I wanted to ensure it stuck around for a little. I'll remove it when I can.
| _, bottom, right, top = candidate.bounds | ||
| score = (top,right,bottom, x,y, angle) | ||
| candidates.append((score, candidate)) | ||
| if candidates: |
There was a problem hiding this comment.
Right now, we ignore any stickers that don't make it on to the sheet. But if our algorithm occasionally fails to fit a sticker on a sheet, the algorithm needs to raise an Error so the frontend notifies the user.
I recommend giving the algorithm a pass focused on Error handling so failures or unexpected behaviors while running the algorithm can notify the frontend when integration happens.
I see this change requiring system-level considerations. If you think this decision merits team input, we can try to set something up with the team before Tuesday.
| while y < max_y: | ||
| x = min_x | ||
| while x < max_x: | ||
| for sticker in stickers: |
There was a problem hiding this comment.
I think this supposed to be remaining and not stickers.
There was a problem hiding this comment.
No, it's stickers. This is double checking placements of all possible stickers in that set. We're also not really worrying about greedy rn anyway, this is just the first pass algo. I'll revisit during break.
There was a problem hiding this comment.
In that case the remaining variable in line 27 is unused.
|
|
||
| FIXTURES = Path(__file__).parent / "fixtures" | ||
|
|
||
| def test_svg_loads_as_one_nonempty_sticker(): |
There was a problem hiding this comment.
There's another function on line 67 with the same name.
| @@ -0,0 +1,28 @@ | |||
| [build-system] | |||
| requires = ["setuptools>=75"] | |||
| build-backed = "setuptools.build_meta" | |||
There was a problem hiding this comment.
Is this supposed to be backend and not backed?
| ] | ||
|
|
||
| [tool.pytest.ini_options] | ||
| testpaths = ["test"] |
There was a problem hiding this comment.
Typo: the testing folder is named tests
| from shapely.affinity import rotate, translate | ||
| from app.models.sticker import Sticker | ||
|
|
||
| PAGE_SIZE = (5.5*inch, 8.5*inch) |
There was a problem hiding this comment.
This should be a global constant that the packer, PDF and HPGL generators all use. Then we can also use it to validate the output of the algorithm actually fits on a sheet. It should by design, but its not a bad idea to do a check on the output.
| def save_hpgl( | ||
| placements, | ||
| output, | ||
| units_per_unit=1, |
There was a problem hiding this comment.
Rename this variable so the input and output units are obvious at a glance.
We convert from SVG units to HPGL points. The SVG units are also converted into PDF points in the PDF generator to map the sticker on to the sheet. We need the conversion of units between SVG, PDF and HPGL to be explicit. A PDF unit is 1/72 in and an HPGL unit is 1/1016 in. These values should be stored as a global constants alongside the default size of PDF half sheet, so we can easily convert between the units.
The unit_per_unit field should then become HPGL units / PDF units by default.
HPGL_UNITS_PER_INCH = 1016
PDF_POINTS_PER_INCH = 72
…re-Engineering/Open-Source-Sticker-Micro-Business into feature/algorithm-development
|
also, remember to follow our git commit message style in future commits |
Describe your changes
Adding algorithm development into the main branch. this encapsulates svg and hpgl generation. PDF will be added, as well as a visual requirement in later prs.
Issue/Story ticket number and link
#22
Issue 22: 2D shape Packing Algorithm
Checklist before requesting a review