mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-30 00:45:26 -05:00
Report sketch loop areas as positive whichever way the loop runs
This commit is contained in:
1 parent
4dd989a9e3
commit
88a366dfb2
3 files changed
+29
-5
No files matched your search
@@ -10677,8 +10677,11 @@ DesignSketchTool::LoopReport DesignSketchTool::loop_report(const std::vector<Ske
|
||||
}
|
||||
cur = Q;
|
||||
}
|
||||
// Both integrals are signed by the way the chain runs, which is only the order its
|
||||
// entities were drawn in (the slot tool lays every slot out clockwise), so the sign is
|
||||
// dropped: the area is the region's, as a circle's is.
|
||||
if (exact) {
|
||||
li.area = 0.5 * area2;
|
||||
li.area = std::abs(0.5 * area2);
|
||||
} else {
|
||||
// Splines and elliptical arcs have no closed form here; the render polyline is
|
||||
// the honest best estimate, and it is flagged as such by being the fallback.
|
||||
@@ -10687,7 +10690,7 @@ DesignSketchTool::LoopReport DesignSketchTool::loop_report(const std::vector<Ske
|
||||
a += r.poly[i].x() * r.poly[i + 1].y() - r.poly[i + 1].x() * r.poly[i].y();
|
||||
if (r.poly.size() > 2)
|
||||
a += r.poly.back().x() * r.poly.front().y() - r.poly.front().x() * r.poly.back().y();
|
||||
li.area = 0.5 * a;
|
||||
li.area = std::abs(0.5 * a);
|
||||
}
|
||||
}
|
||||
out.loops.push_back(std::move(li));
|
||||
|
||||
@@ -632,7 +632,7 @@ public:
|
||||
std::vector<int> ents; // entities of this loop, in chain order
|
||||
std::vector<int> holes; // indices into LoopReport::loops that this loop encloses
|
||||
bool closed{false};
|
||||
double area{0.0}; // signed shoelace area of the loop polyline
|
||||
double area{0.0}; // area the loop encloses (mm^2), its holes not taken out
|
||||
bool defect{false}; // crosses or folds back on itself (see RegionLoop)
|
||||
Vec2d defect_at{0, 0};
|
||||
};
|
||||
|
||||
@@ -2213,7 +2213,7 @@ double only_loop_area(const GUI::DesignSketchTool& tool)
|
||||
const GUI::DesignSketchTool::LoopReport rep = tool.loop_report();
|
||||
REQUIRE(rep.loops.size() == 1);
|
||||
CHECK(rep.open_ends.empty());
|
||||
return std::abs(rep.loops[0].area);
|
||||
return rep.loops[0].area;
|
||||
}
|
||||
|
||||
BoundingBoxf entities_box(const std::vector<SketchEntity>& ents, size_t first, size_t count)
|
||||
@@ -2273,7 +2273,7 @@ TEST_CASE("sketch_add draws polygons, slots, ellipses and splines as their tools
|
||||
for (const auto& l : rep.loops)
|
||||
if (l.ents.size() == 4) {
|
||||
slot_found = true;
|
||||
CHECK_THAT(std::abs(l.area), WithinAbs(20.0 * 5.0 + PI * 2.5 * 2.5, 1e-6));
|
||||
CHECK_THAT(l.area, WithinAbs(20.0 * 5.0 + PI * 2.5 * 2.5, 1e-6));
|
||||
}
|
||||
CHECK(slot_found);
|
||||
const SketchEntity& el = ents[5];
|
||||
@@ -2488,6 +2488,27 @@ TEST_CASE("sketch_transform moves, rotates, scales and arrays as the transform t
|
||||
CHECK(ents.size() == n);
|
||||
}
|
||||
|
||||
TEST_CASE("a loop reports the area it encloses whichever way it runs", "[Mcp][CAD]")
|
||||
{
|
||||
GUI::DesignSketchTool tool;
|
||||
begin_sketch(tool);
|
||||
// A 10 mm square drawn clockwise (entities 0-3), and a slot, which the slot tool lays out
|
||||
// clockwise whichever way its centres are given (4-7).
|
||||
sketch(tool, "sketch_add", {{"entities",
|
||||
{{{"type", "line"}, {"p0", {0, 0}}, {"p1", {0, 10}}},
|
||||
{{"type", "line"}, {"p0", {0, 10}}, {"p1", {10, 10}}},
|
||||
{{"type", "line"}, {"p0", {10, 10}}, {"p1", {10, 0}}},
|
||||
{{"type", "line"}, {"p0", {10, 0}}, {"p1", {0, 0}}},
|
||||
{{"type", "slot"}, {"c0", {30, 0}}, {"c1", {50, 0}}, {"width", 6}}}}});
|
||||
// The report sketch_validate and sketch_describe print as closed_loops.
|
||||
const GUI::DesignSketchTool::LoopReport rep = tool.loop_report();
|
||||
REQUIRE(rep.loops.size() == 2);
|
||||
for (const auto& l : rep.loops) {
|
||||
const bool square = l.ents.at(0) < 4;
|
||||
CHECK_THAT(l.area, WithinAbs(square ? 10.0 * 10.0 : 20.0 * 6.0 + PI * 3.0 * 3.0, 1e-6));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("constraints are planned from picks as the CONSTRAIN bar does, or taken from refs as written", "[Mcp][CAD]")
|
||||
{
|
||||
using T = SketchConstraintType;
|
||||
|
||||
Reference in new issue
Block a user