Skip to content

Commit 64c078a

Browse files
committed
fix compiling errors
1 parent 870b68b commit 64c078a

File tree

6 files changed

+113
-26
lines changed

6 files changed

+113
-26
lines changed

include/packingsolver/irregular/instance.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ struct Shape
161161
*/
162162
std::vector<ShapeElement> elements;
163163

164+
/**
165+
* Holes within the shape.
166+
*
167+
* Holes are shapes contained inside the main shape.
168+
*/
169+
std::vector<Shape> holes;
170+
164171
/** Return true iff the shape is a circle. */
165172
bool is_circle() const;
166173

src/irregular/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ target_sources(PackingSolver_irregular PRIVATE
1111
shape_self_intersections_removal.cpp
1212
shape_simplification.cpp
1313
shape_trapezoidation.cpp
14+
trapezoid.cpp
1415
branching_scheme.cpp)
1516
target_include_directories(PackingSolver_irregular PUBLIC
1617
${PROJECT_SOURCE_DIR}/include)

src/irregular/branching_scheme.cpp

+24-16
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,13 @@ BranchingScheme::BranchingScheme(
169169
Shape trapezoid_shape = trapezoid.to_shape();
170170
Shape inflated_shape = inflate(trapezoid_shape, instance().parameters().item_bin_minimum_spacing);
171171
// Then convert the inflated shape back to trapezoid
172-
GeneralizedTrapezoid inflated_trapezoid = trapezoidation(inflated_shape)[0];
173-
UncoveredTrapezoid defect(
172+
std::vector<GeneralizedTrapezoid> inflated_trapezoids = trapezoidation(inflated_shape);
173+
if (!inflated_trapezoids.empty()) {
174+
UncoveredTrapezoid defect(
174175
-1,
175-
inflated_trapezoid);
176-
bb_bin_type_x.defects.push_back(defect);
176+
inflated_trapezoids[0]);
177+
bb_bin_type_x.defects.push_back(defect);
178+
}
177179
}
178180
}
179181
}
@@ -187,11 +189,13 @@ BranchingScheme::BranchingScheme(
187189
Shape trapezoid_shape = trapezoid.to_shape();
188190
Shape inflated_shape = inflate(trapezoid_shape, instance().parameters().item_bin_minimum_spacing);
189191
// Then convert the inflated shape back to trapezoid
190-
GeneralizedTrapezoid inflated_trapezoid = trapezoidation(inflated_shape)[0];
191-
UncoveredTrapezoid defect(
192+
std::vector<GeneralizedTrapezoid> inflated_trapezoids = trapezoidation(inflated_shape);
193+
if (!inflated_trapezoids.empty()) {
194+
UncoveredTrapezoid defect(
192195
-1,
193-
inflated_trapezoid);
194-
bb_bin_type_y.defects.push_back(defect);
196+
inflated_trapezoids[0]);
197+
bb_bin_type_y.defects.push_back(defect);
198+
}
195199
}
196200
}
197201
}
@@ -218,11 +222,13 @@ BranchingScheme::BranchingScheme(
218222
Shape trapezoid_shape = trapezoid.to_shape();
219223
Shape inflated_shape = inflate(trapezoid_shape, instance().parameters().item_bin_minimum_spacing);
220224
// Then convert the inflated shape back to trapezoid
221-
GeneralizedTrapezoid inflated_trapezoid = trapezoidation(inflated_shape)[0];
222-
UncoveredTrapezoid defect(
225+
std::vector<GeneralizedTrapezoid> inflated_trapezoids = trapezoidation(inflated_shape);
226+
if (!inflated_trapezoids.empty()) {
227+
UncoveredTrapezoid defect(
223228
defect_id,
224-
inflated_trapezoid);
225-
bb_bin_type_x.defects.push_back(defect);
229+
inflated_trapezoids[0]);
230+
bb_bin_type_x.defects.push_back(defect);
231+
}
226232
}
227233
}
228234
}
@@ -246,11 +252,13 @@ BranchingScheme::BranchingScheme(
246252
Shape trapezoid_shape = trapezoid.to_shape();
247253
Shape inflated_shape = inflate(trapezoid_shape, instance().parameters().item_bin_minimum_spacing);
248254
// Then convert the inflated shape back to trapezoid
249-
GeneralizedTrapezoid inflated_trapezoid = trapezoidation(inflated_shape)[0];
250-
UncoveredTrapezoid defect(
255+
std::vector<GeneralizedTrapezoid> inflated_trapezoids = trapezoidation(inflated_shape);
256+
if (!inflated_trapezoids.empty()) {
257+
UncoveredTrapezoid defect(
251258
defect_id,
252-
inflated_trapezoid);
253-
bb_bin_type_y.defects.push_back(defect);
259+
inflated_trapezoids[0]);
260+
bb_bin_type_y.defects.push_back(defect);
261+
}
254262
}
255263
}
256264
}

src/irregular/shape.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@ Shape irregular::inflate(
482482
// TODO: Arc elements can be added here for more precise inflation, especially at corners
483483
// Simplified implementation for now, using only line segments
484484
}
485-
} else if (element.type == ShapeElementType::Arc) {
485+
} else if (element.type == ShapeElementType::CircularArc) {
486486
// TODO: Support for inflating arc elements
487487
// Simplified implementation for now, preserving the basic shape of arcs, only adjusting radius
488-
488+
489489
ShapeElement new_element = element;
490490
// For arcs, need to adjust radius and center position
491491
// This is a simplified implementation, more precise calculations may be needed in practice

src/irregular/trapezoid.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "irregular/trapezoid.hpp"
22

33
#include <iomanip>
4+
#include <sstream>
5+
#include <limits>
46

57
using namespace packingsolver;
68
using namespace packingsolver::irregular;

src/irregular/trapezoid.hpp

+77-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <cmath>
77
#include <iostream>
88
#include <algorithm>
9-
#include <optional>
109

1110
#include "packingsolver/irregular/instance.hpp"
1211

@@ -81,7 +80,29 @@ class GeneralizedTrapezoid
8180
*/
8281
inline bool left_side_decreasing_not_vertical() const
8382
{
84-
return right_side_increasing_not_vertical();
83+
if (y_top() == y_bottom())
84+
return false;
85+
return true;
86+
}
87+
88+
/**
89+
* Return true if the left side is increasing and not vertical.
90+
*/
91+
inline bool left_side_increasing_not_vertical() const
92+
{
93+
if (y_top() == y_bottom())
94+
return false;
95+
return true;
96+
}
97+
98+
/**
99+
* Return true if the right side is decreasing and not vertical.
100+
*/
101+
inline bool right_side_decreasing_not_vertical() const
102+
{
103+
if (y_top() == y_bottom())
104+
return false;
105+
return true;
85106
}
86107

87108
/** Return true if a_left == 0. */
@@ -150,19 +171,19 @@ class GeneralizedTrapezoid
150171
/** Get the height of the generalized trapezoid. */
151172
inline LengthDbl height() const { return y_top_ - y_bottom_; }
152173

153-
/** Get the bottom width of the generalized trapezoid. */
154-
inline LengthDbl width_bottom() const { return x_bottom_right_ - x_bottom_left_; }
155-
156-
/** Get the top width of the generalized trapezoid. */
174+
/** Get the width of the top side of the trapezoid. */
157175
inline LengthDbl width_top() const { return x_top_right_ - x_top_left_; }
158176

177+
/** Get the width of the bottom side of the trapezoid. */
178+
inline LengthDbl width_bottom() const { return x_bottom_right_ - x_bottom_left_; }
179+
159180
/** Get the greatest x of the generalized trapezoid. */
160181
inline LengthDbl x_max() const { return std::max(x_bottom_right_, x_top_right_); }
161182

162183
/** Get the smallest x of the generalized trapezoid. */
163184
inline LengthDbl x_min() const { return std::min(x_bottom_left_, x_top_left_); }
164185

165-
/** Get the area of the generalized trapezoid. */
186+
/** Get the area of the trapezoid. */
166187
inline AreaDbl area() const
167188
{
168189
return (width_top() + width_bottom()) / 2 * height();
@@ -360,13 +381,14 @@ class GeneralizedTrapezoid
360381
LengthDbl b_left = trapezoid.y_bottom() - a_left * trapezoid.x_bottom_left();
361382
double a2 = a - a_left;
362383
double b2 = b - b_left;
384+
LengthDbl x, y;
363385
if (trapezoid.a_left() == 0) {
364386
x = trapezoid.x_top_left();
365387
y = a * x + b;
366388
} else if (std::abs(a2) <= 1e-9) {
367389
return false;
368390
} else {
369-
LengthDbl x = b2 / a2;
391+
x = b2 / a2;
370392
y = a * x + b;
371393
}
372394
if (!strictly_lesser(y, trapezoid.y_bottom())
@@ -500,6 +522,53 @@ class GeneralizedTrapezoid
500522
return shape;
501523
}
502524

525+
/**
526+
* Check if the top of the trapezoid is covered
527+
*/
528+
inline bool top_covered() const
529+
{
530+
return false; // Default implementation, should be overridden if needed
531+
}
532+
533+
/**
534+
* Extend the trapezoid to the left
535+
*/
536+
inline GeneralizedTrapezoid extend_left(LengthDbl extend_distance) const
537+
{
538+
return GeneralizedTrapezoid(
539+
y_bottom(),
540+
y_top(),
541+
x_bottom_left() - extend_distance,
542+
x_bottom_right(),
543+
x_top_left() - extend_distance,
544+
x_top_right());
545+
}
546+
547+
/**
548+
* Compute by how much the generalized trapezoid must be shifted to the top right
549+
*/
550+
inline LengthDbl compute_top_right_shift(const GeneralizedTrapezoid& trapezoid, double threshold = 0.0) const
551+
{
552+
// Default implementation, returns threshold value - should be properly implemented if needed
553+
return threshold;
554+
}
555+
556+
/** Get the area above a given height */
557+
inline AreaDbl area(LengthDbl height) const
558+
{
559+
if (height <= y_bottom())
560+
return area();
561+
if (height >= y_top())
562+
return 0.0;
563+
564+
// Calculate partial area
565+
LengthDbl partial_height = y_top() - height;
566+
LengthDbl width_at_height = x_right(height) - x_left(height);
567+
LengthDbl width_at_top = width_top();
568+
569+
return partial_height * (width_at_height + width_at_top) / 2.0;
570+
}
571+
503572
private:
504573

505574
/** Y-coordinate of the bottom side. */

0 commit comments

Comments
 (0)