From ba32041b535b5d08187fa57eb7c0765bc3510ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C4=8C=C3=AD=C5=BEek?= Date: Tue, 2 Feb 2021 19:18:43 +0100 Subject: [PATCH] Make circle_point_tangents() behavior consistent for points on the circle. Fix #408 --- geometry.scad | 2 +- tests/test_geometry.scad | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/geometry.scad b/geometry.scad index 52f03c2..280a4fd 100644 --- a/geometry.scad +++ b/geometry.scad @@ -1508,7 +1508,7 @@ function circle_point_tangents(r, d, cp, pt) = dist = norm(delta), baseang = atan2(delta.y,delta.x) ) dist < r? [] : - approx(dist,r)? [[baseang, pt]] : + approx(dist,r)? [pt] : let( relang = acos(r/dist), angs = [baseang + relang, baseang - relang] diff --git a/tests/test_geometry.scad b/tests/test_geometry.scad index 6dc8e02..fbcf4de 100644 --- a/tests/test_geometry.scad +++ b/tests/test_geometry.scad @@ -606,7 +606,10 @@ module test_circle_point_tangents() { [[0,0], 50, [50*sqrt(2),0], [polar_to_xy(50,45), polar_to_xy(50,-45)]], [[5,10], 50, [5+50*sqrt(2),10], [[5,10]+polar_to_xy(50,45), [5,10]+polar_to_xy(50,-45)]], [[0,0], 50, [0,50*sqrt(2)], [polar_to_xy(50,135), polar_to_xy(50,45)]], - [[5,10], 50, [5,10+50*sqrt(2)], [[5,10]+polar_to_xy(50,135), [5,10]+polar_to_xy(50,45)]] + [[5,10], 50, [5,10+50*sqrt(2)], [[5,10]+polar_to_xy(50,135), [5,10]+polar_to_xy(50,45)]], + [[5,10], 50, [5,10+50*sqrt(2)], [[5,10]+polar_to_xy(50,135), [5,10]+polar_to_xy(50,45)]], + [[5,10], 50, [5, 60], [[5, 60]]], + [[5,10], 50, [5, 59], []], ]; for (v = testvals) { cp = v[0]; r = v[1]; pt = v[2]; expect = v[3];