From 242962f41cd885c64006d7d3e44ca2e945c13623 Mon Sep 17 00:00:00 2001 From: eyal0 <109809+eyal0@users.noreply.github.com> Date: Tue, 16 Jun 2020 21:51:09 -0600 Subject: [PATCH] Use cosine formula instead of length formula --- eulerian_paths.hpp | 12 +++++++++--- .../expected/back.ngc | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/eulerian_paths.hpp b/eulerian_paths.hpp index b79cf0fcd..0ced0eb6b 100644 --- a/eulerian_paths.hpp +++ b/eulerian_paths.hpp @@ -200,11 +200,17 @@ class eulerian_paths { // This must be reversed. p2 = paths[option.second.first].first[paths[option.second.first].first.size()-2]; } - auto length_p0_p1 = bg::distance(p0, p1); - auto length_p1_p2 = bg::distance(p1, p2); - auto delta_x = (p1.x() - p0.x())/length_p0_p1 + (p2.x() - p1.x())/length_p1_p2; + /*auto delta_x = (p1.x() - p0.x())/length_p0_p1 + (p2.x() - p1.x())/length_p1_p2; auto delta_y = (p1.y() - p0.y())/length_p0_p1 + (p2.y() - p1.y())/length_p1_p2; return (delta_x * delta_x + delta_y * delta_y); // No need to sqrt, this is comparable. + */ + auto delta_x10 = p0.x() - p1.x(); + auto delta_y10 = p0.y() - p1.y(); + auto delta_x12 = p2.x() - p1.x(); + auto delta_y12 = p2.y() - p1.y(); + auto length_product = sqrt((delta_x10*delta_x10 + delta_y10*delta_y10) * (delta_x12*delta_x12 + delta_y12*delta_y12)); + auto dot_product = (delta_x10*delta_x12) + (delta_y10*delta_y12); + return -dot_product/length_product; } double path_score(const linestring_t&, diff --git a/testing/gerbv_example/am-test-voronoi-wide-extra-passes/expected/back.ngc b/testing/gerbv_example/am-test-voronoi-wide-extra-passes/expected/back.ngc index ef332e8f6..a3173689d 100644 --- a/testing/gerbv_example/am-test-voronoi-wide-extra-passes/expected/back.ngc +++ b/testing/gerbv_example/am-test-voronoi-wide-extra-passes/expected/back.ngc @@ -39,9 +39,9 @@ G01 X-10.43250 Y10.43250 G01 X-10.43250 Y-0.43250 G01 X0.43250 Y-0.43250 G01 X0.38250 Y-0.38250 -G01 X0.38250 Y10.38250 -G01 X-10.38250 Y10.38250 G01 X-10.38250 Y-0.38250 +G01 X-10.38250 Y10.38250 +G01 X0.38250 Y10.38250 G01 X0.38250 Y-0.38250 G04 P0 ( dwell for no time -- G64 should not smooth over this point ) G00 Z0.08000 ( retract )