From: Shaheen Gandhi Date: Tue, 20 Aug 2013 06:34:47 +0000 (-0700) Subject: [Helix][perf] Write replacement distance function for inlining X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e034041e0651b6e57ebb2d2399df8a560c92b231;p=SugarCubes.git [Helix][perf] Write replacement distance function for inlining --- diff --git a/ShaheenGandhi.pde b/ShaheenGandhi.pde index d562e3b..86ead55 100644 --- a/ShaheenGandhi.pde +++ b/ShaheenGandhi.pde @@ -115,6 +115,13 @@ class HelixPattern extends SCPattern { PVector middle = PVector.add(p, phaseNormal); return axis.rotatePoint(middle, (t / period) * TWO_PI + phase); } + + private float myDist(PVector p1, PVector p2) { + final float x = p2.x-p1.x; + final float y = p2.y-p1.y; + final float z = p2.z-p1.z; + return sqrt(x*x + y*y + z*z); + } color colorOfPoint(final PVector p) { final float t = axis.getTValue(p); @@ -122,7 +129,7 @@ class HelixPattern extends SCPattern { // For performance reasons, cut out points that are outside of // the tube where the toroidal coil lives. - if (abs(PVector.dist(p, axisPoint) - radius) > girth*.5f) { + if (abs(myDist(p, axisPoint) - radius) > girth*.5f) { return color(0,0,0); } @@ -135,7 +142,7 @@ class HelixPattern extends SCPattern { // The rotated point represents the middle of the girth of // the helix. Figure out if the current point is inside that // region. - float d = PVector.dist(p, toroidPoint); + float d = myDist(p, toroidPoint); // Soften edges by fading brightness. float b = constrain(100*(1 - ((d-.5*girth)/(girth*.5))), 0, 100);