Skip to content
Merged

Dev #177

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
40 changes: 20 additions & 20 deletions include/packingsolver/irregular/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,6 @@ namespace packingsolver
namespace irregular
{

struct ItemShape
{
/** Main shape. */
Shape shape;

/**
* Holes.
*
* Holes are shapes contained inside the main shape.
*/
std::vector<Shape> holes;

/** Quality rule. */
QualityRule quality_rule = 0;

bool check() const;

std::string to_string(Counter indentation) const;
};

////////////////////////////////////////////////////////////////////////////////
///////////////////////// Item type, Bin type, Defect //////////////////////////
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -116,6 +96,26 @@ struct BinType
const std::string& file_path) const;
};

struct ItemShape
{
/** Main shape. */
Shape shape;

/**
* Holes.
*
* Holes are shapes contained inside the main shape.
*/
std::vector<Shape> holes;

/** Quality rule. */
QualityRule quality_rule = 0;

bool check() const;

std::string to_string(Counter indentation) const;
};

/**
* Item type structure for a problem of type 'irregular'.
*/
Expand Down
8 changes: 5 additions & 3 deletions include/packingsolver/irregular/shape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ using ItemShapePos = int64_t;
using ShapePos = int64_t;
using Counter = int64_t;

using packingsolver::equal;

////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////// Point /////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -307,7 +309,7 @@ inline bool operator==(
return (point_1.x == point_2.x) && (point_1.y == point_2.y);
}

inline bool near(
inline bool equal(
const Point& point_1,
const Point& point_2)
{
Expand All @@ -318,15 +320,15 @@ bool operator==(
const ShapeElement& element_1,
const ShapeElement& element_2);

bool near(
bool equal(
const ShapeElement& element_1,
const ShapeElement& element_2);

bool operator==(
const Shape& shape_1,
const Shape& shape_2);

bool near(
bool equal(
const Shape& shape_1,
const Shape& shape_2);

Expand Down
25 changes: 12 additions & 13 deletions src/irregular/shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ LengthDbl ShapeElement::length() const
return distance(this->start, this->end);
case ShapeElementType::CircularArc:
LengthDbl r = distance(center, start);
return angle_radian(start - center, end - center) * r;
if (anticlockwise) {
return angle_radian(start - center, end - center) * r;
} else {
return angle_radian(end - center, start - center) * r;
}
}
return -1;
}
Expand Down Expand Up @@ -437,11 +441,6 @@ bool Shape::is_rectangle() const
it_prev = it;
}
return true;
if (!equal(elements[0].length(), elements[2].length()))
return false;
if (!equal(elements[1].length(), elements[3].length()))
return false;
return true;
}

bool Shape::is_polygon() const
Expand Down Expand Up @@ -973,18 +972,18 @@ bool irregular::operator==(
return true;
}

bool irregular::near(
bool irregular::equal(
const ShapeElement& element_1,
const ShapeElement& element_2)
{
if (element_1.type != element_2.type)
return false;
if (!near(element_1.start, element_2.start))
if (!equal(element_1.start, element_2.start))
return false;
if (!near(element_1.end, element_2.end))
if (!equal(element_1.end, element_2.end))
return false;
if (element_1.type == ShapeElementType::CircularArc) {
if (!near(element_1.center, element_2.center))
if (!equal(element_1.center, element_2.center))
return false;
if (element_1.anticlockwise != element_2.anticlockwise)
return false;
Expand Down Expand Up @@ -1024,7 +1023,7 @@ bool irregular::operator==(
return true;
}

bool irregular::near(
bool irregular::equal(
const Shape& shape_1,
const Shape& shape_2)
{
Expand All @@ -1036,7 +1035,7 @@ bool irregular::near(
for (ElementPos element_pos = 0;
element_pos < (ElementPos)shape_2.elements.size();
++element_pos) {
if (near(shape_2.elements[element_pos], shape_1.elements[0])) {
if (equal(shape_2.elements[element_pos], shape_1.elements[0])) {
offset = element_pos;
break;
}
Expand All @@ -1048,7 +1047,7 @@ bool irregular::near(
element_pos < (ElementPos)shape_2.elements.size();
++element_pos) {
ElementPos element_pos_2 = (element_pos + offset) % shape_2.elements.size();
if (!near(shape_1.elements[element_pos], shape_2.elements[element_pos_2])) {
if (!equal(shape_1.elements[element_pos], shape_2.elements[element_pos_2])) {
return false;
}
}
Expand Down
26 changes: 25 additions & 1 deletion test/irregular/shape_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@
using namespace packingsolver;
using namespace packingsolver::irregular;

struct ShapeElementLengthTestParams
{
ShapeElement element;
LengthDbl expected_length;
};

class IrregularShapeElementLengthTest: public testing::TestWithParam<ShapeElementLengthTestParams> { };

TEST_P(IrregularShapeElementLengthTest, ShapeElementLength)
{
ShapeElementLengthTestParams test_params = GetParam();
EXPECT_TRUE(equal(test_params.element.length(), test_params.expected_length));
}

INSTANTIATE_TEST_SUITE_P(
Irregular,
IrregularShapeElementLengthTest,
testing::ValuesIn(std::vector<ShapeElementLengthTestParams>{
{build_shape({{0, 0}, {0, 1}}, true).elements.front(), 1 },
{build_shape({{1, 0}, {0, 0, 1}, {0, 1}}, true).elements.front(), M_PI / 2 },
{build_shape({{1, 0}, {0, 0, -1}, {0, -1}}, true).elements.front(), M_PI / 2 },
}));


struct CleanShapeTestParams
{
Shape shape;
Expand Down Expand Up @@ -66,7 +90,7 @@ TEST_P(IrregularApproximateCircularArcByLineSegmentsTest, ApproximateCircularArc
ASSERT_EQ(line_segments.size(), test_params.number_of_line_segments);
for (ElementPos pos = 0; pos < test_params.number_of_line_segments; ++pos) {
//std::cout << std::setprecision (15) << line_segments[pos].start.x << std::endl;
EXPECT_TRUE(near(line_segments[pos], test_params.expected_line_segments[pos]));
EXPECT_TRUE(equal(line_segments[pos], test_params.expected_line_segments[pos]));
}
}

Expand Down
Loading