From 20fc3b9f0f7d69f382b9a2c2e197b95e8378fe2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 28 Mar 2016 08:17:27 -0700 Subject: [PATCH] Optimize Curve.getArea() to use less operators. As proposed by @iconexperience in https://github.com/paperjs/paper.js/issues/994#issuecomment-189946135, rearranged for mathematical symmetry. Closes #994 --- src/path/Curve.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/path/Curve.js b/src/path/Curve.js index b911c245..b352885a 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -761,9 +761,9 @@ statics: /** @lends Curve */{ c1x = v[2], c1y = v[3], c2x = v[4], c2y = v[5], p2x = v[6], p2y = v[7]; - return (6 * (p1x*c1y-p1y*c1x+c2x*p2y-p2x*c2y) + - 3 * (c1x*p2y-c1y*p2x+p1x*c2y-c2x*p1y+c1x*c2y-c1y*c2x) + - 1 * (p1x*p2y-p1y*p2x)) / 20; + return 3 * ((p2y - p1y) * (c1x + c2x) - (p2x - p1x) * (c1y + c2y) + + c1y * (p1x - c2x) - c1x * (p1y - c2y) + + p2y * (c2x + p1x / 3) - p2x * (c2y + p1y / 3)) / 20; }, getBounds: function(v) {