Skip to content
Merged
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
317 changes: 317 additions & 0 deletions data/tests/approximation/approximate_by_line_segments/4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
{
"expected_output": {
"elements": [
{
"end": {
"x": 0.0,
"y": 100.0
},
"start": {
"x": 100.0,
"y": 100.0
},
"type": "LineSegment"
},
{
"end": {
"x": 0.0,
"y": 0.0
},
"start": {
"x": 0.0,
"y": 100.0
},
"type": "LineSegment"
},
{
"end": {
"x": 100.0,
"y": 0.0
},
"start": {
"x": 0.0,
"y": 0.0
},
"type": "LineSegment"
},
{
"end": {
"x": 100.0,
"y": 100.0
},
"start": {
"x": 100.0,
"y": 0.0
},
"type": "LineSegment"
}
],
"holes": [
{
"elements": [
{
"end": {
"x": 25.0,
"y": 50.0
},
"start": {
"x": 20.0,
"y": 50.0
},
"type": "LineSegment"
},
{
"end": {
"x": 25.0,
"y": 62.071067811865476
},
"start": {
"x": 25.0,
"y": 50.0
},
"type": "LineSegment"
},
{
"end": {
"x": 20.0,
"y": 50.0
},
"start": {
"x": 25.0,
"y": 62.071067811865476
},
"type": "LineSegment"
}
],
"is_path": false,
"type": "general"
},
{
"elements": [
{
"end": {
"x": 49.999999999999986,
"y": 78.86751345948127
},
"start": {
"x": 26.286262797369307,
"y": 65.17638090205041
},
"type": "LineSegment"
},
{
"end": {
"x": 73.71373720263071,
"y": 65.17638090205043
},
"start": {
"x": 49.999999999999986,
"y": 78.86751345948127
},
"type": "LineSegment"
},
{
"end": {
"x": 71.21320343559643,
"y": 71.21320343559643
},
"start": {
"x": 73.71373720263071,
"y": 65.17638090205043
},
"type": "LineSegment"
},
{
"end": {
"x": 50.0,
"y": 80.0
},
"start": {
"x": 71.21320343559643,
"y": 71.21320343559643
},
"type": "LineSegment"
},
{
"end": {
"x": 28.786796564403577,
"y": 71.21320343559643
},
"start": {
"x": 50.0,
"y": 80.0
},
"type": "LineSegment"
},
{
"end": {
"x": 26.286262797369307,
"y": 65.17638090205041
},
"start": {
"x": 28.786796564403577,
"y": 71.21320343559643
},
"type": "LineSegment"
}
],
"is_path": false,
"type": "general"
},
{
"elements": [
{
"end": {
"x": 75.0,
"y": 50.0
},
"start": {
"x": 74.99999999999997,
"y": 62.07106781186556
},
"type": "LineSegment"
},
{
"end": {
"x": 80.0,
"y": 50.0
},
"start": {
"x": 75.0,
"y": 50.0
},
"type": "LineSegment"
},
{
"end": {
"x": 74.99999999999997,
"y": 62.07106781186556
},
"start": {
"x": 80.0,
"y": 50.0
},
"type": "LineSegment"
}
],
"is_path": false,
"type": "general"
}
],
"is_path": false,
"type": "general"
},
"segment_length": 20.0,
"shape_with_holes": {
"elements": [
{
"end": {
"x": 100.0,
"y": 0.0
},
"start": {
"x": 0.0,
"y": 0.0
},
"type": "LineSegment"
},
{
"end": {
"x": 100.0,
"y": 100.0
},
"start": {
"x": 100.0,
"y": 0.0
},
"type": "LineSegment"
},
{
"end": {
"x": 0.0,
"y": 100.0
},
"start": {
"x": 100.0,
"y": 100.0
},
"type": "LineSegment"
},
{
"end": {
"x": 0.0,
"y": 0.0
},
"start": {
"x": 0.0,
"y": 100.0
},
"type": "LineSegment"
}
],
"holes": [
{
"elements": [
{
"center": {
"x": 50.0,
"y": 50.0
},
"end": {
"x": 20.0,
"y": 50.0
},
"orientation": "Anticlockwise",
"start": {
"x": 80.0,
"y": 50.0
},
"type": "CircularArc"
},
{
"end": {
"x": 25.0,
"y": 50.0
},
"start": {
"x": 20.0,
"y": 50.0
},
"type": "LineSegment"
},
{
"center": {
"x": 50.0,
"y": 50.0
},
"end": {
"x": 75.0,
"y": 50.0
},
"orientation": "Clockwise",
"start": {
"x": 25.0,
"y": 50.0
},
"type": "CircularArc"
},
{
"end": {
"x": 80.0,
"y": 50.0
},
"start": {
"x": 75.0,
"y": 50.0
},
"type": "LineSegment"
}
],
"is_path": false,
"type": "general"
}
],
"is_path": false,
"type": "general"
}
}
15 changes: 9 additions & 6 deletions src/approximation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,21 +301,24 @@ std::vector<Shape> compute_circular_arc_extras_inner(
}
//std::cout << "point_circle " << point_circle.to_string() << std::endl;

// The circular segment between the chord and the arc, anticlockwise
// like every shape passed to 'compute_union' (the arc is always
// traversed anticlockwise, the chord closes it).
Shape shape;
if (circular_arc.orientation != shape::ShapeElementOrientation::Clockwise) {
shape.elements.push_back(build_line_segment(point_circle_prev, point_circle));
shape.elements.push_back(build_circular_arc(
point_circle,
point_circle_prev,
point_circle,
circular_arc.center,
ShapeElementOrientation::Clockwise));
ShapeElementOrientation::Anticlockwise));
shape.elements.push_back(build_line_segment(point_circle, point_circle_prev));
} else {
shape.elements.push_back(build_line_segment(point_circle_prev, point_circle));
shape.elements.push_back(build_circular_arc(
point_circle_prev,
point_circle,
point_circle_prev,
circular_arc.center,
ShapeElementOrientation::Clockwise));
shape.elements.push_back(build_line_segment(point_circle, point_circle_prev));
ShapeElementOrientation::Anticlockwise));
}
output.push_back(shape);
point_circle_prev = point_circle;
Expand Down
7 changes: 7 additions & 0 deletions test/approximation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ INSTANTIATE_TEST_SUITE_P(
// is not positive" (fontanf/packingsolver#595).
ApproximateByLineSegmentsTestParams::read_json(
(fs::path("data") / "tests" / "approximation" / "approximate_by_line_segments" / "3.json").string()),
// Thin half-annulus hole with a large segment length: the tangent
// approximation of its clockwise inner arc crosses the chords of
// its anticlockwise outer arc, so the fallback union is used. The
// circular segments between the outer arc's chords and the arc
// used to be clockwise, and the union filled the hole entirely.
ApproximateByLineSegmentsTestParams::read_json(
(fs::path("data") / "tests" / "approximation" / "approximate_by_line_segments" / "4.json").string()),
}),
[](const testing::TestParamInfo<ApproximateByLineSegmentsTest::ParamType>& info) {
return fs::path(info.param.name).stem().string();
Expand Down
Loading