From 663a7e0369a19294d4eb7fb77a7951b846c56877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 18 Jun 2013 18:23:48 -0700 Subject: [PATCH] Implement unit tests for Curve#getTangentAt() and #getNormalAt(). --- test/tests/Curve.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/tests/Curve.js b/test/tests/Curve.js index 9cb7fefa..47712fd0 100644 --- a/test/tests/Curve.js +++ b/test/tests/Curve.js @@ -32,3 +32,45 @@ test('Curve#getPointAt()', function() { 'curve.getPointAt(' + entry[0] + ', true);'); } }); + +test('Curve#getTangentAt()', function() { + var curve = new Path.Circle({ + center: [100, 100], + radius: 100 + }).getFirstCurve(); + + var points = [ + [0, new Point(0, -165.68542 )], + [0.25, new Point(60.7233, -143.56602)], + [0.5, new Point(108.57864, -108.57864)], + [0.75, new Point(143.56602, -60.7233)], + [1, new Point(165.68542, 0)] + ]; + + for (var i = 0; i < points.length; i++) { + var entry = points[i]; + comparePoints(curve.getTangentAt(entry[0], true), entry[1], + 'curve.getPointAt(' + entry[0] + ', true);'); + } +}); + +test('Curve#getNormalAt()', function() { + var curve = new Path.Circle({ + center: [100, 100], + radius: 100 + }).getFirstCurve(); + + var points = [ + [0, new Point(-165.68542, 0)], + [0.25, new Point(-143.56602, -60.7233)], + [0.5, new Point(-108.57864, -108.57864)], + [0.75, new Point(-60.7233, -143.56602)], + [1, new Point(0, -165.68542)] + ]; + + for (var i = 0; i < points.length; i++) { + var entry = points[i]; + comparePoints(curve.getNormalAt(entry[0], true), entry[1], + 'curve.getPointAt(' + entry[0] + ', true);'); + } +});