From 5cd8fb04fe78b9930346522c3ef5350672f6d13b Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sat, 21 Mar 2020 08:32:49 +0800 Subject: [PATCH] Disambiguation of saddle points --- .../_impl/_marching_squares_impl.scad | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/experimental/_impl/_marching_squares_impl.scad b/src/experimental/_impl/_marching_squares_impl.scad index 91dd1cb7..6a830dc4 100644 --- a/src/experimental/_impl/_marching_squares_impl.scad +++ b/src/experimental/_impl/_marching_squares_impl.scad @@ -39,10 +39,18 @@ function case4_contours(cell_pts, sigma) = [ [interpolated_pt(cell_pts[1], cell_pts[2], sigma), interpolated_pt(cell_pts[2], cell_pts[3], sigma)] ]; -function case5_contours(cell_pts, sigma) = [ - [interpolated_pt(cell_pts[0], cell_pts[1], sigma), interpolated_pt(cell_pts[1], cell_pts[2], sigma)], - [interpolated_pt(cell_pts[0], cell_pts[3], sigma), interpolated_pt(cell_pts[2], cell_pts[3], sigma)] -]; +function case5_contours(cell_pts, sigma) = + let(mdpz = ((cell_pts[0] + cell_pts[1]) / 2)[2]) + mdpz >= sigma ? + [ + [interpolated_pt(cell_pts[0], cell_pts[1], sigma), interpolated_pt(cell_pts[1], cell_pts[2], sigma)], + [interpolated_pt(cell_pts[0], cell_pts[3], sigma), interpolated_pt(cell_pts[2], cell_pts[3], sigma)] + ] + : + [ + [interpolated_pt(cell_pts[0], cell_pts[1], sigma), interpolated_pt(cell_pts[0], cell_pts[3], sigma)], + [interpolated_pt(cell_pts[1], cell_pts[2], sigma), interpolated_pt(cell_pts[2], cell_pts[3], sigma)] + ]; function case6_contours(cell_pts, sigma) = [ [interpolated_pt(cell_pts[1], cell_pts[2], sigma), interpolated_pt(cell_pts[0], cell_pts[3], sigma)] @@ -56,10 +64,18 @@ function case8_contours(cell_pts, sigma) = case7_contours(cell_pts, sigma); function case9_contours(cell_pts, sigma) = case6_contours(cell_pts, sigma); -function case10_contours(cell_pts, sigma) = [ - [interpolated_pt(cell_pts[0], cell_pts[1], sigma), interpolated_pt(cell_pts[0], cell_pts[3], sigma)], - [interpolated_pt(cell_pts[1], cell_pts[2], sigma), interpolated_pt(cell_pts[2], cell_pts[3], sigma)] -]; +function case10_contours(cell_pts, sigma) = + let(mdpz = ((cell_pts[0] + cell_pts[1]) / 2)[2]) + mdpz >= sigma ? + [ + [interpolated_pt(cell_pts[0], cell_pts[1], sigma), interpolated_pt(cell_pts[0], cell_pts[3], sigma)], + [interpolated_pt(cell_pts[1], cell_pts[2], sigma), interpolated_pt(cell_pts[2], cell_pts[3], sigma)] + ] + : + [ + [interpolated_pt(cell_pts[0], cell_pts[1], sigma), interpolated_pt(cell_pts[1], cell_pts[2], sigma)], + [interpolated_pt(cell_pts[0], cell_pts[3], sigma), interpolated_pt(cell_pts[2], cell_pts[3], sigma)] + ]; function case11_contours(cell_pts, sigma) = case4_contours(cell_pts, sigma);