This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Different ways to save state or configure a function | |
| * | |
| */ | |
| //------------------------------------------------- | |
| // Typical prototypical inheritance | |
| var Talker = function( phrase ) { | |
| this.phrase = phrase; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| findPerpendicularDistance = ( point, line ) -> | |
| [pointX,pointY] = point[0..1] | |
| lineStart = x: line[0][0], y: line[0][1] | |
| lineEnd = x: line[1][0], y: line[1][1] | |
| slope = ( lineEnd.y - lineStart.y ) / ( lineEnd.x - lineStart.x ) | |
| intercept = lineStart.y - ( slope * lineStart.x ) | |
| Math.abs( slope * pointX - pointY + intercept ) / Math.sqrt( Math.pow( slope, 2) + 1) | |
| douglasPeucker = ( points, epsilon ) -> | |
| maxIndex = maxDistance = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function findPerpendicularDistance(point, line) { | |
| var pointX = point[0], | |
| pointY = point[1], | |
| lineStart = { | |
| x: line[0][0], | |
| y: line[0][1] | |
| }, | |
| lineEnd = { | |
| x: line[1][0], | |
| y: line[1][1] |