diff --git a/algorithm/.gitignore b/algorithm/.gitignore
new file mode 100644
index 0000000..f6d9080
--- /dev/null
+++ b/algorithm/.gitignore
@@ -0,0 +1,31 @@
+
+# Python bytecode and caches
+__pycache__/
+*.py[cod]
+.pytest_cache/
+.coverage
+htmlcov/
+
+# Virtual environments
+.venv/
+venv/
+env/
+
+# Packaging/build artifacts
+build/
+dist/
+*.egg-info/
+
+# IDE/editor settings
+.vscode/
+.idea/
+*.swp
+*.swo
+
+# OS files
+.DS_Store
+Thumbs.db
+
+# Generated output
+output/*
+!output/.gitkeep
diff --git a/algorithm/algo_doc.md b/algorithm/algo_doc.md
new file mode 100644
index 0000000..4fc866d
--- /dev/null
+++ b/algorithm/algo_doc.md
@@ -0,0 +1,110 @@
+I’m using a bottom-left greedy polygon-packing algorithm with a compactness score. Basically, place the biggest/weirdest/most difficult sticker first, then place the next one in the lowest leftmost position that produces the most compact sheet.
+It’s greedy because I’m not planning on moving stickers again after placing them, as that would be very expensive computationally and time-wise.
+It’s not optimal! But it is relatively fast, deterministic, human-readable, and with polygon geometry it can be very good.
+For my code and for your visualization, I’m using tetris shapes.
+
+Steps:
+Get info from stickers.
+For a quick example, 2 5 square pieces.
+A
+O O
+O
+O
+O
+(0,0)(1,0)
+(0,1)
+(0,2)
+(0,3)
+
+And
+B
+O O
+O O
+O
+(0,0)(1,0)
+(0,1)(1,1)
+(0,2)
+(this is just convenient picks to show the program)
+
+2: Sort the stickers
+We need to place the largest sticker first, so we sort with a couple parameters.
+Area, bounding-box area (ill get to this later), width, height, complexity.
+(easiest version:
+stickers.sort(
+ key=lambda sticker: sticker.area,
+ reverse=True
+)
+)
+
+For example, A would have an area of 5, and so would B. Their bounding box would be 2*4 for A, but only 2*3 for B, so you could put A first because it’s more awkward. Pick weird shapes first.
+
+3:
+The sheet can be whatever size you want, so we can arbitrarily choose what our demo sheet size is (obviously usually it’s 8x4 or whatever the size of a half sheet is)
+
+4:
+Sticker by Sticker
+First, nothing on the sheet, so the candidate is (0,0)
+And you place A there, taking up
+(0,0)(1,0)
+(0,1)
+(0,2)
+(0,3)
+Then, B:
+The laziest implementation would look at every coordinate, but because we’re not just working in whole numbers, that’s not helpful.
+We would want to look for each edge of the current shape, including
+Right side, bottom line, corners, and internal vertices.
+For this example we get (2,0)(1,1)(1,2)(1,3) and (0,4) as options.
+
+5: Where to put it
+We go through all of the candidates!
+(2,0)
+If we place at 2,0 it looks like
+O O O O
+O X O O
+O X O X
+O X X X
+So the placement would be (2,0)
+
+(1,1)
+It looks like
+O O X X
+O O O X
+O O O X
+O O X X
+
+Continue for all of those position, then consider rotations of the shape.
+
+A simple algorithm prefers lowest x, then lowest y, cram it all in the corner. However, I also want to consider going for the most square space.
+O O X X feels more helpful than O O X X
+O O X X O O O X
+O O O O O O O X
+O O O O O O O X
+
+Because it can fit a bigger sticker in that space. (Want to figure this out, what im working on currently.)
+
+So, I used a score: height of the shape after placement + wasted space + fragmentation. A lower score is better.
+
+For option (2,0) our choice was
+O O O O
+O X O O
+O X O X
+O X X X
+With a bounding box of 4*4
+Where
+O O X X
+O O O X
+O O O X
+O O X X
+Only has 3*4.
+So it chooses that one.
+
+That pattern continues until we get the smallest total area and score.
+Obviously normal stickers aren’t just blocks but this is proof of concept that should work.
+
+
+I’m including a 1-step lookahead, to avoid true recursion and too much burden, but it does help fit bigger stickers.
+
+I’m going to include a variable for this that we can actually change to get deeper, but for now it’s staying at 0 for demos, then 1 for normal stuff, but if we want to go insane for efficiency over time we can deepen it.
+Basically it’ll try one sticker, check other answers, go back a step and check again in case one of those is a more accurate fit.
+
+
diff --git a/algorithm/app/geometry/__init__.py b/algorithm/app/geometry/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/algorithm/app/geometry/placement.py b/algorithm/app/geometry/placement.py
new file mode 100644
index 0000000..70bdf5f
--- /dev/null
+++ b/algorithm/app/geometry/placement.py
@@ -0,0 +1,27 @@
+from shapely.affinity import rotate, translate
+
+def place_sticker(geometry, x, y, rotation_degrees=0):
+ """Rotate a sticker and place its bounding box at (x,y)"""
+ placed = rotate(
+ geometry,
+ rotation_degrees,
+ origin="centroid",
+ )
+
+ min_x, min_y, _, _ = placed.bounds
+
+ return translate(
+ placed,
+ xoff=x - min_x,
+ yoff = y- min_y,
+ )
+
+def stickers_overlap(first,second):
+ """Return whether two stickers overlap in their interiors"""
+ return first.intersection(second).area >0
+
+# page logic
+def fits_on_page(sticker,page):
+ """Return whether the entire sticker lies inside the page"""
+ return page.covers(sticker)
+
diff --git a/algorithm/app/hpgl/__init__.py b/algorithm/app/hpgl/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/algorithm/app/hpgl/output.py b/algorithm/app/hpgl/output.py
new file mode 100644
index 0000000..aaf040a
--- /dev/null
+++ b/algorithm/app/hpgl/output.py
@@ -0,0 +1,54 @@
+from pathlib import Path
+
+def save_hpgl(
+ placements,
+ output,
+ units_per_unit=1,
+ offset=(0,0),
+):
+ """Export sticker polygons as HPGL paths"""
+ output = Path(output)
+
+ offset_x, offset_y = offset
+ commands = [
+ "IN;",
+ "PA;",
+ "SP1;",
+ ]
+
+ def plot_point(x,y):
+ plot_x = round((x + offset_x) * units_per_unit)
+ plot_y = round((y+offset_y) * units_per_unit)
+ return plot_x, plot_y
+
+ for _, geometry in placements:
+ if geometry.geom_type != "Polygon":
+ raise ValueError(
+ "Each sticker must be a single Polygon"
+ )
+
+ coordinates = list(geometry.exterior.coords)
+ if len(coordinates) < 4:
+ raise ValueError(
+ "Sticker outline must contain at least three points"
+ )
+
+ points = [plot_point(x,y) for x,y in coordinates]
+
+ # go to starting point with pen raised
+ start_x, start_y = points[0]
+ commands.append(f"PU{start_x},{start_y};")
+
+ #lower pen
+ remaining_points = points[1:-1]
+ coordinate_data = ",".join(
+ f"{x},{y}" for x,y in remaining_points
+ )
+
+ commands.append(f"PD{coordinate_data};")
+ commands.append("PU;")
+
+ commands.append("SP0;")
+
+ output.parent.mkdir(parents=True,exist_ok=True)
+ output.write_text("\n".join(commands), encoding="ascii")
diff --git a/algorithm/app/models/__init__.py b/algorithm/app/models/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/algorithm/app/models/sticker.py b/algorithm/app/models/sticker.py
new file mode 100644
index 0000000..cf8ad70
--- /dev/null
+++ b/algorithm/app/models/sticker.py
@@ -0,0 +1,14 @@
+from dataclasses import dataclass,field
+# from shapely.geometry import Polygon
+
+@dataclass
+class Sticker:
+ """Catalog metadata and file refs for one sticker."""
+ id:str
+ name:str
+ size:float
+ description:str
+ tags:list[str] = field(default_factory=list)
+ category:str=""
+ hpgl_path:str=""
+ svg_path:str=""
\ No newline at end of file
diff --git a/algorithm/app/packing/__init__.py b/algorithm/app/packing/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/algorithm/app/packing/greedy.py b/algorithm/app/packing/greedy.py
new file mode 100644
index 0000000..561730c
--- /dev/null
+++ b/algorithm/app/packing/greedy.py
@@ -0,0 +1,59 @@
+from app.geometry.placement import (
+ fits_on_page,
+ place_sticker,
+ stickers_overlap,
+)
+
+def pack_stickers(stickers,page):
+ """Place stickers at the first valid position (super greedy)"""
+ placements = []
+ min_x,min_y,max_x,max_y = page.bounds
+
+ # use smallest sticker dimension
+ dimensions = [
+ min(sticker.bounds[2] - sticker.bounds[0],
+ sticker.bounds[3] - sticker.bounds[1])
+ for sticker in stickers
+ if not sticker.is_empty
+ ]
+
+ if not dimensions:
+ return placements
+
+ step = min(dimensions)
+ if step <= 0:
+ return placements
+
+ remaining = sorted(
+ stickers,
+ key=lambda s: (
+ (s.bounds[2]-s.bounds[0])
+ * (s.bounds[3] - s.bounds[1])
+ ),
+ reverse= True
+ )
+
+ y = min_y
+ while y < max_y:
+ x = min_x
+ while x < max_x:
+ for sticker in stickers:
+ if any(original is sticker for original, _ in placements):
+ continue
+
+ placed = place_sticker(sticker, x, y)
+
+ if not fits_on_page(placed,page):
+ continue
+
+ if any(
+ stickers_overlap(placed,existing)
+ for _, existing in placements
+ ):
+ continue
+
+ placements.append((sticker, placed))
+
+ x+= step
+ y += step
+ return placements
\ No newline at end of file
diff --git a/algorithm/app/packing/semi_greedy.py b/algorithm/app/packing/semi_greedy.py
new file mode 100644
index 0000000..da4fa78
--- /dev/null
+++ b/algorithm/app/packing/semi_greedy.py
@@ -0,0 +1,64 @@
+from app.packing.greedy import pack_stickers
+import random
+
+from app.geometry.placement import (
+ fits_on_page,
+ place_sticker,
+ stickers_overlap,
+)
+
+
+def pack_stickers_semi_greedy(stickers, page, seed=None):
+ """Pack stickers by randomly choosing among the best candidates, including rotation"""
+ rng = random.Random(seed)
+
+ remaining = sorted(
+ stickers,
+ key=lambda s: (
+ (s.bounds[2] - s.bounds[0])
+ * (s.bounds[3] - s.bounds[1])
+ ),
+ reverse=True,
+ )
+
+ min_x, min_y, _,_ = page.bounds
+ placements = []
+
+ for sticker in remaining:
+ positions = {(min_x,min_y)}
+
+ for _, placed in placements:
+ left, bottom, right, top = placed.bounds
+ positions.add((right, bottom))
+ positions.add((left,top))
+
+ candidates = []
+
+ for x, y in positions:
+ for angle in (0,90,180,270):
+ candidate = place_sticker(
+ sticker,
+ x,
+ y,
+ rotation_degrees=angle,
+ )
+
+ if not fits_on_page(candidate,page):
+ continue
+ if any(
+ stickers_overlap(candidate, existing)
+ for _, existing in placements
+ ):
+ continue
+
+ _, bottom, right, top = candidate.bounds
+ score = (top,right,bottom, x,y, angle)
+ candidates.append((score, candidate))
+ if candidates:
+ candidates.sort(key=lambda item: item[0])
+
+ #choose randomly from 3 (variable) best valid candidates
+ shortlist = candidates[:3]
+ _, chosen = rng.choice(shortlist)
+ placements.append((sticker,chosen))
+ return placements
\ No newline at end of file
diff --git a/algorithm/app/svg/__init__.py b/algorithm/app/svg/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/algorithm/app/svg/loader.py b/algorithm/app/svg/loader.py
new file mode 100644
index 0000000..8c99ce7
--- /dev/null
+++ b/algorithm/app/svg/loader.py
@@ -0,0 +1,175 @@
+from pathlib import Path
+import re
+import xml.etree.ElementTree as ET
+
+from shapely.geometry import Polygon
+from shapely.ops import unary_union
+from svgpathtools import parse_path
+
+def _local_tag(element):
+ """Return an SVG element's tag without the XML namespace, for testing/parsing."""
+ return element.tag.rsplit("}",1)[-1]
+
+def _split_subpaths(path_data):
+ """Split SVG path data at moveto commands into seperate subpaths."""
+ # An uppercase or lowercase M starts a subpath
+ # exponents can't be mistaken as commands
+ starts = [
+ match.start()
+ for match in re.finditer(r"[Mm]", path_data)
+ ]
+
+ if not starts:
+ return []
+
+ starts.append(len(path_data))
+
+ return [
+ path_data[starts[i]:starts[i+1]].strip()
+ for i in range(len(starts) - 1)
+ if path_data[starts[i]:starts[i+1]].strip()
+ ]
+
+def _sample_closed_path(path_data, samples_per_curve=12):
+ """Convert one closed psubpath into polygon coordinates"""
+ path = parse_path(path_data)
+
+ if len(path) == 0:
+ return None
+
+ #check continuity
+ if not path.iscontinuous() or not path.isclosed():
+ return None
+
+ points = []
+
+ for segment in path:
+ if not points:
+ points.append(
+ (segment.start.real, segment.start.imag)
+ )
+
+ for i in range(1, samples_per_curve+1):
+ point = segment.point(i/samples_per_curve)
+ points.append((point.real, point.imag))
+
+ if len(points) < 4:
+ return None
+
+ polygon = Polygon(points)
+
+ if polygon.is_empty or not polygon.is_valid or polygon.area <= 0:
+ return None
+
+ return polygon
+
+
+
+def _parse_points(points_text):
+ """Parse the points attribute of an SVG polygon or line."""
+ import re
+ values = re.findall(
+ r"[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][]?\d+)?",
+ points_text,
+ )
+
+ if len(values) < 6 or len(values) % 2:
+ return []
+
+ numbers = [float(value) for value in values]
+ return list(zip(numbers[::2], numbers[1::2]))
+
+def _read_polygons(root):
+ """Extract closed polygon geometry from supported SVG elements."""
+ polygons = []
+ for element in root.iter():
+ tag = _local_tag(element)
+
+ if tag == "path":
+ path_data = element.get("d","").strip()
+
+ for subpath_data in _split_subpaths(path_data):
+ try:
+ polygon = _sample_closed_path(subpath_data)
+ except (ValueError, AssertionError, ZeroDivisionError):
+ polygon = None
+
+ if polygon is not None:
+ polygons.append(polygon)
+
+ elif tag in {"polygon", "polyline"}:
+ points = _parse_points(element.get("points", ""))
+
+ if tag == "polyline" and points and points[0] != points[-1]:
+ continue
+
+ if len(points) >= 3:
+ polygon = Polygon(points)
+
+ if polygon.is_valid and polygon.area > 0:
+ polygons.append(polygon)
+
+ return polygons
+
+def load_sticker_svg(
+ path: str | Path,
+ *,
+ merge_tolerance: float = 0.0,
+):
+ """Load one sticker SVG and return its exterior silhouette.
+
+ Args:
+ path: SVG file path.
+ merge_tolerance: Maximum geometric closing distance, in SVG units.
+ Zero merges touching shapes but does not bridge gaps.
+
+ Returns:
+ A Shapely Polygon representing the sticker's outside outline.
+
+ Raises:
+ FileNotFoundError: If the file does not exist.
+ ValueError: If no usable single sticker outline can be extracted.
+ """
+ path = Path(path)
+
+ if not path.is_file():
+ raise FileNotFoundError(path)
+
+ if merge_tolerance < 0:
+ raise ValueError("merge_tolerance cannot be negative")
+
+ try:
+ root = ET.parse(path).getroot()
+ except ET.ParseError as exc:
+ raise ValueError(f"Invalid SVG file: {path}") from exc
+
+ polygons = _read_polygons(root)
+
+ if not polygons:
+ raise ValueError("no usable sticker geometry")
+
+ geometry = unary_union(polygons)
+
+ # Close small gaps, then restore the original overall scale as much
+ # as possible. This is a geometric closing operation.
+ if merge_tolerance > 0:
+ geometry = (
+ geometry.buffer(merge_tolerance)
+ .buffer(-merge_tolerance)
+ )
+
+ # The cutter needs one continuous exterior outline.
+ if geometry.geom_type == "MultiPolygon":
+ raise ValueError(
+ "Sticker geometry contains disconnected components. "
+ "Increase merge_tolerance only if the gaps are unintended."
+ )
+
+ if geometry.geom_type != "Polygon" or geometry.is_empty:
+ raise ValueError("no usable sticker geometry")
+
+ if not geometry.is_valid or geometry.area <= 0:
+ raise ValueError("no usable sticker geometry")
+
+ # Return only the exterior silhouette, discarding interior rings.
+ return Polygon(geometry.exterior)
diff --git a/algorithm/app/visualization/__init__.py b/algorithm/app/visualization/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/algorithm/app/visualization/preview.py b/algorithm/app/visualization/preview.py
new file mode 100644
index 0000000..a873dad
--- /dev/null
+++ b/algorithm/app/visualization/preview.py
@@ -0,0 +1,87 @@
+from pathlib import Path
+from shapely.geometry import Polygon, MultiPolygon, GeometryCollection
+
+def _polygons(geometry):
+ """polygon componenets from shapely geometry"""
+
+ if isinstance(geometry,Polygon):
+ yield geometry
+ elif isinstance(geometry, (MultiPolygon,GeometryCollection)):
+ for part in geometry.geoms:
+ yield from _polygons(part)
+
+
+def save_packing_preview(page,placements,output):
+ """Save an svg preview of a page and its placed sticker outlines."""
+
+ output = Path(output)
+
+ min_x, min_y, max_x, max_y = page.bounds
+ page_width = max_x - min_x
+ page_height = max_y - min_y
+
+ if page_width <= 0 or page_height <= 0:
+ raise ValueError("Page must have positive width and height")
+
+ padding= 20
+ max_size = 800
+ scale = min(
+ max_size / page_width,
+ max_size/page_height,
+ )
+
+ width = page_width * scale + 2* padding
+ height = page_height * scale + 2 * padding
+
+ def point(x,y):
+ screen_x = padding + (x- min_x) * scale
+ screen_y = padding + (max_y -y) * scale
+ return screen_x, screen_y
+
+ def ring_path(ring):
+ coords = list(ring.coords)
+ if not coords:
+ return ""
+
+ x,y = point(*coords[0])
+ commands = [f"M {x:.3f} {y:.3f}"]
+
+ for coord in coords[1:]:
+ x, y = point(*coord)
+ commands.append(f"L {x:.3f} {y:.3f}")
+
+ commands.append("Z")
+ return " ".join(commands)
+
+ output_lines = [
+ f'")
+
+ output.parent.mkdir(parents=True, exist_ok=True)
+ output.write_text(
+ "\n".join(output_lines)
+ )
\ No newline at end of file
diff --git a/algorithm/pyproject.toml b/algorithm/pyproject.toml
new file mode 100644
index 0000000..e93ae3c
--- /dev/null
+++ b/algorithm/pyproject.toml
@@ -0,0 +1,26 @@
+[build-system]
+requires = ["setuptools>=75"]
+build-backed = "setuptools.build_meta"
+
+[project]
+name = "sticker-packer"
+version = "0.1.0"
+description = "Test-driven geometry and HPGL tools for packing sticker outlines"
+requires-python = ">=3.11"
+dependencies = [
+ "shapely>=2.0, <3.0",
+ "svgpathtools>=1.6,<2.0",
+]
+
+[project.optional-dependencies]
+test = [
+ "pytest>=8.0,<9.0",
+]
+
+[tool.pytest.ini_options]
+testpaths = ["test"]
+pythonpath = ["."]
+addopts = "-ra"
+
+[tool.setuptools.packages.find]
+include = ["app*"]
\ No newline at end of file
diff --git a/algorithm/testrun.py b/algorithm/testrun.py
new file mode 100644
index 0000000..7eecb3c
--- /dev/null
+++ b/algorithm/testrun.py
@@ -0,0 +1,28 @@
+from shapely.geometry import box
+from app.packing.greedy import pack_stickers
+from app.packing.semi_greedy import pack_stickers_semi_greedy
+from app.visualization.preview import save_packing_preview
+
+page = box(0, 0, 300, 300)
+
+stickers = [
+ box(0, 0, 20, 10),
+ box(0, 0, 15, 15),
+ box(0, 0, 10, 25),
+]
+
+placements = pack_stickers_semi_greedy(stickers, page, seed=42)
+
+save_packing_preview(
+ page,
+ placements,
+ "output/packing_preview_semi_greedy.svg",
+)
+
+placements = pack_stickers(stickers, page)
+
+save_packing_preview(
+ page,
+ placements,
+ "output/packing_preview_greedy.svg",
+)
\ No newline at end of file
diff --git a/algorithm/tests/fixtures/tetrispieceI.hpgl b/algorithm/tests/fixtures/tetrispieceI.hpgl
new file mode 100644
index 0000000..44edcdc
--- /dev/null
+++ b/algorithm/tests/fixtures/tetrispieceI.hpgl
@@ -0,0 +1,78 @@
+%-12345X@PJL SET RESOLUTION = 300
+@PJL SET ORIENTATION = LANDSCAPE
+@PJL ENTER LANGUAGE = HPGL2
+%1B
+BP5,1;IN;SP1;IW;PS9600,7100;TR0;IP0,0,7100,9600;SC;
+PC1,82,229,250;
+PU51928,206583;
+PM0;
+PU51928,206583;
+PD51928,204548,51928,202513,51928,200479,51928,198444,51928,196410,51928,194375,51928,192341,51928,190306,51928,188272,51928,186237,51928,184203,51928,182168,51928,180134,51928,178099,51928,176065,51928,174030,51928,171995,51928,169961,51928,167926,51928,165892,51928,163857,51928,161823,51928,159788,51928,157754,49889,157754,47851,157754,45813,157754,43775,157754,41737,157754,39699,157754,37661,157754,35624,157754,33586,157754,31548,157754,29510,157754,27473,157754,25435,157754,23397,157754,21359,157754,19322,157754,17284,157754,15246,157754,13208,157754,11170,157754,9132,157754,7094,157754,5056,157754,3018,157754,3018,159788,3018,161823,3018,163857,3018,165892,3018,167926,3018,169961,3018,171995,3018,174030,3018,176065,3018,178099,3018,180134,3018,182168,3018,184203,3018,186237,3018,188272,3018,190306,3018,192341,3018,194375,3018,196410,3018,198444,3018,200479,3018,202513,3018,204548,3018,206583,5056,206583,7094,206583,9132,206583,11170,206583,13208,206583,15246,206583,17284,206583,19322,206583,21359,206583,23397,206583,25435,206583,27473,206583,29510,206583,31548,206583,33586,206583,35624,206583,37661,206583,39699,206583,41737,206583,43775,206583,45813,206583,47851,206583,49889,206583,51928,206583;
+PU;PM1;
+PU51928,155224;
+PD51928,153191,51928,151157,51928,149124,51928,147091,51928,145058,51928,143024,51928,140991,51928,138958,51928,136925,51928,134891,51928,132858,51928,130825,51928,128791,51928,126758,51928,124725,51928,122692,51928,120658,51928,118625,51928,116592,51928,114559,51928,112525,51928,110492,51928,108459,51928,106426,49889,106426,47851,106426,45813,106426,43774,106426,41736,106426,39698,106426,37659,106426,35621,106426,33583,106426,31544,106426,29506,106426,27468,106426,25429,106426,23391,106426,21352,106426,19314,106426,17276,106426,15237,106426,13199,106426,11161,106426,9122,106426,7084,106426,5046,106426,3007,106426,3007,108459,3007,110492,3007,112525,3007,114559,3007,116592,3007,118625,3007,120658,3007,122692,3007,124725,3007,126758,3007,128791,3007,130825,3007,132858,3007,134891,3007,136925,3007,138958,3007,140991,3007,143024,3007,145058,3007,147091,3007,149124,3007,151157,3007,153191,3007,155224,5046,155224,7084,155224,9122,155224,11161,155224,13199,155224,15237,155224,17276,155224,19314,155224,21352,155224,23391,155224,25429,155224,27468,155224,29506,155224,31544,155224,33583,155224,35621,155224,37659,155224,39698,155224,41736,155224,43774,155224,45813,155224,47851,155224,49889,155224,51928,155224;
+PU;PM1;
+PU51938,103378;
+PD51938,101355,51938,99331,51938,97308,51938,95285,51938,93262,51938,91239,51938,89216,51938,87193,51938,85170,51938,83147,51938,81123,51938,79100,51938,77077,51938,75054,51938,73031,51938,71008,51938,68985,51938,66962,51938,64939,51938,62916,51938,60892,51938,58869,51938,56846,51938,54823,49898,54823,47859,54823,45819,54823,43780,54823,41741,54823,39702,54823,37663,54823,35624,54823,33585,54823,31546,54823,29507,54823,27469,54823,25430,54823,23392,54823,21353,54823,19315,54823,17276,54823,15238,54823,13199,54823,11161,54823,9122,54823,7084,54823,5046,54823,3007,54823,3007,56832,3007,58841,3007,60851,3007,62860,3007,64869,3007,66878,3007,68887,3007,70896,3007,72905,3007,74914,3007,76924,3007,78933,3007,80942,3007,82951,3007,84960,3007,86969,3007,88978,3007,90988,3007,92997,3007,95006,3007,97015,3007,99024,3007,101033,3007,103042,3322,103280,3679,103485,4073,103660,4502,103807,4961,103927,5448,104023,5959,104097,6491,104151,7040,104186,7602,104205,8175,104209,8755,104201,9339,104182,9922,104154,10503,104120,11076,104081,11639,104039,12188,103997,12721,103955,13233,103917,13721,103884,14181,103858,14611,103841,15006,103835,16051,103835,17097,103835,18141,103835,19186,103835,20231,103835,21276,103835,22320,103835,23365,103835,24409,103835,25454,103835,26498,103835,27542,103835,28587,103835,29631,103835,30675,103835,31719,103835,32763,103835,33807,103835,34851,103835,35895,103835,36939,103835,37983,103835,39027,103835,40071,103835,40533,103839,41005,103850,41487,103867,41978,103888,42476,103913,42981,103941,43491,103969,44006,103996,44523,104022,45043,104046,45564,104065,46084,104079,46604,104086,47122,104085,47636,104076,48146,104056,48650,104025,49148,103981,49638,103922,50120,103849,50592,103759,51053,103651,51502,103525,51938,103378;
+PU;PM1;
+PU51928,52395;
+PD51928,50350,51928,48306,51928,46261,51928,44217,51928,42173,51928,40128,51928,38084,51928,36040,51928,33996,51928,31952,51928,29908,51928,27864,51928,25820,51928,23776,51928,21731,51928,19687,51928,17643,51928,15599,51928,13555,51928,11510,51928,9466,51928,7422,51928,5377,51928,3332,49889,3332,47851,3332,45813,3332,43775,3332,41737,3332,39699,3332,37661,3332,35624,3332,33586,3332,31548,3332,29510,3332,27473,3332,25435,3332,23397,3332,21359,3332,19322,3332,17284,3332,15246,3332,13208,3332,11170,3332,9132,3332,7094,3332,5056,3332,3018,3332,3018,5377,3018,7422,3018,9466,3018,11510,3018,13555,3018,15599,3018,17643,3018,19687,3018,21731,3018,23776,3018,25820,3018,27864,3018,29908,3018,31952,3018,33996,3018,36040,3018,38084,3018,40128,3018,42173,3018,44217,3018,46261,3018,48306,3018,50350,3018,52395,5056,52395,7094,52395,9132,52395,11170,52395,13208,52395,15246,52395,17284,52395,19322,52395,21359,52395,23397,52395,25435,52395,27473,52395,29510,52395,31548,52395,33586,52395,35624,52395,37661,52395,39699,52395,41737,52395,43775,52395,45813,52395,47851,52395,49889,52395,51928,52395;
+PU;PM1;
+PM2;FP;
+IW;
+PU51928,206583;
+PD51928,204548,51928,202513,51928,200479,51928,198444,51928,196410,51928,194375,51928,192341,51928,190306,51928,188272,51928,186237,51928,184203,51928,182168,51928,180134,51928,178099,51928,176065,51928,174030,51928,171995,51928,169961,51928,167926,51928,165892,51928,163857,51928,161823,51928,159788,51928,157754,49889,157754,47851,157754,45813,157754,43775,157754,41737,157754,39699,157754,37661,157754,35624,157754,33586,157754,31548,157754,29510,157754,27473,157754,25435,157754,23397,157754,21359,157754,19322,157754,17284,157754,15246,157754,13208,157754,11170,157754,9132,157754,7094,157754,5056,157754,3018,157754,3018,159788,3018,161823,3018,163857,3018,165892,3018,167926,3018,169961,3018,171995,3018,174030,3018,176065,3018,178099,3018,180134,3018,182168,3018,184203,3018,186237,3018,188272,3018,190306,3018,192341,3018,194375,3018,196410,3018,198444,3018,200479,3018,202513,3018,204548,3018,206583,5056,206583,7094,206583,9132,206583,11170,206583,13208,206583,15246,206583,17284,206583,19322,206583,21359,206583,23397,206583,25435,206583,27473,206583,29510,206583,31548,206583,33586,206583,35624,206583,37661,206583,39699,206583,41737,206583,43775,206583,45813,206583,47851,206583,49889,206583,51928,206583,51928,206583;
+PU51928,155224;
+PD51928,153191,51928,151157,51928,149124,51928,147091,51928,145058,51928,143024,51928,140991,51928,138958,51928,136925,51928,134891,51928,132858,51928,130825,51928,128791,51928,126758,51928,124725,51928,122692,51928,120658,51928,118625,51928,116592,51928,114559,51928,112525,51928,110492,51928,108459,51928,106426,49889,106426,47851,106426,45813,106426,43774,106426,41736,106426,39698,106426,37659,106426,35621,106426,33583,106426,31544,106426,29506,106426,27468,106426,25429,106426,23391,106426,21352,106426,19314,106426,17276,106426,15237,106426,13199,106426,11161,106426,9122,106426,7084,106426,5046,106426,3007,106426,3007,108459,3007,110492,3007,112525,3007,114559,3007,116592,3007,118625,3007,120658,3007,122692,3007,124725,3007,126758,3007,128791,3007,130825,3007,132858,3007,134891,3007,136925,3007,138958,3007,140991,3007,143024,3007,145058,3007,147091,3007,149124,3007,151157,3007,153191,3007,155224,5046,155224,7084,155224,9122,155224,11161,155224,13199,155224,15237,155224,17276,155224,19314,155224,21352,155224,23391,155224,25429,155224,27468,155224,29506,155224,31544,155224,33583,155224,35621,155224,37659,155224,39698,155224,41736,155224,43774,155224,45813,155224,47851,155224,49889,155224,51928,155224,51928,155224;
+PU51938,103378;
+PD51938,101355,51938,99331,51938,97308,51938,95285,51938,93262,51938,91239,51938,89216,51938,87193,51938,85170,51938,83147,51938,81123,51938,79100,51938,77077,51938,75054,51938,73031,51938,71008,51938,68985,51938,66962,51938,64939,51938,62916,51938,60892,51938,58869,51938,56846,51938,54823,49898,54823,47859,54823,45819,54823,43780,54823,41741,54823,39702,54823,37663,54823,35624,54823,33585,54823,31546,54823,29507,54823,27469,54823,25430,54823,23392,54823,21353,54823,19315,54823,17276,54823,15238,54823,13199,54823,11161,54823,9122,54823,7084,54823,5046,54823,3007,54823,3007,56832,3007,58841,3007,60851,3007,62860,3007,64869,3007,66878,3007,68887,3007,70896,3007,72905,3007,74914,3007,76924,3007,78933,3007,80942,3007,82951,3007,84960,3007,86969,3007,88978,3007,90988,3007,92997,3007,95006,3007,97015,3007,99024,3007,101033,3007,103042,3322,103280,3679,103485,4073,103660,4502,103807,4961,103927,5448,104023,5959,104097,6491,104151,7040,104186,7602,104205,8175,104209,8755,104201,9339,104182,9922,104154,10503,104120,11076,104081,11639,104039,12188,103997,12721,103955,13233,103917,13721,103884,14181,103858,14611,103841,15006,103835,16051,103835,17097,103835,18141,103835,19186,103835,20231,103835,21276,103835,22320,103835,23365,103835,24409,103835,25454,103835,26498,103835,27542,103835,28587,103835,29631,103835,30675,103835,31719,103835,32763,103835,33807,103835,34851,103835,35895,103835,36939,103835,37983,103835,39027,103835,40071,103835,40533,103839,41005,103850,41487,103867,41978,103888,42476,103913,42981,103941,43491,103969,44006,103996,44523,104022,45043,104046,45564,104065,46084,104079,46604,104086,47122,104085,47636,104076,48146,104056,48650,104025,49148,103981,49638,103922,50120,103849,50592,103759,51053,103651,51502,103525,51938,103378,51938,103378;
+PU51928,52395;
+PD51928,50350,51928,48306,51928,46261,51928,44217,51928,42173,51928,40128,51928,38084,51928,36040,51928,33996,51928,31952,51928,29908,51928,27864,51928,25820,51928,23776,51928,21731,51928,19687,51928,17643,51928,15599,51928,13555,51928,11510,51928,9466,51928,7422,51928,5377,51928,3332,49889,3332,47851,3332,45813,3332,43775,3332,41737,3332,39699,3332,37661,3332,35624,3332,33586,3332,31548,3332,29510,3332,27473,3332,25435,3332,23397,3332,21359,3332,19322,3332,17284,3332,15246,3332,13208,3332,11170,3332,9132,3332,7094,3332,5056,3332,3018,3332,3018,5377,3018,7422,3018,9466,3018,11510,3018,13555,3018,15599,3018,17643,3018,19687,3018,21731,3018,23776,3018,25820,3018,27864,3018,29908,3018,31952,3018,33996,3018,36040,3018,38084,3018,40128,3018,42173,3018,44217,3018,46261,3018,48306,3018,50350,3018,52395,5056,52395,7094,52395,9132,52395,11170,52395,13208,52395,15246,52395,17284,52395,19322,52395,21359,52395,23397,52395,25435,52395,27473,52395,29510,52395,31548,52395,33586,52395,35624,52395,37661,52395,39699,52395,41737,52395,43775,52395,45813,52395,47851,52395,49889,52395,51928,52395,51928,52395;
+PC1,2,5,6;
+PU996,209153;
+PM0;
+PU996,209153;
+PD3193,209153,5390,209153,7587,209153,9783,209152,11980,209152,14177,209151,16373,209151,18569,209150,20766,209149,22962,209148,25158,209148,27354,209147,29551,209146,31747,209145,33943,209144,36139,209142,38335,209141,40531,209140,42726,209139,44922,209138,47118,209136,49314,209135,51510,209134,53706,209133,53707,200459,53708,191785,53709,183111,53711,174437,53712,165764,53713,157090,53714,148417,53715,139743,53717,131070,53718,122397,53719,113723,53720,105050,53721,96377,53721,87704,53722,79031,53723,70358,53724,61685,53724,53012,53725,44339,53725,35667,53726,26994,53726,18321,53726,9648,53726,975,51535,988,49344,1001,47153,1013,44962,1026,42771,1039,40580,1052,38388,1064,36197,1077,34006,1090,31814,1102,29622,1115,27431,1128,25239,1140,23047,1153,20855,1166,18664,1179,16472,1191,14280,1204,12088,1217,9896,1229,7704,1242,5512,1255,3320,1267,1128,1280,1123,9942,1118,18603,1112,27264,1107,35926,1102,44587,1097,53248,1092,61910,1087,70571,1082,79232,1076,87894,1071,96555,1066,105217,1060,113878,1055,122539,1049,131201,1043,139862,1038,148523,1032,157185,1026,165846,1020,174508,1014,183169,1008,191830,1002,200492,996,209153;
+PU;PM1;
+PU51928,206583;
+PD49889,206583,47851,206583,45813,206583,43775,206583,41737,206583,39699,206583,37661,206583,35624,206583,33586,206583,31548,206583,29510,206583,27473,206583,25435,206583,23397,206583,21359,206583,19322,206583,17284,206583,15246,206583,13208,206583,11170,206583,9132,206583,7094,206583,5056,206583,3018,206583,3018,204548,3018,202513,3018,200479,3018,198444,3018,196410,3018,194375,3018,192341,3018,190306,3018,188272,3018,186237,3018,184203,3018,182168,3018,180134,3018,178099,3018,176065,3018,174030,3018,171995,3018,169961,3018,167926,3018,165892,3018,163857,3018,161823,3018,159788,3018,157754,5056,157754,7094,157754,9132,157754,11170,157754,13208,157754,15246,157754,17284,157754,19322,157754,21359,157754,23397,157754,25435,157754,27473,157754,29510,157754,31548,157754,33586,157754,35624,157754,37661,157754,39699,157754,41737,157754,43775,157754,45813,157754,47851,157754,49889,157754,51928,157754,51928,159788,51928,161823,51928,163857,51928,165892,51928,167926,51928,169961,51928,171995,51928,174030,51928,176065,51928,178099,51928,180134,51928,182168,51928,184203,51928,186237,51928,188272,51928,190306,51928,192341,51928,194375,51928,196410,51928,198444,51928,200479,51928,202513,51928,204548,51928,206583;
+PU;PM1;
+PU51928,155224;
+PD49889,155224,47851,155224,45813,155224,43774,155224,41736,155224,39698,155224,37659,155224,35621,155224,33583,155224,31544,155224,29506,155224,27468,155224,25429,155224,23391,155224,21352,155224,19314,155224,17276,155224,15237,155224,13199,155224,11161,155224,9122,155224,7084,155224,5046,155224,3007,155224,3007,153191,3007,151157,3007,149124,3007,147091,3007,145058,3007,143024,3007,140991,3007,138958,3007,136925,3007,134891,3007,132858,3007,130825,3007,128791,3007,126758,3007,124725,3007,122692,3007,120658,3007,118625,3007,116592,3007,114559,3007,112525,3007,110492,3007,108459,3007,106426,5046,106426,7084,106426,9122,106426,11161,106426,13199,106426,15237,106426,17276,106426,19314,106426,21352,106426,23391,106426,25429,106426,27468,106426,29506,106426,31544,106426,33583,106426,35621,106426,37659,106426,39698,106426,41736,106426,43774,106426,45813,106426,47851,106426,49889,106426,51928,106426,51928,108459,51928,110492,51928,112525,51928,114559,51928,116592,51928,118625,51928,120658,51928,122692,51928,124725,51928,126758,51928,128791,51928,130825,51928,132858,51928,134891,51928,136925,51928,138958,51928,140991,51928,143024,51928,145058,51928,147091,51928,149124,51928,151157,51928,153191,51928,155224;
+PU;PM1;
+PU51938,103378;
+PD51502,103525,51053,103651,50592,103759,50120,103849,49638,103922,49148,103981,48650,104025,48146,104056,47636,104076,47122,104085,46604,104086,46084,104079,45564,104065,45043,104046,44523,104022,44006,103996,43491,103969,42981,103941,42476,103913,41978,103888,41487,103867,41005,103850,40533,103839,40071,103835,39027,103835,37983,103835,36939,103835,35895,103835,34851,103835,33807,103835,32763,103835,31719,103835,30675,103835,29631,103835,28587,103835,27542,103835,26498,103835,25454,103835,24409,103835,23365,103835,22320,103835,21276,103835,20231,103835,19186,103835,18141,103835,17097,103835,16051,103835,15006,103835,14611,103841,14181,103858,13721,103884,13233,103917,12721,103955,12188,103997,11639,104039,11076,104081,10503,104120,9922,104154,9339,104182,8755,104201,8175,104209,7602,104205,7040,104186,6491,104151,5959,104097,5448,104023,4961,103927,4502,103807,4073,103660,3679,103485,3322,103280,3007,103042,3007,101033,3007,99024,3007,97015,3007,95006,3007,92997,3007,90988,3007,88978,3007,86969,3007,84960,3007,82951,3007,80942,3007,78933,3007,76924,3007,74914,3007,72905,3007,70896,3007,68887,3007,66878,3007,64869,3007,62860,3007,60851,3007,58841,3007,56832,3007,54823,5046,54823,7084,54823,9122,54823,11161,54823,13199,54823,15238,54823,17276,54823,19315,54823,21353,54823,23392,54823,25430,54823,27469,54823,29507,54823,31546,54823,33585,54823,35624,54823,37663,54823,39702,54823,41741,54823,43780,54823,45819,54823,47859,54823,49898,54823,51938,54823,51938,56846,51938,58869,51938,60892,51938,62916,51938,64939,51938,66962,51938,68985,51938,71008,51938,73031,51938,75054,51938,77077,51938,79100,51938,81123,51938,83147,51938,85170,51938,87193,51938,89216,51938,91239,51938,93262,51938,95285,51938,97308,51938,99331,51938,101355,51938,103378;
+PU;PM1;
+PU51928,52395;
+PD49889,52395,47851,52395,45813,52395,43775,52395,41737,52395,39699,52395,37661,52395,35624,52395,33586,52395,31548,52395,29510,52395,27473,52395,25435,52395,23397,52395,21359,52395,19322,52395,17284,52395,15246,52395,13208,52395,11170,52395,9132,52395,7094,52395,5056,52395,3018,52395,3018,50350,3018,48306,3018,46261,3018,44217,3018,42173,3018,40128,3018,38084,3018,36040,3018,33996,3018,31952,3018,29908,3018,27864,3018,25820,3018,23776,3018,21731,3018,19687,3018,17643,3018,15599,3018,13555,3018,11510,3018,9466,3018,7422,3018,5377,3018,3332,5056,3332,7094,3332,9132,3332,11170,3332,13208,3332,15246,3332,17284,3332,19322,3332,21359,3332,23397,3332,25435,3332,27473,3332,29510,3332,31548,3332,33586,3332,35624,3332,37661,3332,39699,3332,41737,3332,43775,3332,45813,3332,47851,3332,49889,3332,51928,3332,51928,5377,51928,7422,51928,9466,51928,11510,51928,13555,51928,15599,51928,17643,51928,19687,51928,21731,51928,23776,51928,25820,51928,27864,51928,29908,51928,31952,51928,33996,51928,36040,51928,38084,51928,40128,51928,42173,51928,44217,51928,46261,51928,48306,51928,50350,51928,52395;
+PU;PM1;
+PM2;FP;
+IW;
+PU996,209153;
+PD3193,209153,5390,209153,7587,209153,9783,209152,11980,209152,14177,209151,16373,209151,18569,209150,20766,209149,22962,209148,25158,209148,27354,209147,29551,209146,31747,209145,33943,209144,36139,209142,38335,209141,40531,209140,42726,209139,44922,209138,47118,209136,49314,209135,51510,209134,53706,209133,53707,200459,53708,191785,53709,183111,53711,174437,53712,165764,53713,157090,53714,148417,53715,139743,53717,131070,53718,122397,53719,113723,53720,105050,53721,96377,53721,87704,53722,79031,53723,70358,53724,61685,53724,53012,53725,44339,53725,35667,53726,26994,53726,18321,53726,9648,53726,975,51535,988,49344,1001,47153,1013,44962,1026,42771,1039,40580,1052,38388,1064,36197,1077,34006,1090,31814,1102,29622,1115,27431,1128,25239,1140,23047,1153,20855,1166,18664,1179,16472,1191,14280,1204,12088,1217,9896,1229,7704,1242,5512,1255,3320,1267,1128,1280,1123,9942,1118,18603,1112,27264,1107,35926,1102,44587,1097,53248,1092,61910,1087,70571,1082,79232,1076,87894,1071,96555,1066,105217,1060,113878,1055,122539,1049,131201,1043,139862,1038,148523,1032,157185,1026,165846,1020,174508,1014,183169,1008,191830,1002,200492,996,209153,996,209153;
+PU51928,206583;
+PD49889,206583,47851,206583,45813,206583,43775,206583,41737,206583,39699,206583,37661,206583,35624,206583,33586,206583,31548,206583,29510,206583,27473,206583,25435,206583,23397,206583,21359,206583,19322,206583,17284,206583,15246,206583,13208,206583,11170,206583,9132,206583,7094,206583,5056,206583,3018,206583,3018,204548,3018,202513,3018,200479,3018,198444,3018,196410,3018,194375,3018,192341,3018,190306,3018,188272,3018,186237,3018,184203,3018,182168,3018,180134,3018,178099,3018,176065,3018,174030,3018,171995,3018,169961,3018,167926,3018,165892,3018,163857,3018,161823,3018,159788,3018,157754,5056,157754,7094,157754,9132,157754,11170,157754,13208,157754,15246,157754,17284,157754,19322,157754,21359,157754,23397,157754,25435,157754,27473,157754,29510,157754,31548,157754,33586,157754,35624,157754,37661,157754,39699,157754,41737,157754,43775,157754,45813,157754,47851,157754,49889,157754,51928,157754,51928,159788,51928,161823,51928,163857,51928,165892,51928,167926,51928,169961,51928,171995,51928,174030,51928,176065,51928,178099,51928,180134,51928,182168,51928,184203,51928,186237,51928,188272,51928,190306,51928,192341,51928,194375,51928,196410,51928,198444,51928,200479,51928,202513,51928,204548,51928,206583,51928,206583;
+PU51928,155224;
+PD49889,155224,47851,155224,45813,155224,43774,155224,41736,155224,39698,155224,37659,155224,35621,155224,33583,155224,31544,155224,29506,155224,27468,155224,25429,155224,23391,155224,21352,155224,19314,155224,17276,155224,15237,155224,13199,155224,11161,155224,9122,155224,7084,155224,5046,155224,3007,155224,3007,153191,3007,151157,3007,149124,3007,147091,3007,145058,3007,143024,3007,140991,3007,138958,3007,136925,3007,134891,3007,132858,3007,130825,3007,128791,3007,126758,3007,124725,3007,122692,3007,120658,3007,118625,3007,116592,3007,114559,3007,112525,3007,110492,3007,108459,3007,106426,5046,106426,7084,106426,9122,106426,11161,106426,13199,106426,15237,106426,17276,106426,19314,106426,21352,106426,23391,106426,25429,106426,27468,106426,29506,106426,31544,106426,33583,106426,35621,106426,37659,106426,39698,106426,41736,106426,43774,106426,45813,106426,47851,106426,49889,106426,51928,106426,51928,108459,51928,110492,51928,112525,51928,114559,51928,116592,51928,118625,51928,120658,51928,122692,51928,124725,51928,126758,51928,128791,51928,130825,51928,132858,51928,134891,51928,136925,51928,138958,51928,140991,51928,143024,51928,145058,51928,147091,51928,149124,51928,151157,51928,153191,51928,155224,51928,155224;
+PU51938,103378;
+PD51502,103525,51053,103651,50592,103759,50120,103849,49638,103922,49148,103981,48650,104025,48146,104056,47636,104076,47122,104085,46604,104086,46084,104079,45564,104065,45043,104046,44523,104022,44006,103996,43491,103969,42981,103941,42476,103913,41978,103888,41487,103867,41005,103850,40533,103839,40071,103835,39027,103835,37983,103835,36939,103835,35895,103835,34851,103835,33807,103835,32763,103835,31719,103835,30675,103835,29631,103835,28587,103835,27542,103835,26498,103835,25454,103835,24409,103835,23365,103835,22320,103835,21276,103835,20231,103835,19186,103835,18141,103835,17097,103835,16051,103835,15006,103835,14611,103841,14181,103858,13721,103884,13233,103917,12721,103955,12188,103997,11639,104039,11076,104081,10503,104120,9922,104154,9339,104182,8755,104201,8175,104209,7602,104205,7040,104186,6491,104151,5959,104097,5448,104023,4961,103927,4502,103807,4073,103660,3679,103485,3322,103280,3007,103042,3007,101033,3007,99024,3007,97015,3007,95006,3007,92997,3007,90988,3007,88978,3007,86969,3007,84960,3007,82951,3007,80942,3007,78933,3007,76924,3007,74914,3007,72905,3007,70896,3007,68887,3007,66878,3007,64869,3007,62860,3007,60851,3007,58841,3007,56832,3007,54823,5046,54823,7084,54823,9122,54823,11161,54823,13199,54823,15238,54823,17276,54823,19315,54823,21353,54823,23392,54823,25430,54823,27469,54823,29507,54823,31546,54823,33585,54823,35624,54823,37663,54823,39702,54823,41741,54823,43780,54823,45819,54823,47859,54823,49898,54823,51938,54823,51938,56846,51938,58869,51938,60892,51938,62916,51938,64939,51938,66962,51938,68985,51938,71008,51938,73031,51938,75054,51938,77077,51938,79100,51938,81123,51938,83147,51938,85170,51938,87193,51938,89216,51938,91239,51938,93262,51938,95285,51938,97308,51938,99331,51938,101355,51938,103378,51938,103378;
+PU51928,52395;
+PD49889,52395,47851,52395,45813,52395,43775,52395,41737,52395,39699,52395,37661,52395,35624,52395,33586,52395,31548,52395,29510,52395,27473,52395,25435,52395,23397,52395,21359,52395,19322,52395,17284,52395,15246,52395,13208,52395,11170,52395,9132,52395,7094,52395,5056,52395,3018,52395,3018,50350,3018,48306,3018,46261,3018,44217,3018,42173,3018,40128,3018,38084,3018,36040,3018,33996,3018,31952,3018,29908,3018,27864,3018,25820,3018,23776,3018,21731,3018,19687,3018,17643,3018,15599,3018,13555,3018,11510,3018,9466,3018,7422,3018,5377,3018,3332,5056,3332,7094,3332,9132,3332,11170,3332,13208,3332,15246,3332,17284,3332,19322,3332,21359,3332,23397,3332,25435,3332,27473,3332,29510,3332,31548,3332,33586,3332,35624,3332,37661,3332,39699,3332,41737,3332,43775,3332,45813,3332,47851,3332,49889,3332,51928,3332,51928,5377,51928,7422,51928,9466,51928,11510,51928,13555,51928,15599,51928,17643,51928,19687,51928,21731,51928,23776,51928,25820,51928,27864,51928,29908,51928,31952,51928,33996,51928,36040,51928,38084,51928,40128,51928,42173,51928,44217,51928,46261,51928,48306,51928,50350,51928,52395,51928,52395;
+PC1,178,178,178;
+PU20,209133;
+PM0;
+PU20,209133;
+PD61,209134,102,209135,142,209136,183,209138,224,209139,264,209140,305,209141,345,209142,386,209144,427,209145,467,209146,508,209147,549,209148,589,209148,630,209149,671,209150,711,209151,752,209151,792,209152,833,209152,874,209153,914,209153,955,209153,996,209153,1002,200492,1008,191830,1014,183169,1020,174508,1026,165846,1032,157185,1038,148523,1043,139862,1049,131201,1055,122539,1060,113878,1066,105217,1071,96555,1076,87894,1082,79232,1087,70571,1092,61910,1097,53248,1102,44587,1107,35926,1112,27264,1118,18603,1123,9942,1128,1280,3320,1267,5512,1255,7704,1242,9896,1229,12088,1217,14280,1204,16472,1191,18664,1179,20855,1166,23047,1153,25239,1140,27431,1128,29622,1115,31814,1102,34006,1090,36197,1077,38388,1064,40580,1052,42771,1039,44962,1026,47153,1013,49344,1001,51535,988,53726,975,53726,959,53726,942,53726,926,53726,909,53726,893,53726,876,53726,860,53726,843,53726,827,53726,810,53726,794,53726,777,53726,761,53726,744,53726,728,53726,711,53726,695,53726,678,53726,662,53726,645,53726,629,53726,612,53726,596,53726,579,52202,531,50676,491,49150,459,47623,433,46096,414,44567,400,43039,392,41510,389,39980,390,38450,394,36920,402,35390,413,33859,425,32329,440,30799,455,29268,472,27738,488,26208,503,24679,518,23150,531,21621,543,20093,551,18565,557,17038,559,16384,553,15711,536,15021,509,14316,476,13597,437,12867,395,12128,351,11381,308,10629,267,9874,231,9116,200,8359,178,7604,165,6854,165,6109,178,5372,207,4646,253,3931,319,3230,406,2545,516,1877,652,1229,815,603,1007,0,1229,0,9892,0,18555,0,27217,1,35880,1,44543,2,53205,2,61868,3,70530,4,79193,5,87856,5,96518,6,105181,7,113844,8,122506,9,131169,11,139832,12,148494,13,157157,14,165819,15,174482,17,183145,18,191807,19,200470,20,209133;
+PM1;PM2;FP;
+IW;
+PU20,209133;
+PD61,209134,102,209135,142,209136,183,209138,224,209139,264,209140,305,209141,345,209142,386,209144,427,209145,467,209146,508,209147,549,209148,589,209148,630,209149,671,209150,711,209151,752,209151,792,209152,833,209152,874,209153,914,209153,955,209153,996,209153,1002,200492,1008,191830,1014,183169,1020,174508,1026,165846,1032,157185,1038,148523,1043,139862,1049,131201,1055,122539,1060,113878,1066,105217,1071,96555,1076,87894,1082,79232,1087,70571,1092,61910,1097,53248,1102,44587,1107,35926,1112,27264,1118,18603,1123,9942,1128,1280,3320,1267,5512,1255,7704,1242,9896,1229,12088,1217,14280,1204,16472,1191,18664,1179,20855,1166,23047,1153,25239,1140,27431,1128,29622,1115,31814,1102,34006,1090,36197,1077,38388,1064,40580,1052,42771,1039,44962,1026,47153,1013,49344,1001,51535,988,53726,975,53726,959,53726,942,53726,926,53726,909,53726,893,53726,876,53726,860,53726,843,53726,827,53726,810,53726,794,53726,777,53726,761,53726,744,53726,728,53726,711,53726,695,53726,678,53726,662,53726,645,53726,629,53726,612,53726,596,53726,579,52202,531,50676,491,49150,459,47623,433,46096,414,44567,400,43039,392,41510,389,39980,390,38450,394,36920,402,35390,413,33859,425,32329,440,30799,455,29268,472,27738,488,26208,503,24679,518,23150,531,21621,543,20093,551,18565,557,17038,559,16384,553,15711,536,15021,509,14316,476,13597,437,12867,395,12128,351,11381,308,10629,267,9874,231,9116,200,8359,178,7604,165,6854,165,6109,178,5372,207,4646,253,3931,319,3230,406,2545,516,1877,652,1229,815,603,1007,0,1229,0,9892,0,18555,0,27217,1,35880,1,44543,2,53205,2,61868,3,70530,4,79193,5,87856,5,96518,6,105181,7,113844,8,122506,9,131169,11,139832,12,148494,13,157157,14,165819,15,174482,17,183145,18,191807,19,200470,20,209133,20,209133;
+PC1,238,238,238;
+PU0,1229;
+PM0;
+PU0,1229;
+PD603,1007,1229,815,1877,652,2545,516,3230,406,3931,319,4646,253,5372,207,6109,178,6854,165,7604,165,8359,178,9116,200,9874,231,10629,267,11381,308,12128,351,12867,395,13597,437,14316,476,15021,509,15711,536,16384,553,17038,559,18565,557,20093,551,21621,543,23150,531,24679,518,26208,503,27738,488,29268,472,30799,455,32329,440,33859,425,35390,413,36920,402,38450,394,39980,390,41510,389,43039,392,44567,400,46096,414,47623,433,49150,459,50676,491,52202,531,53726,579,53726,555,53726,531,53726,507,53725,483,53725,458,53724,434,53724,410,53723,386,53722,362,53721,338,53721,314,53720,290,53719,265,53718,241,53717,217,53715,193,53714,169,53713,145,53712,121,53711,97,53709,72,53708,48,53707,24,53706,0,51469,0,49233,0,46996,0,44759,0,42522,0,40285,0,38048,0,35811,0,33574,0,31337,0,29100,0,26863,0,24626,0,22389,0,20152,0,17915,0,15678,0,13441,0,11204,0,8967,0,6730,0,4493,0,2257,0,20,0,19,51,18,102,17,153,15,204,14,255,13,306,12,358,11,409,9,460,8,512,7,563,6,615,5,666,5,718,4,769,3,820,2,872,2,923,1,974,1,1025,0,1077,0,1128,0,1178,0,1229;
+PM1;PM2;FP;
+IW;
+PU0,1229;
+PD603,1007,1229,815,1877,652,2545,516,3230,406,3931,319,4646,253,5372,207,6109,178,6854,165,7604,165,8359,178,9116,200,9874,231,10629,267,11381,308,12128,351,12867,395,13597,437,14316,476,15021,509,15711,536,16384,553,17038,559,18565,557,20093,551,21621,543,23150,531,24679,518,26208,503,27738,488,29268,472,30799,455,32329,440,33859,425,35390,413,36920,402,38450,394,39980,390,41510,389,43039,392,44567,400,46096,414,47623,433,49150,459,50676,491,52202,531,53726,579,53726,555,53726,531,53726,507,53725,483,53725,458,53724,434,53724,410,53723,386,53722,362,53721,338,53721,314,53720,290,53719,265,53718,241,53717,217,53715,193,53714,169,53713,145,53712,121,53711,97,53709,72,53708,48,53707,24,53706,0,51469,0,49233,0,46996,0,44759,0,42522,0,40285,0,38048,0,35811,0,33574,0,31337,0,29100,0,26863,0,24626,0,22389,0,20152,0,17915,0,15678,0,13441,0,11204,0,8967,0,6730,0,4493,0,2257,0,20,0,19,51,18,102,17,153,15,204,14,255,13,306,12,358,11,409,9,460,8,512,7,563,6,615,5,666,5,718,4,769,3,820,2,872,2,923,1,974,1,1025,0,1077,0,1128,0,1178,0,1229,0,1229;
diff --git a/algorithm/tests/fixtures/tetrispieceI.svg b/algorithm/tests/fixtures/tetrispieceI.svg
new file mode 100644
index 0000000..7b199aa
--- /dev/null
+++ b/algorithm/tests/fixtures/tetrispieceI.svg
@@ -0,0 +1,7 @@
+
+
\ No newline at end of file
diff --git a/algorithm/tests/fixtures/tetrispiecesL.svg b/algorithm/tests/fixtures/tetrispiecesL.svg
new file mode 100644
index 0000000..64be517
--- /dev/null
+++ b/algorithm/tests/fixtures/tetrispiecesL.svg
@@ -0,0 +1,6 @@
+
+
\ No newline at end of file
diff --git a/algorithm/tests/fixtures/tetrispiecesS.svg b/algorithm/tests/fixtures/tetrispiecesS.svg
new file mode 100644
index 0000000..69058a4
--- /dev/null
+++ b/algorithm/tests/fixtures/tetrispiecesS.svg
@@ -0,0 +1,6 @@
+
+
\ No newline at end of file
diff --git a/algorithm/tests/fixtures/tetrispiecesT.svg b/algorithm/tests/fixtures/tetrispiecesT.svg
new file mode 100644
index 0000000..cb7248e
--- /dev/null
+++ b/algorithm/tests/fixtures/tetrispiecesT.svg
@@ -0,0 +1,6 @@
+
+
\ No newline at end of file
diff --git a/algorithm/tests/fixtures/tetrispiecesquare.svg b/algorithm/tests/fixtures/tetrispiecesquare.svg
new file mode 100644
index 0000000..779fa68
--- /dev/null
+++ b/algorithm/tests/fixtures/tetrispiecesquare.svg
@@ -0,0 +1,6 @@
+
+
\ No newline at end of file
diff --git a/algorithm/tests/fixtures/tetrispiecesrevL.svg b/algorithm/tests/fixtures/tetrispiecesrevL.svg
new file mode 100644
index 0000000..418bc3c
--- /dev/null
+++ b/algorithm/tests/fixtures/tetrispiecesrevL.svg
@@ -0,0 +1,6 @@
+
+
\ No newline at end of file
diff --git a/algorithm/tests/test_hpgl_output.py b/algorithm/tests/test_hpgl_output.py
new file mode 100644
index 0000000..8f37b26
--- /dev/null
+++ b/algorithm/tests/test_hpgl_output.py
@@ -0,0 +1,69 @@
+from shapely.geometry import box
+from app.hpgl.output import save_hpgl
+
+def test_writes_a_closed_sticker_outline(tmp_path):
+ sticker = box(0,0,10,5)
+ output = "../output/test.plt"
+
+ save_hpgl(
+ [(sticker,sticker)],
+ output,
+ units_per_unit=1,
+ )
+
+ content = output.read_text()
+
+ assert "IN;" in content
+ assert "PA;" in content
+ assert "SP1;" in content
+ assert "PU10,0;" in content
+ assert "PD10,5,0,5,0,0;" in content
+ assert "PU;" in content
+ assert "SP0;" in content
+
+def test_scales_coordinates(tmp_path):
+ sticker = box(0,0,10,5)
+ output = tmp_path / "scaled.plt"
+
+ save_hpgl(
+ [(sticker,sticker)],
+ output,
+ units_per_unit = 10,
+ )
+
+ content = output.read_text()
+
+ assert "PU100,0;" in content
+ assert "PD100,50,0,50,0,0;" in content
+
+def test_applies_coordinate_offset(tmp_path):
+ sticker = box(0,0,10,5)
+ output = tmp_path / "offset.plt"
+
+ save_hpgl(
+ [(sticker,sticker)],
+ output,
+ units_per_unit = 1,
+ offset = (20,30),
+ )
+
+ content = output.read_text()
+
+ assert "PU30,30;" in content
+ assert "PD30,35,20,35,20,30;" in content
+
+def test_lifts_pen_between_stickers(tmp_path):
+ first = box(0, 0, 10, 10)
+ second = box(20, 0, 30, 10)
+ output = tmp_path / "multiple.plt"
+
+ save_hpgl(
+ [(first, first), (second, second)],
+ output,
+ units_per_unit=1,
+ )
+
+ content = output.read_text()
+
+ assert content.count("PU;") == 2
+ assert content.count("PD") == 2
\ No newline at end of file
diff --git a/algorithm/tests/test_packing.py b/algorithm/tests/test_packing.py
new file mode 100644
index 0000000..913e1af
--- /dev/null
+++ b/algorithm/tests/test_packing.py
@@ -0,0 +1,84 @@
+import pytest
+from shapely.geometry import box
+from app.packing.greedy import pack_stickers
+
+from app.packing.semi_greedy import pack_stickers_semi_greedy
+
+def test_packs_two_stickers_without_overlap():
+ stickers = [
+ box(0,0,10,10),
+ box(0,0,10,10),
+ ]
+ page = box(0,0,20,10)
+
+ placements = pack_stickers(stickers,page)
+
+ assert len(placements) == 2
+
+ first = placements[0][1]
+ second = placements[1][1]
+
+ assert page.covers(first)
+ assert page.covers(second)
+ assert first.intersection(second).area == pytest.approx(0)
+
+def test_skips_sticker_that_cannot_fit():
+ stickers = [
+ box(0,0,20,20),
+ ]
+ page = box(0,0,10,10)
+ placements = pack_stickers(stickers,page)
+ assert placements == []
+
+def test_returns_original_and_placed_geometry():
+ sticker = box(0,0,5,5)
+ page = box(0,0,10,10)
+ placements = pack_stickers([sticker],page)
+
+ assert len(placements) == 1
+
+ original, placed = placements[0]
+
+ assert original is sticker
+ assert placed.area == pytest.approx(sticker.area)
+ assert page.covers(placed)
+
+def test_empty_input_returns_no_placements():
+ page = box(0,0,100,100)
+ assert pack_stickers([],page) == []
+
+
+#post-greedy development tests
+def test_rotates_sticker_when_needed():
+ sticker = box(0,0,10,5)
+ page = box(0,0,5,10)
+
+ placements = pack_stickers_semi_greedy([sticker],page)
+
+ assert len(placements)==1
+ assert page.covers(placements[0][1])
+
+def test_places_large_sticker_before_small_sticker():
+ small = box(0,0,2,2)
+ large = box(0,0,8,8)
+ page = box(0,0,10,10)
+
+ placements = pack_stickers_semi_greedy([small,large], page)
+
+ #both should fit, but the large sticker should be placed first at [0][0]
+ assert len(placements) == 2
+ assert placements[0][0] is large
+
+#purely semi greedy tests
+
+def test_semi_greedy_packs_a_sticker():
+ sticker = box(0,0,5,5)
+ page = box(0,0,10,10)
+
+ placements = pack_stickers_semi_greedy(
+ [sticker], page, seed=42
+ )
+
+ assert len(placements) == 1
+ assert page.covers(placements[0][1])
+
diff --git a/algorithm/tests/test_placement.py b/algorithm/tests/test_placement.py
new file mode 100644
index 0000000..331e14f
--- /dev/null
+++ b/algorithm/tests/test_placement.py
@@ -0,0 +1,58 @@
+import pytest
+from shapely.geometry import box
+from app.geometry.placement import place_sticker, stickers_overlap
+from app.geometry.placement import fits_on_page
+
+def test_placement_moves_sticker_to_requested_position():
+ sticker = box(0,0,10,5)
+ placed = place_sticker(sticker, x=20, y=30)
+ assert placed.bounds == pytest.approx((20,30,30,35))
+ assert placed.area == pytest.approx(sticker.area)
+
+def test_rotation_preserves_area_and_swaps_bounds_at_90_degrees():
+ sticker = box(0,0,10,5)
+ placed = place_sticker(
+ sticker,
+ x=0,
+ y=0,
+ rotation_degrees=90,
+ )
+
+ min_x,min_y,max_x,max_y = placed.bounds
+
+ assert max_x - min_x == pytest.approx(5)
+ assert max_y - min_y == pytest.approx(10)
+ assert placed.area == pytest.approx(sticker.area)
+
+def test_overlapping_stickers_are_detected():
+ first = box(0,0,10,10)
+ second = box(5,5,15,15)
+ assert stickers_overlap(first, second)
+
+def test_stickers_that_only_touch_edges_do_not_overlap():
+ first = box(0,0,10,10)
+ second = box(10,0,20,10)
+ assert not stickers_overlap(first, second)
+
+def test_seperate_stickers_do_not_overlap():
+ first = box(0,0,10,10)
+ second = box(20,20,30,30)
+ assert not stickers_overlap(first,second)
+
+
+# extra geometry: page boundaries
+def test_sticker_inside_page_fits():
+ sticker = box(10,10,30,20)
+ page = box(0,0,100,100)
+
+ assert fits_on_page(sticker, page)
+
+def test_sticker_outside_page_does_not_fit():
+ sticker = box(90,90,110,110)
+ page = box(0,0,100,100)
+ assert not fits_on_page(sticker,page)
+
+def test_sticker_touching_page_edge_fits():
+ sticker = box(0,0,100,20)
+ page = box(0,0,100,100)
+ assert fits_on_page(sticker, page)
\ No newline at end of file
diff --git a/algorithm/tests/test_preview.py b/algorithm/tests/test_preview.py
new file mode 100644
index 0000000..9967186
--- /dev/null
+++ b/algorithm/tests/test_preview.py
@@ -0,0 +1,30 @@
+from shapely.geometry import box
+
+from app.visualization.preview import save_packing_preview
+
+def test_preview_creates_svg_file(tmp_path):
+ page = box(0,0,100,100)
+ sticker = box(10,20,30,40)
+ output = tmp_path/"preview.svg"
+
+ save_packing_preview(
+ page,
+ [(sticker,sticker)],
+ output,
+ )
+
+ assert output.exists()
+
+ svg = output.read_text()
+ assert "