mirror of https://github.com/vitalif/openscad
Mark twist-free linear extrusions of convex polygons convex
parent
2e1f24b4dc
commit
b62079a632
|
@ -633,7 +633,8 @@ static void add_slice(PolySet *ps, const Polygon2d &poly,
|
||||||
*/
|
*/
|
||||||
static Geometry *extrudePolygon(const LinearExtrudeNode &node, const Polygon2d &poly)
|
static Geometry *extrudePolygon(const LinearExtrudeNode &node, const Polygon2d &poly)
|
||||||
{
|
{
|
||||||
PolySet *ps = new PolySet(3);
|
bool cvx = poly.is_convex();
|
||||||
|
PolySet *ps = new PolySet(3, !cvx ? boost::tribool(false) : node.twist == 0 ? boost::tribool(true) : unknown);
|
||||||
ps->setConvexity(node.convexity);
|
ps->setConvexity(node.convexity);
|
||||||
if (node.height <= 0) return ps;
|
if (node.height <= 0) return ps;
|
||||||
|
|
||||||
|
|
|
@ -92,3 +92,20 @@ void Polygon2d::resize(Vector2d newsize, const Eigen::Matrix<bool,2,1> &autosize
|
||||||
this->transform(t);
|
this->transform(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Polygon2d::is_convex() const {
|
||||||
|
if (theoutlines.size() > 1) return false;
|
||||||
|
if (theoutlines.empty()) return true;
|
||||||
|
|
||||||
|
std::vector<Vector2d> const& pts = theoutlines[0].vertices;
|
||||||
|
int N = pts.size();
|
||||||
|
|
||||||
|
// Check for a right turn. This assumes the polygon is simple.
|
||||||
|
for (int i = 0; i < N; i++) {
|
||||||
|
Vector2d d1 = pts[(i+1)%N] - pts[i];
|
||||||
|
Vector2d d2 = pts[(i+2)%N] - pts[(i+1)%N];
|
||||||
|
double zcross = d1[0]*d2[1]-d1[1]*d2[0];
|
||||||
|
if (zcross < 0) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
|
|
||||||
bool isSanitized() const { return this->sanitized; }
|
bool isSanitized() const { return this->sanitized; }
|
||||||
void setSanitized(bool s) { this->sanitized = s; }
|
void setSanitized(bool s) { this->sanitized = s; }
|
||||||
|
bool is_convex() const;
|
||||||
private:
|
private:
|
||||||
Outlines2d theoutlines;
|
Outlines2d theoutlines;
|
||||||
bool sanitized;
|
bool sanitized;
|
||||||
|
|
Loading…
Reference in New Issue