Skip to content

Commit

Permalink
linear_extrude slices calculation (#4371)
Browse files Browse the repository at this point in the history
* linear_extrude slices calculation: non uniform scale with twist uses max of twist and non uniform scale
  • Loading branch information
UBaer21 committed Oct 19, 2022
1 parent 66818d1 commit 484f3c6
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/geometry/GeometryEvaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1034,20 +1034,33 @@ static Geometry *extrudePolygon(const LinearExtrudeNode& node, const Polygon2d&
for (const auto& v : o.vertices)
max_r1_sqr = fmax(max_r1_sqr, v.squaredNorm());
// Calculate Helical curve length for Twist with no Scaling
// **** Don't know how to handle twist with non-uniform scaling, ****
// **** so just use this straight helix calculation anyways. ****
if ((node.scale_x == 1.0 && node.scale_y == 1.0) || node.scale_x != node.scale_y) {
if (node.scale_x == 1.0 && node.scale_y == 1.0) {
slices = (unsigned int)Calc::get_helix_slices(max_r1_sqr, node.height, node.twist, node.fn, node.fs, node.fa);
} else if ( node.scale_x != node.scale_y) { // non uniform scaling with twist using max slices from twist and non uniform scale
double max_delta_sqr = 0; // delta from before/after scaling
Vector2d scale(node.scale_x, node.scale_y);
for (const auto& o : poly.outlines()){
for (const auto& v : o.vertices){
max_delta_sqr = fmax(max_delta_sqr, (v - v.cwiseProduct(scale)).squaredNorm());
}
}
size_t slicesNonUniScale;
size_t slicesTwist;
slicesNonUniScale = (unsigned int)Calc::get_diagonal_slices(max_delta_sqr, node.height, node.fn, node.fs);
slicesTwist = (unsigned int)Calc::get_helix_slices(max_r1_sqr, node.height, node.twist, node.fn, node.fs, node.fa);
slices = std::max(slicesNonUniScale,slicesTwist);
} else { // uniform scaling with twist, use conical helix calculation
slices = (unsigned int)Calc::get_conical_helix_slices(max_r1_sqr, node.height, node.twist, node.scale_x, node.fn, node.fs, node.fa);
}
} else if (node.scale_x != node.scale_y) {
// Non uniform scaling, w/o twist
double max_delta_sqr = 0; // delta from before/after scaling
Vector2d scale(node.scale_x, node.scale_y);
for (const auto& o : poly.outlines())
for (const auto& v : o.vertices)
for (const auto& o : poly.outlines()){
for (const auto& v : o.vertices){
max_delta_sqr = fmax(max_delta_sqr, (v - v.cwiseProduct(scale)).squaredNorm());
}
}
slices = Calc::get_diagonal_slices(max_delta_sqr, node.height, node.fn, node.fs);
} else {
// uniform or [1,1] scaling w/o twist needs only one slice
Expand Down

0 comments on commit 484f3c6

Please sign in to comment.