Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions python/packaide/packaide.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from xml.dom import minidom

from PackaideBindings import Point, Polygon, PolygonWithHoles, Sheet, State, Placement
from PackaideBindings import pack_decreasing, sheet_add_holes
from PackaideBindings import pack_decreasing, sheet_add_holes_with_holes

# We want to preserve presentation and identification (e.g., id, name, class) attributes
# when flattening the SVG elements and writing them into the output, so that the packed
Expand Down Expand Up @@ -252,8 +252,7 @@ def pack(sheet_svgs, shapes, offset = 1, tolerance = 1, partial_solution = False
sheet = Sheet()
_, holes = extract_polygons(svg_string, tolerance, offset)
sheet.height, sheet.width = get_sheet_dimensions(svg_string)
holes = [hole.boundary for hole in holes]
sheet_add_holes(sheet, holes, state)
sheet_add_holes_with_holes(sheet, holes, state)
sheets.append(sheet)

# Run the packing algorithm
Expand Down
19 changes: 17 additions & 2 deletions src/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,31 @@ packaide::PolygonWithHoles boost_polygon_with_holes_convert(const Polygon_with_h
// ------------------------------------------------------
// Helper functions

// Given a sheet object and a list of polyons, add those
// Given a sheet object and a list of polygons, add those
// polygons as holes to the sheet
void sheet_add_holes_bind(packaide::Sheet& sheet, boost::python::list polygons, packaide::State& state){
std::vector<Polygon_with_holes_2> pgons;
for(boost::python::ssize_t i=0; i<boost::python::len(polygons); i++){
auto hole = Polygon_with_holes_2(packaide_polygon_convert(boost::python::extract<packaide::Polygon>(polygons[i])));
auto python_polygon = boost::python::extract<packaide::Polygon>(polygons[i]);
auto packaide_polygon = packaide_polygon_convert(python_polygon);
auto hole = Polygon_with_holes_2(packaide_polygon);
pgons.push_back(hole);
}
sheet.holes = pgons;
}

// Given a sheet object and a list of polygons with holes, add those
// polygons as holes to the sheet
void sheet_add_holes_with_holes_bind(packaide::Sheet& sheet, boost::python::list polygons_with_holes, packaide::State& state){
std::vector<Polygon_with_holes_2> pgons;
for(boost::python::ssize_t i=0; i<boost::python::len(polygons_with_holes); i++){
auto python_polygon = boost::python::extract<packaide::PolygonWithHoles>(polygons_with_holes[i]);
auto packaide_polygon = packaide_polygon_with_holes_convert(python_polygon);
pgons.push_back(packaide_polygon);
}
sheet.holes = pgons;
}

// ------------------------------------------------------
// Main packing function

Expand Down Expand Up @@ -172,5 +186,6 @@ BOOST_PYTHON_MODULE(PackaideBindings) {
class_<packaide::State>("State", init<>());

def("sheet_add_holes", sheet_add_holes_bind);
def("sheet_add_holes_with_holes", sheet_add_holes_with_holes_bind);
def("pack_decreasing", pack_decreasing_bind);
}