diff --git a/dist/core/pt-core.js b/dist/core/pt-core.js index ca35dd3..7e6ff26 100644 --- a/dist/core/pt-core.js +++ b/dist/core/pt-core.js @@ -722,14 +722,14 @@ this.Space = Space; CanvasSpace = (function(superClass) { extend(CanvasSpace, superClass); - function CanvasSpace(id, callback) { + function CanvasSpace(elem, callback) { this._resizeHandler = bind(this._resizeHandler, this); - var _existed, _selector, b; - if (!id) { - id = 'pt'; + var _existed, _selector, b, isElement; + if (!elem) { + elem = 'pt'; } - CanvasSpace.__super__.constructor.call(this, id); - this.id = this.id[0] === "#" ? this.id.substr(1) : this.id; + isElement = elem instanceof Element; + CanvasSpace.__super__.constructor.call(this, isElement ? "pt_custom_space" : elem); this.space = null; this.bound = null; this.boundRect = { @@ -740,8 +740,14 @@ CanvasSpace = (function(superClass) { }; this.pixelScale = 1; this._autoResize = true; - _selector = document.querySelector("#" + this.id); - _existed = true; + _selector = null; + if (isElement) { + _selector = elem; + } else { + this.id = this.id[0] === "#" ? this.id.substr(1) : this.id; + _selector = document.querySelector("#" + this.id); + _existed = true; + } if (!_selector) { this.bound = this._createElement("div", this.id + "_container"); this.space = this._createElement("canvas", this.id); @@ -900,17 +906,17 @@ this.CanvasSpace = CanvasSpace; DOMSpace = (function(superClass) { extend(DOMSpace, superClass); - function DOMSpace(id, callback, spaceElement) { - var _selector; + function DOMSpace(elem, callback, spaceElement) { + var _selector, isElement; if (spaceElement == null) { spaceElement = "div"; } this._resizeHandler = bind(this._resizeHandler, this); - if (!id) { - id = 'pt'; + if (!elem) { + elem = 'pt'; } - DOMSpace.__super__.constructor.call(this, id); - this.id = this.id[0] === "#" ? this.id.substr(1) : this.id; + isElement = elem instanceof Element; + DOMSpace.__super__.constructor.call(this, isElement ? "pt_custom_space" : elem); this.space = null; this.bound = null; this.boundRect = { @@ -920,7 +926,13 @@ DOMSpace = (function(superClass) { height: 0 }; this.css = {}; - _selector = document.querySelector("#" + this.id); + _selector = null; + if (isElement) { + _selector = elem; + } else { + this.id = this.id[0] === "#" ? this.id.substr(1) : this.id; + _selector = document.querySelector("#" + this.id); + } if (!_selector) { this.space = this._createElement(spaceElement, this.id); document.body.appendChild(this.space); diff --git a/dist/core/pt-core.js.map b/dist/core/pt-core.js.map index 5e18ec3..ba58187 100644 --- a/dist/core/pt-core.js.map +++ b/dist/core/pt-core.js.map @@ -1 +1 @@ -{"version":3,"sources":["pt-core.coffee"],"names":[],"mappings":";AACA;AAAA,IAAA,iMAAA;EAAA;;;;;AAGM;;;EAGJ,KAAC,CAAA,EAAD,GAAM;;EAGN,KAAC,CAAA,EAAD,GAAM;;EAGN,KAAC,CAAA,EAAD,GAAM;;EAGN,KAAC,CAAA,GAAD,GAAO;;EAGP,KAAC,CAAA,SAAD,GAAa,CAAC;;EAGd,KAAC,CAAA,KAAD,GAAS;;EAGT,KAAC,CAAA,YAAD,GAAgB;;EAGhB,KAAC,CAAA,MAAD,GAAU;;EAGV,KAAC,CAAA,WAAD,GAAe;;EAGf,KAAC,CAAA,IAAD,GAAQ;;EAGR,KAAC,CAAA,QAAD,GAAY;;EAGZ,KAAC,CAAA,GAAD,GAAO;;EAGP,KAAC,CAAA,SAAD,GAAa;;EAGb,KAAC,CAAA,UAAD,GAAc,CAAC,WAAD,EAAc,OAAd,EAAuB,cAAvB,EAAuC,QAAvC,EAAiD,aAAjD,EAAgE,MAAhE,EAAwE,UAAxE,EAAoF,KAApF,EAA2F,WAA3F;;EAGd,KAAC,CAAA,OAAD,GAAY;;EAGZ,KAAC,CAAA,EAAD,GAAM,IAAI,CAAC;;EAGX,KAAC,CAAA,MAAD,GAAW;;EAGX,KAAC,CAAA,OAAD,GAAY;;EAGZ,KAAC,CAAA,UAAD,GAAe;;EAGf,KAAC,CAAA,UAAD,GAAc;;EAGd,KAAC,CAAA,UAAD,GAAc;;EAGd,KAAC,CAAA,UAAD,GAAc;;EAGd,KAAC,CAAA,OAAD,GAAW;;EAGX,KAAC,CAAA,MAAD,GAAU;;EAGV,KAAC,CAAA,QAAD,GAAY;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,SAAC,IAAD,EAAO,OAAP;;MAAO,UAAQ;;AACjC,WAAO,IAAI,CAAC,cAAL,CAAqB,IAAC,CAAA,KAAD,CAAA,CAArB,EAA+B,OAA/B;EADW;;qBAQpB,eAAA,GAAiB,SAAC,MAAD,EAAS,OAAT;;MAAS,UAAQ;;AAChC,WAAO,MAAM,CAAC,cAAP,CAAuB,IAAC,CAAA,KAAD,CAAA,CAAvB,EAAiC,OAAjC;EADQ;;qBAQjB,iBAAA,GAAmB,SAAC,GAAD,EAAM,OAAN;;MAAM,UAAQ;;AAC/B,WAAO,GAAG,CAAC,cAAJ,CAAoB,IAAC,CAAA,KAAD,CAAA,CAApB,EAA8B,OAA9B;EADU;;qBAKnB,KAAA,GAAO,SAAA;WAAU,IAAA,QAAA,CAAS,IAAT,CAAW,CAAC,EAAZ,CAAgB,IAAC,CAAA,EAAjB,EAAqB,IAAC,CAAA,EAAtB;EAAV;;;;GAnVc;;AAuVvB,IAAI,CAAC,QAAL,GAAgB","file":"pt-core.js","sourceRoot":"/source/","sourcesContent":["\n### Licensed under the Apache License, Version 2.0. (http://www.apache.org/licenses/LICENSE-2.0). Copyright 2015-2016 William Ngan. (https://github.com/williamngan/pt/) ###\n\n# ### A list of useful constant values for calculations and labeling.\r\nclass Const\r\n\r\n # ## represents the xy plane\r\n @xy = 'xy'\r\n\r\n # ## represents the yz plane\r\n @yz = 'yz'\r\n\r\n # ## reporesents the xz plane\r\n @xz = 'xz'\r\n\r\n # ## represents xyz space\r\n @xyz = 'xyz'\r\n\r\n # ## represents identical point or value\r\n @identical = -1\r\n\r\n # ## represents right position or direction\r\n @right = 3\r\n\r\n # ## represents bottom right position or direction\r\n @bottom_right = 4\r\n\r\n # ## represents bottom position or direction\r\n @bottom = 5\r\n\r\n # ## represents bottom left position or direction\r\n @bottom_left = 6\r\n\r\n # ## represents left position or direction\r\n @left = 7\r\n\r\n # ## represents top left position or direction\r\n @top_left = 0\r\n\r\n # ## represents top position or direction\r\n @top = 1\r\n\r\n # ## represents top right position or direction\r\n @top_right = 2\r\n\r\n # ## an array of strings to label position constants above. Eg, `Const.sideLabels[ Const.top_left]` will return the string \"top left\"\r\n @sideLabels = [\"identical\", \"right\", \"bottom right\", \"bottom\", \"bottom left\", \"left\", \"top left\", \"top\", \"top right\"]\r\n\r\n # ## represents an arbitrary very small number. It is set as 0.0001 here.\r\n @epsilon = 0.0001\r\n\r\n # ## pi radian (180 deg)\r\n @pi = Math.PI\r\n\r\n # ## two pi radian (360deg)\r\n @two_pi = 6.283185307179586\r\n\r\n # ## half pi radian (90deg)\r\n @half_pi = 1.5707963267948966\r\n\r\n # ## pi/4 radian (45deg)\r\n @quarter_pi = 0.7853981633974483\r\n\r\n # ## pi/180 = 1 degree in radian\r\n @one_degree = 0.017453292519943295\r\n\r\n # ## multiply this constant with a radian to get a degree\r\n @rad_to_deg = 57.29577951308232\r\n\r\n # ## multiply this constant with a degree to get a radian\r\n @deg_to_rad = 0.017453292519943295\r\n\r\n # ## Gravity acceleration (unit = m/s^2) and gravity force (unit = Newton) on 1kg of mass.\r\n @gravity = 9.81\r\n\r\n # ## 1 Newton = 0.10197 Kilogram-force\r\n @newton = 0.10197\r\n\r\n # ## Gaussian constant (1 / Math.sqrt(2 * Math.PI))\r\n @gaussian = 0.3989422804014327\r\n\r\n\r\n\r\n# namespace\r\nthis.Const = Const\n# ### Functions to calculate various Matrix transformations\r\nclass Matrix\r\n\r\n # ## Get a 3x3 matrix for 2D rotation around an anchor point\r\n # @param `radian` rotation angle in radian\r\n # @param `anchor` anchor point of rotation\r\n # @return an array representing a 3x3 matrix. Apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @rotateAnchor2D: ( radian, anchor, axis=Const.xy ) ->\r\n a = anchor.get2D( axis )\r\n cosA = Math.cos( radian )\r\n sinA = Math.sin( radian )\r\n return [\r\n cosA, sinA, 0\r\n -sinA, cosA, 0\r\n a.x*(1-cosA) + a.y*sinA, a.y*(1-cosA)-a.x*sinA, 1\r\n ]\r\n\r\n\r\n # ## Get a 3x3 matrix to reflect a point along a line. See also `Line.reflect()` for a potentially simpler calculation\r\n # @param `line` the path to define the reflection\r\n # @return an array representing a 3x3 matrix. apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @reflectAnchor2D: ( line, axis=Const.xy ) ->\r\n inc = line.intercept( axis )\r\n ang2 = Math.atan( inc.slope ) * 2\r\n cosA = Math.cos( ang2 )\r\n sinA = Math.sin( ang2 )\r\n return [\r\n cosA, sinA, 0\r\n sinA, -cosA, 0\r\n -inc.yi*sinA, inc.yi + inc.yi*cosA, 1\r\n ]\r\n\r\n\r\n # ## Get a 3x3 matrix for 2D shear from an anchor point\r\n # @param `sx, sy` shear scale values, usually between -1 to 1, where 0 means no change in shear.\r\n # @param `anchor` anchor point of shearing\r\n # @return an array representing a 3x3 matrix. apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @shearAnchor2D: (sx, sy, anchor, axis=Const.xy ) ->\r\n a = anchor.get2D( axis )\r\n tx = Math.tan( sx )\r\n ty = Math.tan( sy )\r\n\r\n return [\r\n 1, tx, 0\r\n ty, 1, 0\r\n -a.y*ty, -a.x*tx, 1\r\n ]\r\n\r\n\r\n # ## Get a 3x3 matrix for 2D scale from an anchor point\r\n # @param `sx, sy` horizontal and vertical scale values, which are usually between 0 to N, where 1 means no change in scale.\r\n # @param `anchor` anchor point of scaling\r\n # @return an array representing a 3x3 matrix. apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @scaleAnchor2D: (sx, sy, anchor, axis=Const.xy ) ->\r\n a = anchor.get2D( axis )\r\n return [\r\n sx, 0, 0,\r\n 0, sy, 0,\r\n -a.x*sx + a.x, -a.y*sy + a.y, 1\r\n ]\r\n\r\n\r\n # ## Get a 3x3 scale matrix\r\n # @param `x, y` horizontal and vertical scale values, which are usually between 0 to N, where 1 means no change in scale.\r\n # @return an array representing a 3x3 matrix. apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @scale2D: ( x, y ) ->\r\n return [\r\n x, 0, 0,\r\n 0, y, 0,\r\n 0, 0, 1\r\n ]\r\n\r\n\r\n # ## Get a 3x3 shear matrix\r\n # @param `x, y` shear scale values, usually between -1 to 1, where 0 means no change in shear.\r\n # @return an array representing a 3x3 matrix. apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @shear2D: (x, y ) ->\r\n return [\r\n 1, Math.tan(x), 0\r\n Math.tan(y), 1, 0\r\n 0, 0, 1\r\n ]\r\n\r\n # ## Get a 3x3 rotate matrix\r\n # @param `cosA, sinA` cosine and sine of the rotation angle.\r\n # @return an array representing a 3x3 matrix. apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @rotate2D: ( cosA, sinA ) ->\r\n return [\r\n cosA, sinA, 0,\r\n -sinA, cosA, 0,\r\n 0, 0, 1\r\n ]\r\n\r\n\r\n # ## Get a 3x3 translate matrix.\r\n # @param `x, y` horizontal and vertical offsets to move by\r\n # @return an array representing a 3x3 matrix. apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @translate2D: ( x, y ) ->\r\n return [\r\n 1, 0, 0\r\n 0, 1, 0\r\n x, y, 1\r\n ]\r\n\r\n\r\n # ## Calculate a 2D transform by applying matrix to a homogeneous vector\r\n # @param `pt` a Point to transform\r\n # @param `m` an array representing 3x3 matrix\r\n # @param `byValue` a boolean value to update the values of `pt` parameter directly if set to true. If false, returns a new Vector object instead. Default is false.\r\n # @return a Vector object, or the `pt` object if `byValue` is true\r\n @transform2D: (pt, m, axis=Const.xy, byValue=false) ->\r\n v = pt.get2D( axis )\r\n x = v.x * m[0] + v.y * m[3] + m[6];\r\n y = v.x * m[1] + v.y * m[4] + m[7];\r\n # z = v.x * m[2] + v.y * m[5] + m[8];\r\n v.x = x\r\n v.y = y\r\n # v.z = z\r\n v = v.get2D(axis, true)\r\n\r\n if !byValue\r\n pt.set(v)\r\n return pt\r\n\r\n return v\r\n\r\n\r\n# namescope\r\nthis.Matrix = Matrix\n# ### A collection of static methods and helper classes to get things done.\r\nclass Util\r\n\r\n # ## A static function to convert degrees to radian\r\n # @param `degree` angle in degrees. ie, 180 degrees = Math.PI radian\r\n @toRadian : ( angle ) -> angle * Const.deg_to_rad\r\n\r\n\r\n # ## A static function to convert radian to degrees\r\n # @param `radian` angle in radian. ie, Math.PI radian = 180 degrees\r\n @toDegree : ( radian ) -> radian * Const.rad_to_deg\r\n\r\n\r\n # ## A static function to convert a color value (0-255) to hex \"FF\". See also `Color.hex()` and `Color.rgba()`\r\n # @param `number` a value between 0 to 255\r\n # @return a string with 2 hex digits, such as \"FF\" or \"00\"\r\n @toHexColor: (number) ->\r\n h = Math.floor(number).toString(16)\r\n return if h.length is 1 then \"0\"+h else h\r\n\r\n\r\n # ## A static function to convert a hex string to rgb value or string. See also `Color.parseHex()`\r\n # @param hexString hex string such as \"FF9900\" or \"#FF9900\"\r\n # @param asRGBA a boolean value to set if the return value should be `rgba(...)` string\r\n # @param opacity optional opacity value between 0 to 1 for `rgba(...)` output\r\n # @eg `Util.toRGBColor(\"\")`\r\n @toRGBColor: (hexString, asRGBA=false, opacity=1) ->\r\n if hexString[0] == \"#\" then hexString = hexString.substr(1)\r\n\r\n if hexString.length == 3\r\n r = parseInt( hexString[0]+hexString[0], 16 )\r\n g = parseInt( hexString[1]+hexString[1], 16 )\r\n b = parseInt( hexString[2]+hexString[2], 16 )\r\n else if hexString.length >= 6\r\n r = parseInt( hexString[0]+hexString[1], 16 )\r\n g = parseInt( hexString[2]+hexString[3], 16 )\r\n b = parseInt( hexString[4]+hexString[5], 16 )\r\n else\r\n r = 0\r\n g = 0\r\n b = 0\r\n\r\n return if asRGBA then \"rgba(#{r},#{g},#{b},#{opacity})\" else [r,g,b,opacity]\r\n\r\n\r\n # ## A static function to limit a value (such as an angle, can be negative) as the modulus between 0 to max, or between -max/2 to max/2\r\n # @param `val` the value to be bound\r\n # @param `max` maximum value as boundary\r\n # @param `positive` a boolean value. If set to `true`, the return value will be between 0 to max; if `false`, return value will be between -max/2 to max/2. Default is `false`.\r\n # @return a value either (0 to max) or (-max/2 to max/2)\r\n @bound : ( val, max, positive=false ) ->\r\n a = val % max\r\n half = max / 2\r\n\r\n if a>half\r\n a -= max\r\n else if a < -half\r\n a += max\r\n\r\n if positive\r\n if a<0 then return a+max else return a\r\n else\r\n return a\r\n\r\n\r\n # ## A static function to limit an angle\r\n # @param `ang` an angle to be bound\r\n # @param `positive` a boolean value. If set to `true`, the return value will be between 0 to max; if `false`, return value will be between -max/2 to max/2. Default is `false`.\r\n # @return an angle either between 0 to 360, or between -180 to 180 degrees\r\n @boundAngle : ( ang, positive ) ->\r\n Util.bound( ang, 360, positive)\r\n\r\n\r\n # ## A static function similar to `Util.boundAngle` but limit a radian angle between 0 to 2*PI, or between -PI to PI\r\n @boundRadian : ( radian, positive ) ->\r\n Util.bound( radian, Const.two_pi, positive )\r\n\r\n\r\n # ## A static function to get a bounding box for a list of points\r\n # @param `points` an array of points\r\n # @param `is3D` a boolean value to specify if the points are 3D. Default is false which means the points are 2D.\r\n # @return an Rectangle object as bounding box\r\n @boundingBox: ( points, is3D=false ) ->\r\n minPt = new Point( Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY)\r\n maxPt = new Point( Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY)\r\n for p in points\r\n if p.x < minPt.x then minPt.x = p.x\r\n if p.y < minPt.y then minPt.y = p.y\r\n if p.x > maxPt.x then maxPt.x = p.x\r\n if p.y > maxPt.y then maxPt.y = p.y\r\n\r\n if is3D\r\n if p.z < minPt.z then minPt.z = p.z\r\n if p.z > maxPt.z then maxPt.z = p.z\r\n\r\n return new Rectangle( minPt ).to( maxPt )\r\n\r\n\r\n # ## A static function to get linear interpolation between two values\r\n # @param `a, b` first and second values\r\n # @param `t` a value between 0 to 1\r\n # return the interpolated value\r\n @lerp: ( a, b, t ) -> return (1-t) * a + t * b\r\n\r\n\r\n # ## Get a centroid point which is the averge positions of a list of points.\r\n # @param `points` an array of points\r\n # @return the centroid point as Vector\r\n @centroid: (points) ->\r\n c = new Vector()\r\n for p in points\r\n c.add( p )\r\n return c.divide( points.length )\r\n\r\n\r\n # ## Check if two numbers are equal within a threshold\r\n # @param `a, b` two numbers to compare\r\n # @param `threshold` the smallest difference allowed to be considered as same. Default is `Const.epsilon`.\r\n # @return a boolean value where `true` means they are the same\r\n @same : (a, b, threshold=Const.epsilon ) ->\r\n ( Math.abs( a - b ) < threshold )\r\n\r\n\r\n # ## Check is a number is within the range of two number\r\n # @param `p` the number to check\r\n # @param `a, b` two numbers to set the range\r\n # @return a boolean value where `true` means the number is within range\r\n @within: ( p, a, b) ->\r\n return p >= Math.min(a, b) and p <= Math.max(a, b)\r\n\r\n\r\n # ## Get a random value in between a range\r\n # @param `a, b` two numbers to set a range. `b` is optional and defaults to 0.\r\n # @return a random number within the range\r\n @randomRange : (a, b=0) ->\r\n r = if a > b then ( a - b ) else ( b - a )\r\n return a + Math.random() * r\r\n\r\n\r\n # ## Simple mixin implementataion\r\n # @param `klass` the class to inject\r\n # @param `mix` is the source mixin object\r\n # @return the klass with mixin\r\n @mixin : ( klass, mix ) ->\r\n for k,v of mix\r\n if mix.hasOwnProperty( k )\r\n klass.prototype[k] = mix[k]\r\n return klass\r\n\r\n\r\n # ## A helper function to extend a class\r\n # @param `klass` constructor function\r\n # @param `parent` class to inherit\r\n # @eg `function V() { Vector.call(this, arguments); }; Util.extend(V, Vector);`\r\n # @return the extended class\r\n @extend: (klass, parent) ->\r\n klass.prototype = Object.create(parent.prototype)\r\n klass.prototype.constructor = klass\r\n return klass\r\n\r\n\r\n # ## Given an array of Points (eg, in results of toArray() ), return an array of the points as copy\r\n @clonePoints: (array) -> ( p.clone() for p in array )\r\n\r\n\r\n # ## Rotate from an origin using canvas rendering context\r\n # @param `ctx` canvas rendering context\r\n # @param `bound` the bounding box as Rectangle object\r\n # @param `radian` the angle in radian to rotate\r\n # @param `origin` an optional Point object to specify the anchor point of rotation. If origin is false or not set, the anchor is at the center of the `bound` bounding box\r\n # @param `mask` an optional Rectangle object as mask\r\n @contextRotateOrigin : (ctx, bound, radian, origin=false, mask) ->\r\n\r\n size = bound.size()\r\n\r\n if !origin\r\n origin = size.$multiply(0.5)\r\n origin.add(bound)\r\n\r\n if mask\r\n msz = mask.size()\r\n Form.rect(ctx, mask)\r\n ctx.clip()\r\n\r\n ctx.translate( origin.x, origin.y )\r\n ctx.rotate( radian )\r\n ctx.translate( -origin.x, -origin.y)\r\n\r\n\r\n # ## A static function to pre-calculate a sine and cosine table. To use this, convert radian to angle as an integer, and then get table index by finding modulus `angle%360`\r\n # @return an object with `{sin, cos}` properties.\r\n @sinCosTable: () ->\r\n cos = []\r\n sin = []\r\n for i in [0..360] by 1\r\n cos[i] = Math.cos( i * Math.PI / 180 )\r\n sin[i] = Math.sin( i * Math.PI / 180 )\r\n return {sin: sin, cos: cos}\r\n\r\n\r\n # ## A static function which check if a random number from 0 to 1 is smaller than a user defined number\r\n # @param `p` a value between 0 to 1\r\n # @return a boolean value where true means a random number is smaller than the supplied parameter\r\n @chance: (p) -> return (Math.random() < p);\r\n\r\n\r\n # ## A static function to calculate Gaussian curve\r\n @gaussian: (x, mean=0, sigma=1) ->\r\n x = (x - mean) / sigma\r\n return Const.gaussian * Math.exp( -0.5 * x * x) / sigma\r\n\r\n\r\n # ## Map a value from one range to another\r\n # @param `n` a value in the first range\r\n # @param `min1` lower bound of the first range\r\n # @param `max1` upper bound of the first range\r\n # @param `min2` lower bound of the second range\r\n # @param `max2` upper bound of the second range\r\n # @return a remapped value in the second range\r\n @mapToRange: (n, min1, max1, min2, max2) ->\r\n if (min1 == max1) then throw \"[min1, max1] must be a non-degenerate interval (that is, min1 != max1)\"\r\n return ( (n - min1) / (max1 - min1) ) * (max2 - min2) + min2;\r\n\r\n\r\n# namespace\r\nthis.Util = Util;\r\n\n# ### Use a timer not to measure time, but to introduce rhythm. The conceptual hums of \"one two three, one two three\", when transfigured into patterns of sounds or words or dances, gives rise to various forms of aesthetic experiences. If time is a river, then timers are the mills we build along its banks.\r\nclass Timer\r\n\r\n # ## Create a Timer\r\n # @param `d` duration of the timer in milliseconds\r\n constructor: ( d=1000 ) ->\r\n @duration = d\r\n @_time = 0\r\n @_ease = (t,b,c,d) -> t/d\r\n @_intervalID = -1\r\n\r\n\r\n # ## Start or restart the timer\r\n # @param `reset` a boolean value to restart the timer from the beginning if set to `true`.\r\n start: (reset) ->\r\n diff = Math.min( Date.now() - @_time, @duration)\r\n\r\n if reset or diff >= @duration\r\n @_time = Date.now()\r\n\r\n\r\n # set an easing function to use in `check()`. See `Easing` class for a set of predefined easing functions\r\n # @param `ease` an easing function with 4 parameters `(current_time, start_value, change_in_value, duration_time)` and must return a number between 0 to 1\r\n setEasing: (ease) ->\r\n @_ease = ease\r\n\r\n\r\n # ## Check % of time that has elapsed currently.\r\n # @return a number between 0 to 1\r\n check: () ->\r\n diff = Math.min( Date.now() - @_time, @duration)\r\n return @_ease( diff, 0, 1, @duration )\r\n\r\n\r\n # Track time (using `setInterval()`)\r\n # @param `callback` a callback function which may include a `(t)` parameter to get current elapsed percentage (value between 0 to 1)\r\n # @return the intervalID from `setInterval()`\r\n track: ( callback ) ->\r\n clearInterval( @_intervalID )\r\n @start(true)\r\n me = @\r\n @_intervalID = setInterval( ( () ->\r\n t = me.check()\r\n callback( t )\r\n if t >= 1 then clearInterval( me._intervalID )\r\n ), 25 )\r\n return @_intervalID\r\n\r\n\r\n\r\n# namespace\r\nthis.Timer = Timer\n# ### Fishes forget their rivers and lakes, said Chuang Tzu. Spaces or contexts give meanings to ideas and lives, but are often overlooked. In Pt, space represents an abstract context in which a point can be made visible in one form or another, and can be specified as an html canvas, a soundscape, or a graffiti robot on a wall. Space is where a concept meets its expression.\r\n\r\nclass Space\r\n\r\n # ## Create a Space which is the context for displaying and animating elements. Extend this to create specific Spaces, for example, a space for HTML Canvas or SVG.\r\n # @param `id` an id property to identify this space\r\n constructor : ( id ) ->\r\n\r\n if typeof id != 'string' or id.length == 0\r\n throw \"id parameter is not valid\"\r\n return false\r\n\r\n # ## A property to identify this space by name\r\n @id = id\r\n\r\n # ## A property to indicate the size of this space as a Vector\r\n @size = new Vector()\r\n\r\n # ## A property to indicate the center of this space as a Vector\r\n @center = new Vector()\r\n\r\n # animation properties\r\n @_timePrev = 0 # record prev time\r\n @_timeDiff = 0 # record prev time difference\r\n @_timeEnd = -1 # end in milliseconds, -1 to play forever, 0 to end immediately\r\n\r\n # ## A set of items in this space. An item should implement a function `animate()` and optionally another callback `onSpaceResize(w,h,evt)`, and will be assigned a property `animateID` automatically. (See `add()`)\r\n @items = {}\r\n\r\n # item properties\r\n @_animID = -1\r\n @_animCount = 0 # player key as increment\r\n @_animPause = false\r\n @_refresh = true # refresh on each frame\r\n\r\n\r\n # ## set whether the rendering should be repainted on each frame\r\n # @param `b` a boolean value to set whether to repaint each frame\r\n # @demo space.refresh\r\n # @return this space\r\n refresh: (b) ->\r\n @_refresh = b\r\n return @\r\n\r\n\r\n # ## set custom render function (on resize and other events)\r\n # @return this space\r\n render: ( context ) ->\r\n return @\r\n\r\n\r\n # ## resize the space. (not implemented)\r\n resize: (w, h) ->\r\n\r\n\r\n # ## clear all contents in the space (not implemented)\r\n clear: () ->\r\n\r\n\r\n # ## Add an item to this space. An item must define a callback function `animate( time, fps, context )` and will be assigned a property `animateID` automatically. An item can also optionally define a callback function `onSpaceResize( w, h, evt )`. Subclasses of Space may define other callback functions.\r\n # @param an object with an `animate( time, fps, context )` function, and optionall a `onSpaceResize( w, h, evt )` function\r\n # @demo space.add\r\n # @return this space\r\n add : (item) ->\r\n if item.animate? and typeof item.animate is 'function'\r\n k = @_animCount++\r\n @items[k] = item\r\n item.animateID = k\r\n\r\n # if player has onSpaceResize defined, call the function\r\n if item.onSpaceResize? then item.onSpaceResize(@size.x, @size.y)\r\n else\r\n throw \"a player object for Space.add must define animate()\"\r\n\r\n return @\r\n\r\n\r\n # ## Remove an item from this Space\r\n # @param an object with an auto-assigned `animateID` property\r\n # @return this space\r\n remove : (item) ->\r\n delete @items[ item.animateID ]\r\n return @\r\n\r\n\r\n # ## Remove all items from this Space\r\n # @return this space\r\n removeAll : () ->\r\n @items = {}\r\n return @\r\n\r\n\r\n # ## Main play loop. This implements window.requestAnimationFrame and calls it recursively. Override this `play()` function to implemenet your own animation loop.\r\n # @param `time` current time\r\n # @return this space\r\n play : (time=0) ->\r\n\r\n # use fat arrow here, because rAF callback will change @ to window\r\n @_animID = requestAnimationFrame( (t) => @play(t) )\r\n\r\n # if pause\r\n if @_animPause then return\r\n\r\n # calc time passed since prev frame\r\n @_timeDiff = time - @_timePrev\r\n\r\n # animate this frame\r\n try\r\n @_playItems( time )\r\n catch err\r\n cancelAnimationFrame( @_animID )\r\n console.error( err.stack )\r\n throw err\r\n\r\n\r\n # store time\r\n @_timePrev = time\r\n\r\n return @\r\n\r\n\r\n # Main animate function. This calls all the items to perform\r\n # @param `time` current time\r\n # @return this space\r\n _playItems : (time) ->\r\n\r\n # clear before draw if refresh is true\r\n if @_refresh then @clear()\r\n\r\n # animate all players\r\n for k, v of @items\r\n v.animate( time, @_timeDiff, @ctx )\r\n\r\n # stop if time ended\r\n if @_timeEnd >= 0 and time > @_timeEnd\r\n cancelAnimationFrame( @_animID )\r\n\r\n return @\r\n\r\n\r\n # ## Pause the animation\r\n # @param `toggle` a boolean value to set if this function call should be a toggle (between pause and resume)\r\n # @return this space\r\n pause: ( toggle=false) ->\r\n @_animPause = if toggle then !@_animPause else true\r\n return @\r\n\r\n\r\n # ## Resume the paused animation\r\n # @return this space\r\n resume: () ->\r\n @_animPause = false\r\n return @\r\n\r\n\r\n # ## Specify when the animation should stop: immediately, after a time period, or never stops.\r\n # @param `t` a value in millisecond to specify a time period to play before stopping, or `-1` to play forever, or `0` to end immediately. Default is 0 which will stop the animation immediately.\r\n # @return this space\r\n stop : ( t=0 ) ->\r\n @_timeEnd = t\r\n return @\r\n\r\n\r\n # ## Play animation loop, and then stop after `duration` time has passed.\r\n # @param `duration` a value in millisecond to specify a time period to play before stopping, or `-1` to play forever\r\n playTime: (duration=5000) ->\r\n @play()\r\n @stop( duration )\r\n\r\n\r\n\r\n # ## Bind event listener in canvas element, for events such as mouse events\r\n # @param `evt` Event object\r\n # @param `callback` a callback function for this event\r\n bindCanvas: ( evt, callback ) ->\r\n if @space.addEventListener then @space.addEventListener( evt, callback )\r\n\r\n\r\n # ## A convenient method to bind (or unbind) all mouse events in canvas element. All item added to `items` property that implements an `onMouseAction` callback will receive mouse event callbacks. The types of mouse actions are: \"up\", \"down\", \"move\", \"drag\", \"drop\", \"over\", and \"out\".\r\n # @param `bind` a boolean value to bind mouse events if set to `true`. If `false`, all mouse events will be unbound. Default is true.\r\n # @demo canvasspace.bindMouse\r\n bindMouse: ( _bind=true ) ->\r\n if @space.addEventListener and @space.removeEventListener\r\n if _bind\r\n @space.addEventListener( \"mousedown\", @_mouseDown.bind(@) )\r\n @space.addEventListener( \"mouseup\", @_mouseUp.bind(@) )\r\n @space.addEventListener( \"mouseover\", @_mouseOver.bind(@) )\r\n @space.addEventListener( \"mouseout\", @_mouseOut.bind(@) )\r\n @space.addEventListener( \"mousemove\", @_mouseMove.bind(@) )\r\n else\r\n @space.removeEventListener( \"mousedown\", @_mouseDown.bind(@) )\r\n @space.removeEventListener( \"mouseup\", @_mouseUp.bind(@) )\r\n @space.removeEventListener( \"mouseover\", @_mouseOver.bind(@) )\r\n @space.removeEventListener( \"mouseout\", @_mouseOut.bind(@) )\r\n @space.removeEventListener( \"mousemove\", @_mouseMove.bind(@) )\r\n\r\n\r\n # ## A convenient method to bind (or unbind) all mobile touch events in canvas element. All item added to `items` property that implements an `onTouchAction` callback will receive touch event callbacks. The types of touch actions are the same as the mouse actions: \"up\", \"down\", \"move\", and \"out\".\r\n # @param `bind` a boolean value to bind touch events if set to `true`. If `false`, all touch events will be unbound. Default is true.\r\n bindTouch: ( _bind=true ) ->\r\n if @space.addEventListener and @space.removeEventListener\r\n if _bind\r\n @space.addEventListener( \"touchstart\", @_mouseDown.bind(@) )\r\n @space.addEventListener( \"touchend\", @_mouseUp.bind(@) )\r\n @space.addEventListener( \"touchmove\",\r\n ((evt) =>\r\n evt.preventDefault();\r\n @_mouseMove(evt)\r\n ) )\r\n @space.addEventListener( \"touchcancel\", @_mouseOut.bind(@) )\r\n else\r\n @space.removeEventListener( \"touchstart\", @_mouseDown.bind(@) )\r\n @space.removeEventListener( \"touchend\", @_mouseUp.bind(@) )\r\n @space.removeEventListener( \"touchmove\", @_mouseMove.bind(@) )\r\n @space.removeEventListener( \"touchcancel\", @_mouseOut.bind(@) )\r\n\r\n\r\n # ## A convenient method to convert the touch points in a touch event to an array of `Vectors`.\r\n # @param evt a touch event which contains touches, changedTouches, and targetTouches list.\r\n # @param which a string to select a touches list: \"touches\", \"changedTouches\", or \"targetTouches\". Default is \"touches\"\r\n # @return an array of Vectors, whose origin position (0,0) is offset to the top-left of this space.\r\n touchesToPoints: ( evt, which=\"touches\" ) ->\r\n if (!evt or !evt[which]) then return []\r\n return ( new Vector(t.pageX - this.boundRect.left, t.pageY - this.boundRect.top) for t in evt[which] )\r\n\r\n\r\n # go through all item in `items` and call its onMouseAction callback function\r\n _mouseAction: (type, evt) ->\r\n if (evt.touches || evt.changedTouches)\r\n for k, v of @items\r\n if v.onTouchAction?\r\n _c = evt.changedTouches and evt.changedTouches.length > 0\r\n px = if (_c) then evt.changedTouches.item(0).pageX else 0;\r\n py = if (_c) then evt.changedTouches.item(0).pageY else 0;\r\n v.onTouchAction( type, px, py, evt )\r\n else\r\n for k, v of @items\r\n if v.onMouseAction?\r\n px = evt.offsetX || evt.layerX;\r\n py = evt.offsetY || evt.layerY;\r\n v.onMouseAction( type, px, py, evt )\r\n\r\n\r\n # mouse down action\r\n _mouseDown: (evt) ->\r\n @_mouseAction( \"down\", evt )\r\n @_mdown = true\r\n\r\n\r\n # mouse up action\r\n _mouseUp: (evt) ->\r\n @_mouseAction( \"up\", evt )\r\n if @_mdrag then @_mouseAction( \"drop\", evt )\r\n @_mdown = false\r\n @_mdrag = false\r\n\r\n\r\n # mouse move action\r\n _mouseMove: (evt) ->\r\n @_mouseAction( \"move\", evt )\r\n if @_mdown\r\n @_mdrag = true\r\n @_mouseAction( \"drag\", evt )\r\n\r\n\r\n # mouse over action\r\n _mouseOver: (evt) ->\r\n @_mouseAction( \"over\", evt )\r\n\r\n\r\n # mouse out action\r\n _mouseOut: (evt) ->\r\n @_mouseAction( \"out\", evt )\r\n if @_mdrag then @_mouseAction( \"drop\", evt )\r\n @_mdrag = false\r\n\r\n\r\n# namespace\r\nthis.Space = Space\r\n\r\n\n# ### CanvasSpace is a space that represents a html canvas. It creates a new canvas or get an existing one in DOM by its id attribute. It also provide methods specific to html canvas, such as tracking resize and mouse position.\r\n\r\nclass CanvasSpace extends Space\r\n\r\n # ## Create a CanvasSpace which represents a HTML Canvas Space\r\n # @param `id` an optional string which refers to the \"id\" attribute of a DOM element. It can either refer to an existing ``, or a `
` container in which a new `` will be created. If left empty, a `
` will be added to DOM. Use css to customize its appearance if needed.\r\n # @param `callback` an optional callback `function(boundingBox, spaceElement)` to be called when canvas is appended and ready. A \"ready\" event will also be fired from the `` element when it's appended, which can be traced with `spaceInstance.space.addEventListener(\"ready\")`\r\n constructor : ( id, callback ) ->\r\n if (!id) then id = 'pt'\r\n super( id )\r\n\r\n @id = if (@id[0] == \"#\") then @id.substr(1) else @id\r\n\r\n # ## A property to store canvas DOM element\r\n @space = null\r\n @bound = null\r\n @boundRect = {top: 0, left: 0, width: 0, height: 0}\r\n\r\n @pixelScale = 1\r\n @_autoResize = true\r\n\r\n _selector = document.querySelector(\"#\"+@id)\r\n _existed = true\r\n\r\n # if selector is not defined, create a canvas\r\n if !_selector\r\n @bound = @_createElement( \"div\", @id+\"_container\" )\r\n @space = @_createElement(\"canvas\", @id)\r\n @bound.appendChild( @space )\r\n document.body.appendChild( @bound )\r\n _existed = false\r\n\r\n # if selector is not canvas, create a canvas inside it\r\n else if _selector.nodeName.toLowerCase() != \"canvas\"\r\n @bound = _selector\r\n @space = @_createElement(\"canvas\", @id+\"_canvas\" )\r\n @bound.appendChild( @space )\r\n\r\n # if selector is an existing canvas\r\n else\r\n @space = _selector\r\n @bound = @space.parentElement\r\n\r\n # size is known so set it immediately\r\n if _existed\r\n b = @bound.getBoundingClientRect()\r\n @resize( b.width, b.height )\r\n\r\n # Track mouse dragging\r\n @_mdown = false\r\n @_mdrag = false\r\n\r\n # no mutation observer, so we set a timeout for ready event\r\n setTimeout( @_ready.bind(@, callback), 50 )\r\n\r\n # A property to store canvas background color\r\n @bgcolor = \"#F3F7FA\"\r\n\r\n # A property to store canvas rendering contenxt\r\n @ctx = @space.getContext( '2d' )\r\n\r\n\r\n\r\n\r\n # A private function to create the canvas element. This will create a
if elem parameter is not set.\r\n _createElement: ( elem=\"div\", id ) ->\r\n d = document.createElement( elem )\r\n d.setAttribute(\"id\", id )\r\n return d\r\n\r\n\r\n # A private function to handle callbacks after DOM element is mounted\r\n _ready: ( callback ) ->\r\n\r\n if @bound\r\n # measurement of the bounds and resize to fit\r\n @boundRect = @bound.getBoundingClientRect()\r\n @resize( @boundRect.width, @boundRect.height )\r\n @autoResize( @_autoResize )\r\n\r\n if @bgcolor then @clear( @bgcolor )\r\n @space.dispatchEvent( new Event('ready') )\r\n\r\n if (callback and typeof callback == \"function\") then callback( @boundRect, @space )\r\n\r\n else\r\n throw \"Cannot initiate #\"+@id+\" element\"\r\n\r\n\r\n # ## `display(...)` is deprecated as of 0.2.0. You can now set the canvas element directly in the constructor, and customize it using `setup()`.\r\n display: () ->\r\n console.warn( \"space.display(...) function is deprecated as of version 0.2.0. You can now set the canvas element in the constructor. Please see the release note for details.\" )\r\n return @\r\n\r\n # ## Set up various options for CanvasSpace. The `opt` parameter is an object with the following fields. This is usually set during instantiation, eg `new CanvasSpace(...).setup( { opt } )`\r\n # @param `opt.bgcolor` a hex or rgba string to set initial background color of the canvas. You may also change it later with `clear()`\r\n # @param `opt.resize` a boolean to set whether `` size should auto resize to match its container's size. You can also set it manually with `autoSize()`\r\n # @param `opt.retina` a boolean to set if device pixel scaling should be used. This may make drawings on retina displays look sharper but may reduce performance slightly. Default is `true`.\r\n # @return this CanvasSpace\r\n setup: ( opt ) ->\r\n\r\n # graphics context\r\n # if opt.context then @ctx = @space.getContext( opt.context )\r\n\r\n # background color\r\n if opt.bgcolor then @bgcolor = opt.bgcolor;\r\n\r\n # auto resize canvas to fit its container\r\n @_autoResize = if (opt.resize != false) then true else false\r\n\r\n # check for retina pixel ratio\r\n @pixelScale = 1\r\n if (opt.retina != false)\r\n r1 = window.devicePixelRatio or 1\r\n r2 = @ctx.webkitBackingStorePixelRatio or @ctx.mozBackingStorePixelRatio or @ctx.msBackingStorePixelRatio or @ctx.oBackingStorePixelRatio or @ctx.backingStorePixelRatio || 1;\r\n @pixelScale = r1/r2\r\n\r\n return this\r\n\r\n\r\n # window resize handler\r\n _resizeHandler: (evt) =>\r\n @boundRect = @bound.getBoundingClientRect()\r\n @resize( @boundRect.width, @boundRect.height, evt )\r\n\r\n\r\n # ## Set whether the canvas element should resize when its container is resized. Default will auto size\r\n # @param `auto` a boolean value indicating if auto size is set. Default is `true`.\r\n # @return this CanvasSpace\r\n autoResize: (auto=true) ->\r\n # listen/unlisten for window resize event and callback\r\n if (auto)\r\n window.addEventListener( 'resize', @_resizeHandler )\r\n else\r\n window.removeEventListener( 'resize', @_resizeHandler )\r\n\r\n return @\r\n\r\n # ## This overrides Space's `resize` function. It's a callback function for window's resize event. Keep track of this with `onSpaceResize(w,h,evt)` callback in your added objects.\r\n # @demo canvasspace.resize\r\n # @return this CanvasSpace\r\n resize: (w, h, evt) ->\r\n\r\n w = Math.floor(w)\r\n h = Math.floor(h)\r\n\r\n @size.set(w, h)\r\n @center = new Vector( w/2, h/2 )\r\n @boundRect.width = w\r\n @boundRect.height = h\r\n\r\n # if retina, resize the canvas size and rescale\r\n @space.width = w * @pixelScale\r\n @space.height = h * @pixelScale\r\n @space.style.width = w + \"px\"\r\n @space.style.height = h + \"px\"\r\n\r\n if (@pixelScale != 1)\r\n @ctx.scale( @pixelScale, @pixelScale )\r\n\r\n\r\n # player resize callback\r\n for k, p of @items\r\n if p.onSpaceResize? then p.onSpaceResize(w, h, evt)\r\n\r\n # repaint canvas\r\n @render( @ctx )\r\n\r\n return @\r\n\r\n\r\n # ## Clear the canvas with its background color. Overrides Space's `clear` function.\r\n # @param `bg` Optionally specify a custom background color. If evaluated to false, it will use its `bgcolor` property as background color.\r\n # @return this CanvasSpace\r\n clear: ( bg ) ->\r\n\r\n if bg then @bgcolor = bg\r\n\r\n lastColor = @ctx.fillStyle\r\n\r\n if @bgcolor\r\n @ctx.fillStyle = @bgcolor;\r\n @ctx.fillRect( 0, 0, @size.x, @size.y )\r\n else\r\n @ctx.clearRect( 0, 0, @size.x, @size.y )\r\n\r\n @ctx.fillStyle = lastColor\r\n\r\n return @\r\n\r\n\r\n\r\n # ## Overrides Space's `animate` function for canvas\r\n # @param `time` current time\r\n # @return this CanvasSpace\r\n animate : (time) ->\r\n\r\n\r\n @ctx.save()\r\n\r\n if @_refresh then @clear()\r\n\r\n # animate all players\r\n for k, v of @items\r\n v.animate( time, @_timeDiff, @ctx )\r\n\r\n # stop if time ended\r\n if @_timeEnd >= 0 and time > @_timeEnd\r\n cancelAnimationFrame( @_animID )\r\n\r\n @ctx.restore()\r\n\r\n return @\r\n\r\n\r\n# namescape\r\nthis.CanvasSpace = CanvasSpace\n# ### DOMSpace is a space that represents a html dom. It is similar to CanvasSpace but usually used as a space for SVG or HTML.\r\n\r\nclass DOMSpace extends Space\r\n\r\n # ## Create a DOMSpace which represents a HTML DOM\r\n # @param `id` an id property which refers to the \"id\" attribute of the element in DOM.\r\n # @param `callback` an optional callback `function(boundingBox, spaceElement)` to be called when element is appended and ready. A \"ready\" event will also be fired from the space's element when it's appended, which can be tracked with `spaceInstance.space.addEventListener(\"ready\")`\r\n # @param `spaceElement` a string of space's dom element name, such as `\"div\"` or `\"svg\"` or . Default is `\"div\"`\r\n constructor: ( id, callback, spaceElement=\"div\" ) ->\r\n if (!id) then id = 'pt'\r\n super( id )\r\n\r\n @id = if (@id[0] == \"#\") then @id.substr(1) else @id\r\n\r\n # ## A property to store the DOM element\r\n @space = null\r\n @bound = null\r\n @boundRect = {top: 0, left: 0, width: 0, height: 0}\r\n\r\n @css = {};\r\n\r\n _selector = document.querySelector(\"#\"+@id)\r\n\r\n # if selector is not defined, create the spaceElement element\r\n if !_selector\r\n @space = @_createElement(spaceElement, @id)\r\n document.body.appendChild( @space )\r\n @bound = @space.parentElement\r\n\r\n # if selector is an existing element\r\n else\r\n @space = _selector\r\n @bound = @space.parentElement\r\n\r\n # Track mouse dragging\r\n @_mdown = false\r\n @_mdrag = false\r\n\r\n # no mutation observer, so we set a timeout for ready event\r\n setTimeout( @_ready.bind(@, callback), 50 )\r\n\r\n # A property to store background color\r\n @bgcolor = false\r\n\r\n # A property to store rendering contenxt\r\n @ctx = {}\r\n\r\n\r\n # A private function to create the dom element. This will create a
if elem parameter is not set.\r\n _createElement: ( elem=\"div\", id ) ->\r\n d = document.createElement( elem )\r\n d.setAttribute(\"id\", id )\r\n return d\r\n\r\n\r\n # A private function to handle callbacks after DOM element is mounted\r\n _ready: ( callback ) ->\r\n\r\n if @bound\r\n # measurement of the bounds and resize to fit\r\n @boundRect = @bound.getBoundingClientRect()\r\n @resize( @boundRect.width, @boundRect.height )\r\n @autoResize( @_autoResize )\r\n\r\n if @bgcolor\r\n @setCSS( \"backgroundColor\", @bgcolor )\r\n\r\n\r\n @updateCSS()\r\n\r\n @space.dispatchEvent( new Event('ready') )\r\n \r\n if (callback) then callback( @boundRect, @space )\r\n \r\n else\r\n throw \"Cannot initiate #\"+@id+\" element\"\r\n \r\n\r\n setCSS: ( key, val, isPx=false) ->\r\n @css[key] = (if isPx then \"#{val}px\" else val)\r\n return this\r\n\r\n\r\n updateCSS: () ->\r\n for k,v of @css\r\n @space.style[k] = v\r\n\r\n\r\n # ## `display(...)` is deprecated as of 0.2.0. You can now set the DOM element directly in the constructor, and customize it using `setup()`.\r\n display: () ->\r\n console.warn( \"space.display(...) function is deprecated as of version 0.2.0. You can now set the DOM element in the constructor. Please see the release note for details.\" )\r\n return @\r\n\r\n # ## Set up various options for DOMSpace. The `opt` parameter is an object with the following fields. This is usually set during instantiation, eg `new DOMSpace(...).setup( { opt } )`\r\n # @param `opt.bgcolor` a hex or rgba string to set initial background color of the element\r\n # @param `opt.resize` a boolean to set whether th element's size should auto resize to match its container's size. You can also set it manually with `autoSize()`\r\n # @return this DOMSpace\r\n setup: ( opt ) ->\r\n\r\n # background color\r\n if opt.bgcolor then @bgcolor = opt.bgcolor\r\n\r\n # auto resize element to fit its container\r\n @_autoResize = if (opt.resize != false) then true else false\r\n\r\n return @\r\n\r\n\r\n # window resize handler\r\n _resizeHandler: (evt) =>\r\n\r\n @boundRect = @bound.getBoundingClientRect()\r\n @resize( @boundRect.width, @boundRect.height, evt )\r\n\r\n\r\n\r\n # ## This overrides Space's `resize` function. It's a callback function for window's resize event when `autoResize` is true. Keep track of this with `onSpaceResize(w,h,evt)` callback in your added objects.\r\n # @return this DOMSpace\r\n resize: (w, h, evt) ->\r\n\r\n @size.set(w, h)\r\n @center = new Vector( w/2, h/2 )\r\n\r\n # player resize callback\r\n for k, p of @items\r\n if p.onSpaceResize? then p.onSpaceResize(w, h, evt)\r\n\r\n return @\r\n\r\n\r\n # ## Set whether the svg element should resize when its container is resized.\r\n # @param `auto` a boolean value indicating if auto size is set. Default is `true`.\r\n # @return this CanvasSpace\r\n autoResize: (auto=true) ->\r\n\r\n # listen/unlisten for window resize event and callback\r\n if (auto)\r\n @css['width'] = '100%'\r\n @css['height'] = '100%'\r\n window.addEventListener( 'resize', @_resizeHandler )\r\n else\r\n delete @css['width']\r\n delete @css['height']\r\n window.removeEventListener( 'resize', @_resizeHandler )\r\n\r\n return @\r\n\r\n\r\n # ## Clear the space. This removes all the child nodes inside `space`\r\n clear: () ->\r\n @space.innerHML = \"\"\r\n\r\n\r\n # ## Overrides Space's `animate` function\r\n # @param `time` current time\r\n # @return this CanvasSpace\r\n animate : (time) ->\r\n\r\n # animate all players\r\n for k, v of @items\r\n v.animate( time, @_timeDiff, @ctx )\r\n\r\n # stop if time ended\r\n if @_timeEnd >= 0 and time > @_timeEnd\r\n cancelAnimationFrame( @_animID )\r\n\r\n return @\r\n\r\n\r\n @attr: (elem, data) ->\r\n for k, v of data\r\n elem.setAttribute( k, v );\r\n\r\n\r\n @css: (data) ->\r\n str = \"\"\r\n for k, v of data\r\n if (v) then str += \"#{k}: #{v}; \"\r\n return str;\r\n\r\n\r\n# namescape\r\nthis.DOMSpace = DOMSpace\n# ### `SVGForm` visualizes forms in the `SVGSpace`.\r\nclass SVGForm\r\n\r\n @_domId = 0\r\n\r\n # ## Create a new Form which is based on SVG\r\n # @param `space` A space that has a valid context for this form. In this case, the space should represent an svg.\r\n # @return a new Form object\r\n constructor: ( space ) ->\r\n\r\n # ## a property to reference the space's rendering context\r\n @cc = space.ctx || {}\r\n\r\n # keep track of dom id names\r\n @cc.group = @cc.group || null\r\n @cc.groupID = \"ptx\"\r\n @cc.groupCount = 0\r\n @cc.currentID = \"ptx0\"\r\n\r\n # default style or false for no fill\r\n @cc.style = {\r\n fill: \"#999\"\r\n stroke: \"#666\"\r\n \"stroke-width\": 1\r\n \"stroke-linejoin\": false\r\n \"stroke-linecap\": false\r\n }\r\n @cc.font = \"11px sans-serif\"\r\n\r\n # ## a property to specify the current font size\r\n @cc.fontSize = 11\r\n\r\n # ## a property to specify the current font face\r\n @cc.fontFace = \"sans-serif\"\r\n\r\n\r\n # ## Set current fill style\r\n # @param `c` fill color. Default is `false` (transparent)\r\n # @eg `form.fill(\"#F90\")` `form.fill(\"rgba(0,0,0,.5\")` `form.fill(false)`\r\n # @return this Form\r\n fill: (c) ->\r\n @cc.style.fill = if c then c else false\r\n return @\r\n\r\n\r\n # ## Set current stroke style\r\n # @param `c` stroke color. Default is false (transparent)\r\n # @param `width` Optional value (can be floating point) to set line width\r\n # @param `joint` Optional string to set line joint style. Can be \"miter\", \"bevel\", or \"round\".\r\n # @param `cap` Optional string to set line joint style. Can be \"butt \", \"round\", or \"square\".\r\n # @eg `form.stroke(\"#F90\")` `form.stroke(\"rgba(0,0,0,.5\")` `form.stroke(false)` `form.stroke(\"#000\", 0.5, 'round')`\r\n # @return this Form\r\n stroke: (c, width, joint, cap) ->\r\n @cc.style.stroke = if c then c else false\r\n if width then @cc.style[\"stroke-width\"] = width\r\n if joint then @cc.style[\"stroke-linejoin\"] = joint\r\n if cap then @cc.style[\"stroke-linecap\"] = cap\r\n return @\r\n\r\n\r\n # ## Set this form's group scope by an ID, and optionally define the group's parent element. A group scope keeps track of DOM elements by their generated IDs, and updates their properties as needed. See also `enterScope()`.\r\n # @param `group_id` a string to use as prefix for the group's id. For example, group_id \"hello\" will create elements with id like \"hello-1\", \"hello-2\", etc\r\n # @param `group` optional dom element to define this group's parent element\r\n # @eg `form.scope(\"dot\")` `form.scope(\"dot\", elem)`\r\n # @demo svgform.scope\r\n # @return context object\r\n scope: ( group_id, group=false ) ->\r\n if (group) then @cc.group = group\r\n @cc.groupID = group_id\r\n @cc.groupCount = 0\r\n\r\n @nextID()\r\n return @cc\r\n\r\n\r\n # ## Set the current group scope to an item added into space, in order to keep track of any point, circle, etc created within it. The item must have an `animateID` property, so that elements created within the item will have generated IDs like \"item-{animateID}-{count}\".\r\n # @param `item` an item that's added to space (see `space.add(...)`) and has an `animateID` property\r\n # @return context object\r\n enterScope: ( item ) ->\r\n if (!item || item.animateID == null )\r\n throw \"getScope()'s item must be added to a Space, and has an animateID property. Otherwise, use scope() instead.\"\r\n return @scope( SVGForm._scopeID( item ) )\r\n\r\n\r\n # ## `getScope(...)` function is deprecated as of 0.2.0. Use `enterScope()` instead.\r\n getScope: ( item ) ->\r\n if !@_warn1\r\n console.warn( \"form.getScope(...) function is deprecated as of version 0.2.0. It is renamed as `enterScope()`.\" )\r\n @_warn1 = true\r\n return @enterScope( item )\r\n\r\n\r\n # ## Get next available id in the current group\r\n # @return an id string\r\n nextID: () ->\r\n @cc.groupCount++\r\n @cc.currentID = @cc.groupID+\"-\"+@cc.groupCount\r\n return @cc.currentID\r\n\r\n\r\n # ## A static function to context\r\n @id: (ctx) ->\r\n return ctx.currentID || \"p-\"+SVGForm._domId++\r\n\r\n\r\n # compose a scope id\r\n @_scopeID: (item) ->\r\n return \"item-\"+item.animateID\r\n\r\n # ## A static function to help adding style object to an element. This put all styles into `style` attribute instead of individual attributes, so that the styles can be parsed by Adobe Illustrator.\r\n # @param `elem` a dom element to add to\r\n # @param `styles` an object of style properties\r\n # @eg `SVGForm.style(elem, {fill: \"#f90\", stroke: false})`\r\n @style: (elem, styles) ->\r\n st = []\r\n\r\n for k,v of styles\r\n if (!v)\r\n if (k==\"fill\")\r\n st.push( \"fill: none\" )\r\n else if (k==\"stroke\")\r\n st.push( \"stroke: none\" )\r\n else\r\n st.push( k+\":\"+v )\r\n\r\n return DOMSpace.attr( elem, {style: st.join(\";\")} )\r\n\r\n\r\n # ## A static function to draw a point\r\n # @param `ctx` rendering context object\r\n # @param `pt` a Point object\r\n # @param `halfsize` radius or half size of the point. Default is 2.\r\n # @param `fill` not used - already defined in ctx\r\n # @param `stroke` not used - already defined in ctx\r\n # @param `circle` a boolean value to specify if the points should be drawn as a circle. Default to false.\r\n @point: (ctx, pt, halfsize=2, fill=true, stroke=true, circle=false ) ->\r\n\r\n elem = SVGSpace.svgElement( ctx.group, (if (circle) then \"circle\" else \"rect\"), SVGForm.id(ctx) )\r\n if (!elem) then return;\r\n\r\n if (circle)\r\n DOMSpace.attr( elem, {\r\n cx: pt.x\r\n cy: pt.y\r\n r: halfsize\r\n })\r\n else\r\n DOMSpace.attr( elem, {\r\n x: pt.x - halfsize\r\n y: pt.y - halfsize\r\n width: halfsize + halfsize\r\n height: halfsize + halfsize\r\n })\r\n\r\n SVGForm.style(elem, ctx.style)\r\n return elem\r\n\r\n\r\n # ## Draw a point\r\n # @param `p` a Point object\r\n # @param `halfsize` radius or half size of the point. Default is 2.\r\n # @param `isCircle` a boolean value to specify if the point should be drawn as a circle. Default is false.\r\n # @return this Form\r\n point: (p, halfsize=2, isCircle=false) ->\r\n @nextID()\r\n SVGForm.point(@cc, p, halfsize, true, true, isCircle )\r\n return @\r\n\r\n\r\n # ## A static function similar to `SVGForm.point()` but draw a series of points\r\n # @param `ctx` rendering context object\r\n # @param `pts` an array of Points\r\n # @param `halfsize, fill, stroke, circle` same parameters as in `SVGForm.point()`\r\n @points: (ctx, pts, halfsize=2, fill=true, stroke=true, circle=false ) ->\r\n return (SVGForm.point( ctx, p, halfsize, fill, stroke, circle ) for p in pts)\r\n\r\n\r\n # ## Draw a series of points\r\n # @param `ps` an array of Points\r\n # @param `halfsize` radius or half size of the point. Default is 2.\r\n # @param `isCircle` a boolean value to specify if the point should be drawn as a circle. Default is false.\r\n # @return this Form\r\n points: (ps, halfsize=2, isCircle=false) ->\r\n for p in ps\r\n @point(p, halfsize, isCircle )\r\n return @\r\n\r\n\r\n # ## A static function to draw a line\r\n # @param `ctx` rendering context object\r\n # @param `pair` a Pair object\r\n @line: (ctx, pair) ->\r\n if !pair.p1 then throw \"#{pair.toString()} is not a Pair\"\r\n elem = SVGSpace.svgElement( ctx.group, \"line\", SVGForm.id(ctx) )\r\n\r\n DOMSpace.attr( elem, {\r\n x1: pair.x\r\n y1: pair.y\r\n x2: pair.p1.x\r\n y2: pair.p1.y\r\n })\r\n\r\n SVGForm.style(elem, ctx.style)\r\n return elem\r\n\r\n\r\n # ## Draw a line\r\n # @param `p` a Pair object\r\n # @return this Form\r\n line: (p) ->\r\n @nextID()\r\n SVGForm.line( @cc, p )\r\n return @\r\n\r\n\r\n # ## A static function to draw a line\r\n # @param `ctx` rendering context object\r\n # @param `pairs` an array of Pair objects\r\n @lines: (ctx, pairs) ->\r\n return ( SVGForm.line( ctx, ln ) for ln in pairs )\r\n\r\n\r\n # ## Draw a series of lines\r\n # @param `ps` an array of Lines\r\n # @return this Form\r\n lines: (ps) ->\r\n for p in ps\r\n @line(p)\r\n return @\r\n\r\n\r\n # ## A static function to draw a rectangle\r\n # @param `ctx` rendering context object\r\n # @param `pair` a Pair object\r\n # @param `fill` not used - already defined in ctx\r\n # @param `stroke` not used - already defined in ctx\r\n @rect: (ctx, pair, fill=true, stroke=true) ->\r\n if !pair.p1 then throw \"#{pair.toString() is not a Pair}\"\r\n elem = SVGSpace.svgElement( ctx.group, \"rect\", SVGForm.id(ctx) )\r\n\r\n size = pair.size()\r\n DOMSpace.attr( elem, {\r\n x: pair.x\r\n y: pair.y\r\n width: size.x\r\n height: size.y\r\n })\r\n\r\n SVGForm.style(elem, ctx.style)\r\n return elem\r\n\r\n\r\n # ## Draw a rectangle\r\n # @param `p` a Pair object\r\n # @return this Form\r\n rect: (p, checkBounds=true) ->\r\n @nextID()\r\n r = if (checkBounds) then p.bounds() else p\r\n SVGForm.rect( @cc, r )\r\n return @\r\n\r\n\r\n # ## A static function to draw a circle\r\n # @param `ctx` rendering context object\r\n # @param `c` a Circle object\r\n # @param `fill` not used - already defined in ctx\r\n # @param `stroke` not used - already defined in ctx\r\n @circle: (ctx, c, fill=true, stroke=false) ->\r\n\r\n elem = SVGSpace.svgElement( ctx.group, \"circle\", SVGForm.id(ctx) )\r\n if (!elem) then return\r\n\r\n DOMSpace.attr( elem, {\r\n cx: c.x\r\n cy: c.y\r\n r: c.radius\r\n })\r\n\r\n SVGForm.style(elem, ctx.style)\r\n return elem\r\n\r\n\r\n # ## Draw a circle\r\n # @param `c` a Circle object\r\n # @demo svgform.circle\r\n # @return this Form\r\n circle: (c) ->\r\n @nextID()\r\n SVGForm.circle( @cc, c )\r\n return @\r\n\r\n\r\n\r\n # ## A static function to draw a polygon\r\n # @param `ctx` rendering context object\r\n # @param `pts` an array of Points\r\n # @param `closePath` a boolean value to specify if the path should be closed (joining last point with first point)\r\n # @param `fill` not used - already defined in ctx\r\n # @param `stroke` not used - already defined in ctx\r\n @polygon: ( ctx, pts, closePath=true, fill=true, stroke=true) ->\r\n\r\n elem = SVGSpace.svgElement( ctx.group, (if (closePath) then \"polygon\" else \"polyline\"), SVGForm.id(ctx) )\r\n if (!elem) then return\r\n\r\n if pts.length <= 1 then return;\r\n\r\n points = (\"#{pts[i].x},#{pts[i].y}\" for i in [0...pts.length] by 1)\r\n DOMSpace.attr( elem, {\r\n points: points.join(\" \")\r\n })\r\n\r\n SVGForm.style(elem, ctx.style)\r\n return elem\r\n\r\n\r\n # ## Draw a polygon\r\n # @param `ps` an array of Points\r\n # @param `closePath` a boolean value to specify if the path should be closed (joining last point with first point)\r\n # @return this Form\r\n polygon: (ps, closePath) ->\r\n @nextID()\r\n SVGForm.polygon( @cc, ps, closePath)\r\n return @\r\n\r\n # ## A static function to draw a triangle\r\n # @param `ctx` rendering context object\r\n # @param `tri` a Triangle object\r\n # @param `fill` not used - already defined in ctx\r\n # @param `stroke` not used - already defined in ctx\r\n @triangle: ( ctx, tri, fill=true, stroke=false) ->\r\n return SVGForm.polygon(ctx, tri.toArray() )\r\n\r\n\r\n # ## Draw a triangle\r\n # @param `tri` a Triangle object\r\n # @return this Form\r\n triangle: (tri) ->\r\n @nextID()\r\n SVGForm.triangle( @cc, tri )\r\n return @\r\n\r\n\r\n # ## A static function to draw a curve as straight polygon segments. In future, this should be converted to bezier curves.\r\n # @param `ctx` rendering context object\r\n # @param `pts` an array of Points\r\n @curve: ( ctx, pts, closePath=false ) ->\r\n SVGForm.polygon( ctx, pts, closePath )\r\n\r\n\r\n # ## Draw a curve\r\n # @param `ps` an array of Points\r\n # @return this Form\r\n curve: (ps, closePath=false ) ->\r\n @nextID()\r\n SVGForm.curve( @cc, ps, closePath )\r\n return @\r\n\r\n\r\n # ## A static function to draw text\r\n # @param `ctx` rendering context object\r\n # @param `pt` a Point object to specify the anchor point\r\n # @param `txt` a string of text to draw\r\n # @param `maxWidth` not applicable in svg\r\n # @param `dx` optional shift in x position\r\n # @param `dy` optional shift in y position\r\n @text: ( ctx, pt, txt, maxWidth=0, dx=0, dy=0 ) ->\r\n elem = SVGSpace.svgElement( ctx.group, \"text\", SVGForm.id(ctx) )\r\n if (!elem) then return\r\n\r\n DOMSpace.attr( elem, {\r\n \"pointer-events\": \"none\",\r\n x: pt.x,\r\n y: pt.y,\r\n dx: 0,\r\n dy: 0\r\n })\r\n\r\n elem.textContent = txt\r\n\r\n SVGForm.style(elem, {\r\n fill: ctx.style.fill\r\n stroke: ctx.style.stroke\r\n \"font-family\": ctx.fontFace or false\r\n \"font-size\": ctx.fontSize or false\r\n })\r\n return elem\r\n\r\n\r\n # ## Draw text\r\n # @param `p` a Point to specify anchor position\r\n # @param `txt` a string of text\r\n # @param `maxWidth` not applicable in svg\r\n # @param `xoff, yoff` x and y positional offset values\r\n text: (p, txt, maxWidth=1000, xoff, yoff) ->\r\n @nextID()\r\n SVGForm.text( @cc, p, txt, maxWidth, xoff, yoff)\r\n return @\r\n\r\n\r\n\r\n # ## Set font size and font face\r\n # @param `size` an integer value to specify font size in pixels\r\n # @param `face` optional name to change the font face, such as \"sans-serif\" or \"Helvetica\"\r\n # @eg `form.font(24)` `form.font(12, \"Georgia\")`\r\n # @return this Form\r\n font: (size, face=false) ->\r\n @cc.fontFace = face\r\n @cc.fontSize = size\r\n @cc.font = \"#{size}px #{face}\"\r\n return @\r\n\r\n\r\n # ## Draw a shape. Defaults to `sketch()`. Override this function to draw differently.\r\n # @return this Form\r\n draw: ( shape ) ->\r\n @sketch( shape )\r\n\r\n\r\n # ## Default draw based on the types of shape (Point, Line, Circle, etc)\r\n # @param `shape` any shape such as `Point` or `Line`, or an array of Points\r\n # @return this Form\r\n sketch: ( shape ) ->\r\n shape.floor()\r\n\r\n if shape instanceof Circle\r\n SVGForm.circle(@cc, shape, @filled, @stroked)\r\n\r\n else if shape instanceof Rectangle\r\n SVGForm.rect( @cc, shape, @filled, @stroked)\r\n\r\n else if shape instanceof Triangle\r\n SVGForm.triangle( @cc, shape, @filled, @stroked)\r\n\r\n else if shape instanceof Line or shape instanceof Pair\r\n SVGForm.line(@cc, shape)\r\n\r\n else if shape instanceof PointSet\r\n SVGForm.polygon(@cc, shape.points )\r\n\r\n else if shape instanceof Vector or shape instanceof Point\r\n SVGForm.point(@cc, shape)\r\n\r\n\r\n return @\r\n\r\n\r\n# namespace\r\nthis.SVGForm = SVGForm\n# ### SVGSpace is an extension of DOMSpace that represents an svg element in DOM. Also refers to DOMSpace for inherited methods.\r\nclass SVGSpace extends DOMSpace\r\n\r\n # ## Create a SVGSpace which represents a svg element\r\n # @param `id` an optional string which refers to the \"id\" attribute of a DOM element. It can either refer to an existing ``, or a `
` container in which a new `` will be created. If left empty, a `
` will be added to DOM. Use css to customize its appearance if needed.\r\n # @param `callback` an optional callback `function(boundingBox, spaceElement)` to be called when element is appended and ready. A \"ready\" event will also be fired from the space's element when it's appended, which can be tracked with `spaceInstance.space.addEventListener(\"ready\")`\r\n constructor: ( id, callback ) ->\r\n super( id, callback, 'svg')\r\n\r\n if @space.nodeName.toLowerCase() != \"svg\"\r\n s = @_createElement(\"svg\", @id+\"_svg\" )\r\n @space.appendChild( s )\r\n @bound = @space\r\n @space = s\r\n\r\n # size is known so set it immediately\r\n b = @bound.getBoundingClientRect()\r\n @resize( b.width, b.height )\r\n\r\n\r\n\r\n # A private function to create the svg namespaced element. This will create a if elem parameter is not set.\r\n _createElement: ( elem=\"svg\", id ) ->\r\n d = document.createElementNS( \"http://www.w3.org/2000/svg\", elem )\r\n if (id) then d.setAttribute(\"id\", id )\r\n return d\r\n\r\n\r\n # ## A static helper method to add a svg element inside a node. Usually you don't need to use this directly. See methods in `SVGForm` instead.\r\n # @param `parent` the parent node element, or `null` to use current `` as parent.\r\n # @param `name` a string of element name, such as `\"rect\"` or `\"circle\"`\r\n # @param `id` id attribute of the new element\r\n @svgElement: (parent, name, id) ->\r\n\r\n if (!parent || !parent.appendChild)\r\n parent = @space\r\n if !parent then throw( \"parent parameter needs to be a DOM node\" )\r\n\r\n elem = document.querySelector(\"#\"+id);\r\n\r\n if (!elem)\r\n elem = document.createElementNS( \"http://www.w3.org/2000/svg\", name)\r\n elem.setAttribute(\"id\",id)\r\n elem.setAttribute(\"class\",id.substring(0, id.indexOf(\"-\")))\r\n parent.appendChild( elem )\r\n\r\n return elem\r\n\r\n\r\n # ## Remove an item from this Space\r\n # @param an object with an auto-assigned `animateID` property\r\n # @demo svgspace.remove\r\n # @return this space\r\n remove : (item) ->\r\n temp = @space.querySelectorAll( \".\"+SVGForm._scopeID(item) )\r\n\r\n for t in temp\r\n t.parentNode.removeChild(t)\r\n\r\n delete @items[ item.animateID ]\r\n return @\r\n\r\n\r\n # ## Remove all items from this Space\r\n # @return this space\r\n removeAll: () ->\r\n while (@space.firstChild)\r\n @space.removeChild(@space.firstChild)\r\n return @\r\n\r\n\r\n# namescape\r\nthis.SVGSpace = SVGSpace\n# ### Form makes visible the invisible. It transforms a point into an inkblot, or an arrow, or a musical note. By separating forms from its concepts, we may create a myriad of expressions on a single concept, or apply a unified style to various concepts. The Form class provides basic method to draw points, lines, and other primitives on CanvasSpace. Extend this class to visualize in different ways in different contexts.\r\nclass Form\r\n\r\n # ## Create a new Form which is based on HTML Canvass\r\n # @param `space` A space that has a valid context for this form. In this case, the space should represent an html canvas.\r\n # @return a new Form object\r\n constructor: ( space ) ->\r\n\r\n # ## a property to reference the space\r\n @space = space\r\n\r\n # ## a property to reference the canvas rendering context\r\n @cc = space.ctx\r\n\r\n # default style\r\n @cc.fillStyle = '#999'\r\n @cc.strokeStyle = '#666'\r\n @cc.lineWidth = 1\r\n @cc.font = \"11px sans-serif\"\r\n\r\n # ## a boolean property to set if the next drawing should be filled with current fill style\r\n @filled = true\r\n\r\n # ## a boolean property to set if the next drawing should be stroked with current stroke style\r\n @stroked = true\r\n\r\n # ## a property to specify the current font size\r\n @fontSize = 11\r\n\r\n # ## a property to specify the current font face\r\n @fontFace = \"sans-serif\"\r\n\r\n\r\n # ## A static function to get 2d context from a canvas element in the DOM\r\n # @param `canvas_id` the id attribute of the canvas element\r\n # @eg `Form.context('my_canvas')`\r\n # @return a canvas rendering context object\r\n @context : ( canvas_id ) ->\r\n # get canvas and its 2d context\r\n elem = document.getElementById( canvas_id )\r\n cc = if elem and elem.getContext then elem.getContext('2d') else false\r\n if !cc then throw \"Cannot initiate canvas 2d context\"\r\n cc\r\n\r\n\r\n # ## A static function to draw a line\r\n # @param `ctx` canvas rendering context\r\n # @param `pair` a Pair object\r\n @line: (ctx, pair) ->\r\n if !pair.p1 then throw \"#{pair.toString()} is not a Pair\"\r\n ctx.beginPath()\r\n ctx.moveTo( pair.x, pair.y )\r\n ctx.lineTo( pair.p1.x, pair.p1.y )\r\n ctx.stroke()\r\n\r\n\r\n\r\n # ## A static function to draw a line\r\n # @param `ctx` canvas rendering context\r\n # @param `pairs` an array of Pair objects\r\n @lines: (ctx, pairs) ->\r\n for ln in pairs\r\n Form.line( ctx, ln )\r\n\r\n\r\n # ## A static function to draw a rectangle\r\n # @param `ctx` canvas rendering context\r\n # @param `pair` a Pair object\r\n # @param `fill` a boolean value to specify if the points should be filled. Default to true.\r\n # @param `stroke` a boolean value to specify if the points should be stroked. Default to false.\r\n @rect: (ctx, pair, fill=true, stroke=false) ->\r\n if !pair.p1 then throw \"#{pair.toString() is not a Pair}\"\r\n ctx.beginPath()\r\n ctx.moveTo( pair.x, pair.y )\r\n ctx.lineTo( pair.x, pair.p1.y )\r\n ctx.lineTo( pair.p1.x, pair.p1.y )\r\n ctx.lineTo( pair.p1.x, pair.y )\r\n ctx.closePath()\r\n if stroke then ctx.stroke()\r\n if fill then ctx.fill()\r\n\r\n\r\n # ## A static function to draw a circle\r\n # @param `ctx` canvas rendering context\r\n # @param `c` a Circle object\r\n # @param `fill` a boolean value to specify if the points should be filled. Default to true.\r\n # @param `stroke` a boolean value to specify if the points should be stroked. Default to false.\r\n @circle: (ctx, c, fill=true, stroke=false) ->\r\n ctx.beginPath()\r\n ctx.arc( c.x, c.y, c.radius, 0, Const.two_pi, false )\r\n if fill then ctx.fill()\r\n if stroke then ctx.stroke()\r\n return\r\n\r\n\r\n # ## A static function to draw an arc\r\n # @param `ctx` canvas rendering context\r\n # @param `pt` a Point\r\n # @param `radius` radius of the arc's circle\r\n # @param `start` start angle\r\n # @param `stroke` end angle\r\n @arc: (ctx, pt, radius, start, end ) ->\r\n ctx.beginPath()\r\n ctx.arc( pt.x, pt.y, radius, start, end)\r\n ctx.stroke()\r\n\r\n\r\n # ## A static function to draw a triangle\r\n # @param `ctx` canvas rendering context\r\n # @param `tri` a Triangle object\r\n # @param `fill` a boolean value to specify if the points should be filled. Default to true.\r\n # @param `stroke` a boolean value to specify if the points should be stroked. Default to false.\r\n @triangle: ( ctx, tri, fill=true, stroke=false) ->\r\n ctx.beginPath()\r\n ctx.moveTo( tri.x, tri.y )\r\n ctx.lineTo( tri.p1.x, tri.p1.y )\r\n ctx.lineTo( tri.p2.x, tri.p2.y )\r\n ctx.closePath()\r\n if fill then ctx.fill()\r\n if stroke then ctx.stroke()\r\n return\r\n\r\n\r\n # ## A static function to draw a point\r\n # @param `ctx` canvas rendering context\r\n # @param `pt` a Point object\r\n # @param `halfsize` radius or half size of the point. Default is 2.\r\n # @param `fill` a boolean value to specify if the points should be filled. Default to true.\r\n # @param `stroke` a boolean value to specify if the points should be stroked. Default to false.\r\n # @param `circle` a boolean value to specify if the points should be drawn as a circle. Default to false.\r\n @point: (ctx, pt, halfsize=2, fill=true, stroke=false, circle=false ) ->\r\n\r\n if circle\r\n ctx.beginPath()\r\n ctx.arc( pt.x, pt.y, halfsize, 0, Const.two_pi, false )\r\n\r\n else\r\n x1 = pt.x-halfsize\r\n y1 = pt.y-halfsize\r\n x2 = pt.x+halfsize\r\n y2 = pt.y+halfsize\r\n\r\n ctx.beginPath()\r\n ctx.moveTo( x1, y1 )\r\n ctx.lineTo( x1, y2 )\r\n ctx.lineTo( x2, y2 )\r\n ctx.lineTo( x2, y1 )\r\n ctx.closePath()\r\n\r\n if fill then ctx.fill()\r\n if stroke then ctx.stroke()\r\n return pt\r\n\r\n\r\n # ## A static function similar to `Form.point()` but draw a series of points\r\n # @param `ctx` canvas rendering context\r\n # @param `pts` an array of Points\r\n # @param `halfsize, fill, stroke, circle` same parameters as in `Form.point()`\r\n @points: (ctx, pts, halfsize=2, fill=true, stroke=false, circle=false ) ->\r\n for p in pts\r\n Form.point( ctx, p, halfsize, fill, stroke, circle )\r\n\r\n\r\n # ## A static function to draw a polygon\r\n # @param `ctx` canvas rendering context\r\n # @param `pts` an array of Points\r\n # @param `closePath` a boolean value to specify if the path should be closed (joining last point with first point)\r\n # @param `fill` a boolean value to specify if the points should be filled. Default to true.\r\n # @param `stroke` a boolean value to specify if the points should be stroked. Default to true.\r\n @polygon: ( ctx, pts, closePath=true, fill=true, stroke=true) ->\r\n if pts.length <= 1 then return;\r\n ctx.beginPath()\r\n ctx.moveTo( pts[0].x, pts[0].y )\r\n for i in [1...pts.length] by 1\r\n ctx.lineTo( pts[i].x, pts[i].y )\r\n\r\n if closePath then ctx.closePath()\r\n if fill then ctx.fill()\r\n if stroke then ctx.stroke()\r\n return\r\n\r\n # ## A static function to draw a curve\r\n # @param `ctx` canvas rendering context\r\n # @param `pts` an array of Points\r\n @curve: ( ctx, pts ) ->\r\n Form.polygon( ctx, pts, false, false, true )\r\n\r\n\r\n # ## A static function to draw text\r\n # @param `ctx` canvas rendering context\r\n # @param `pt` a Point object to specify the anchor point\r\n # @param `txt` a string of text to draw\r\n # @param `maxWidth` specify a maximum width per line\r\n @text: ( ctx, pt, txt, maxWidth ) ->\r\n ctx.fillText( txt, pt.x, pt.y, maxWidth )\r\n\r\n\r\n\r\n # ## Set current fill style\r\n # @param `c` fill color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle)) Default is `false` (transparent)\r\n # @eg `form.fill(\"#F90\")` `form.fill(\"rgba(0,0,0,.5\")` `form.fill(false)`\r\n # @demo form.fill\r\n # @return this Form\r\n fill: (c) ->\r\n @cc.fillStyle = if c then c else \"transparent\"\r\n @filled = !!c\r\n return @\r\n\r\n\r\n # ## Set current stroke style\r\n # @param `c` stroke color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/strokeStyle)) Default is false (transparent)\r\n # @param `width` Optional value (can be floating point) to set line width\r\n # @param `joint` Optional string to set line joint style. Can be \"miter\", \"bevel\", or \"round\".\r\n # @param `cap` Optional string to set line cap style. Can be \"butt\", \"round\", or \"square\".\r\n # @eg `form.stroke(\"#F90\")` `form.stroke(\"rgba(0,0,0,.5\")` `form.stroke(false)` `form.stroke(\"#000\", 0.5, 'round')`\r\n # @return this Form\r\n stroke: (c, width, joint, cap) ->\r\n @cc.strokeStyle = if c then c else \"transparent\"\r\n @stroked = !!c\r\n if width then @cc.lineWidth = width\r\n if joint then @cc.lineJoin = joint\r\n if cap then @cc.lineCap = cap\r\n return @\r\n\r\n\r\n # ## Set font size and font face\r\n # @param `size` an integer value to specify font size in pixels\r\n # @param `face` optional name to change the font face, such as \"sans-serif\" or \"Helvetica\"\r\n # @eg `form.font(24)` `form.font(12, \"Georgia\")`\r\n # @demo form.font\r\n # @return this Form\r\n font: (size, face=@fontFace) ->\r\n @fontSize = size\r\n @cc.font = \"#{size}px #{face}\"\r\n return @\r\n\r\n\r\n # ## Draw a shape. Defaults to `sketch()`. Override this function to draw differently.\r\n # @return this Form\r\n draw: ( shape ) ->\r\n @sketch( shape )\r\n\r\n\r\n # ## Default draw based on the types of shape (Point, Line, Circle, etc)\r\n # @param `shape` any shape such as `Point` or `Line`, or an array of Points\r\n # @return this Form\r\n sketch: ( shape ) ->\r\n shape.floor()\r\n\r\n if shape instanceof Circle\r\n Form.circle(@cc, shape, @filled, @stroked)\r\n\r\n else if shape instanceof Rectangle\r\n Form.rect( @cc, shape, @filled, @stroked)\r\n\r\n else if shape instanceof Triangle\r\n Form.triangle( @cc, shape, @filled, @stroked)\r\n\r\n else if shape instanceof Line or shape instanceof Pair\r\n Form.line(@cc, shape)\r\n\r\n else if shape instanceof PointSet\r\n Form.polygon(@cc, shape.points )\r\n\r\n else if shape instanceof Vector or shape instanceof Point\r\n Form.point(@cc, shape)\r\n\r\n\r\n return @\r\n\r\n\r\n # ## Draw a point\r\n # @param `p` a Point object\r\n # @param `halfsize` radius or half size of the point. Default is 2.\r\n # @param `isCircle` a boolean value to specify if the point should be drawn as a circle. Default is false.\r\n # @return this Form\r\n point: (p, halfsize=2, isCircle=false) ->\r\n Form.point(@cc, p, halfsize, @filled, @stroked, isCircle )\r\n return @\r\n\r\n # ## Draw a series of points\r\n # @param `ps` an array of Points\r\n # @param `halfsize` radius or half size of the point. Default is 2.\r\n # @param `isCircle` a boolean value to specify if the point should be drawn as a circle. Default is false.\r\n # @demo form.points\r\n # @return this Form\r\n points: (ps, halfsize=2, isCircle=false) ->\r\n Form.points(@cc, ps, halfsize, @filled, @stroked, isCircle )\r\n return @\r\n\r\n\r\n # ## Draw a line\r\n # @param `p` a Pair object\r\n # @return this Form\r\n line: (p) ->\r\n Form.line(@cc, p)\r\n return @\r\n\r\n # ## Draw a series of lines\r\n # @param `ps` an array of Lines\r\n # @return this Form\r\n lines: (ps) ->\r\n Form.lines(@cc, ps)\r\n return @\r\n\r\n\r\n # ## Draw a rectangle\r\n # @param `p` a Pair object\r\n # @return this Form\r\n rect: (p) ->\r\n Form.rect( @cc, p, @filled, @stroked )\r\n return @\r\n\r\n\r\n # ## Draw a circle\r\n # @param `p` a Circle object\r\n # @return this Form\r\n circle: (p) ->\r\n Form.circle( @cc, p, @filled, @stroked )\r\n return @\r\n\r\n # ## Draw an arc\r\n # @param `p` a Circle object\r\n # @param `start` start angle\r\n # @param `end` end angle\r\n # @return this Form\r\n arc: (p, start, end) ->\r\n Form.arc( @cc, p, p.radius, start, end);\r\n return @\r\n\r\n # ## Draw a triangle\r\n # @param `p` a Triangle object\r\n # @return this Form\r\n triangle: (p) ->\r\n Form.triangle( @cc, p, @filled, @stroked )\r\n return @\r\n\r\n\r\n # ## Draw a polygon\r\n # @param `ps` an array of Points\r\n # @param `closePath` a boolean value to specify if the path should be closed (joining last point with first point)\r\n # @return this Form\r\n polygon: (ps, closePath) ->\r\n Form.polygon( @cc, ps, closePath, @filled, @stroked)\r\n return @\r\n\r\n\r\n # ## Draw a curve\r\n # @param `ps` an array of Points\r\n # @demo form.curve\r\n # @return this Form\r\n curve: (ps) ->\r\n Form.curve( @cc, ps )\r\n return @\r\n\r\n\r\n # ## Draw text\r\n # @param `p` a Point to specify anchor position\r\n # @param `txt` a string of text\r\n # @param `maxWidth` maximum width per line\r\n # @param `xoff, yoff` x and y positional offset values\r\n text: (p, txt, maxWidth=1000, xoff, yoff) ->\r\n pos = new Vector(p)\r\n if xoff then pos.add(xoff, 0)\r\n if yoff then pos.add(0, yoff)\r\n @cc.fillText(txt, pos.x, pos.y, maxWidth)\r\n return @\r\n\r\n\r\n # Not implemented, see SVGForm\r\n scope: () -> return @cc\r\n\r\n # Not implemented, see SVGForm\r\n enterScope: () -> return @cc\r\n\r\n\r\n# namespace\r\nthis.Form = Form\n# ### A point is the smallest thing in a space. It defines a static position, an indivisible abstraction, and a creative beginning. Think of a point not as a dot, but as a potentiality, visible only to the mind's squinted eyes.\r\nclass Point\r\n\r\n # ## Create a new point using optional parameters which can be a list of numeric values, or an array, or an object with x,y,z properties. If no parameter is specified, this will return a Point at (0,0,0) position.\r\n # @param `args(x,y,z)` optional comma separated values to specify x, y, and z position\r\n # @param `args([x,y,z])` optional array with 1 to 3 values to specify x, y, and z position\r\n # @param `args(pt)` an optional object with `{x, y, z}` properties.\r\n # @eg `new Point()` `new Point(1,2,3)` `new Point([2,4])` `new Point({x:3, y:6, z:9})`\r\n # @return a new Point object\r\n constructor: (args) ->\r\n\r\n # parse arguments and copy to this.x,y,z\r\n @copy( Point.get(arguments) )\r\n\r\n\r\n # ## A static function `Point.get()` which converts arrays or objects to an object with `{x, y, z}` properties.\r\n # @param `args` Similar to Point constructor, this accepts optional parameters which can be comma-separated values, or an array, or any object.\r\n # @eg `Point.get([2,4])` `Point.get({x:3, y:6, z:9})`\r\n # @return an Object with {x, y, z} properties\r\n @get : ( args ) ->\r\n\r\n if args.length > 0\r\n\r\n if typeof args[0] is 'object'\r\n\r\n # if it's Array or arguments (object with length property). Note that \"arguments\" is not considered as an Array by javascript.\r\n if args[0] instanceof Array or args[0].length > 0\r\n\r\n return {\r\n x: args[0][0] || 0\r\n y: args[0][1] || 0\r\n z: args[0][2] || 0\r\n }\r\n\r\n # Point object\r\n else\r\n return {\r\n x: args[0].x || 0\r\n y: args[0].y || 0\r\n z: args[0].z || 0\r\n }\r\n\r\n # multiple args for x, y, z\r\n else\r\n\r\n return {\r\n x: args[0] || 0\r\n y: args[1] || 0\r\n z: args[2] || 0\r\n }\r\n\r\n else\r\n # no argument return empty point\r\n return { x: 0, y: 0, z: 0 }\r\n\r\n\r\n # ## Given another point in relation to this point, this returns which side or quadrant the other point is at.\r\n # @param `pt` a Point object\r\n # @param `epsilon` an optional value to specify the minimum distance threshold. Default is Const.epsilon.\r\n # @eg `p.quadrant( another_p )` `p.quadrant( another_p, 2 )`\r\n # @demo point.quadrant\r\n # @return a constant value such as Const.identical, Const.bottom, Const.top_right\r\n quadrant: (pt, epsilon=Const.epsilon) ->\r\n\r\n if pt.near(@) then return Const.identical\r\n\r\n if (Math.abs(pt.x-@x) < epsilon)\r\n return if pt.y < @y then Const.top else Const.bottom\r\n\r\n if (Math.abs(pt.y-@y) < epsilon)\r\n return if pt.x < @x then Const.left else Const.right\r\n\r\n if (pt.y < @y && pt.x > @x)\r\n return Const.top_right\r\n else if (pt.y < @y && pt.x < @x)\r\n return Const.top_left\r\n else if (pt.y > @y && pt.x < @x)\r\n return Const.bottom_left\r\n else\r\n return Const.bottom_right\r\n\r\n\r\n # ## Set position of this point\r\n # @param `args` comma-separated values, as an array, or as a Point object.\r\n # @eg Eg, `p.set( x, y )` or `p.set( {x, y, z} )` or `p.set( [x, y, z] )`\r\n # @return this Point\r\n set: (args) ->\r\n p = Point.get(arguments)\r\n\r\n # ## property for x position\r\n @x = p.x\r\n\r\n # ## property for y position\r\n @y = p.y\r\n\r\n # ## propoerty for z position\r\n @z = p.z\r\n return @\r\n\r\n\r\n # ## Copy another point object to this point. Slightly faster than `set()`\r\n # @param `p` a Point object to copy\r\n # @return this Point\r\n copy: (p) ->\r\n @x = p.x\r\n @y = p.y\r\n @z = p.z\r\n return @\r\n\r\n\r\n # ## Clone this point\r\n # @return a new Point that is identical to this point\r\n clone: () -> return new Point( @ )\r\n\r\n\r\n # ## Describe this point as a text string\r\n # @return \"Point x, y, z\" text\r\n toString: () -> \"Point #{ @x }, #{ @y }, #{ @z }\"\r\n\r\n # ## Put this vector into an array\r\n # @return an array with a single point object\r\n toArray: () -> [@]\r\n\r\n\r\n\r\n # ## When a point has 3 dimensions `(x,y,z)`, this function converts it to a new point `(x,y)` of a specific 2D plane (such as `yz`)\r\n # @param `axis` an axis id such as `Const.yz`.\r\n # @param `reverse` optional boolean value. If `true`, the mapping will be flipped. Default is false.\r\n # @eg `p.get2D( Const.xy )` `p.get2D(Const.yz, true)`\r\n # @return a new 2D Point\r\n get2D: (axis, reverse=false) ->\r\n\r\n if axis == Const.xy then return new this.__proto__.constructor( @ )\r\n if axis == Const.xz then return new this.__proto__.constructor( @x, @z, @y ) # same flip in reverse\r\n if axis == Const.yz\r\n if reverse\r\n return new this.__proto__.constructor( @z, @x, @y )\r\n else\r\n return new this.__proto__.constructor( @y, @z, @x )\r\n\r\n return new this.__proto__.constructor( @ )\r\n\r\n\r\n\r\n # ## Evaluate the minimum x,y,z of this point and another point, and get a minimum Point\r\n # @param `args` comma-separated values, as an array, or as a Point object.\r\n # @eg `p.min(1,2)` `p.min( another_p )`\r\n # @return this Point\r\n min: (args) ->\r\n _p = Point.get(arguments)\r\n @x = Math.min(@x, _p.x)\r\n @y = Math.min(@y, _p.y)\r\n @z = Math.min(@z, _p.z)\r\n return @\r\n\r\n\r\n # ## Similar to `min()` but returns a new instance\r\n $min: (args) ->\r\n _p = Point.get(arguments)\r\n return new this.__proto__.constructor( Math.min(@x, _p.x), Math.min(@y, _p.y), Math.min(@z, _p.z) )\r\n\r\n\r\n # ## Evaluate the minimum x,y,z of this point and another point, and get a maximum Point\r\n # @param `args` comma-separated values, as an array, or as a Point object.\r\n # @eg `p.max(1,2)` `p.max( another_p )`\r\n # @demo point.max\r\n # @return this Point\r\n max: (args) ->\r\n _p = Point.get(arguments)\r\n @x = Math.max(@x, _p.x)\r\n @y = Math.max(@y, _p.y)\r\n @z = Math.max(@z, _p.z)\r\n return @\r\n\r\n\r\n # ## Similar to `max()` but returns a new instance\r\n $max: (args) ->\r\n _p = Point.get(arguments)\r\n return new this.__proto__.constructor( Math.max(@x, _p.x), Math.max(@y, _p.y), Math.max(@z, _p.z) )\r\n\r\n\r\n # ## Check if this point is at exactly the same position as the other point\r\n # @param `args` comma-separated values, as an array, or as a Point object.\r\n # @eg `p.equal(1,2)` `p.equal( another_p )`\r\n # @return boolean, true if they are equal\r\n equal: (args) ->\r\n _p = Point.get(arguments)\r\n return (_p.x == @x) and (_p.y == @y) and (_p.z == @z)\r\n\r\n\r\n # ## Check if this point is at exactly the same position as the other point\r\n # @param `pt` a Point to check against\r\n # @param `epsilon` an optional threshold value indicating the minimum distance that's near enough\r\n # @eg `p.near(another_p)` `p.near( another_p, 2 )` `p.near( Point.get(1,2,3) )`\r\n # @return boolean, true if they are near\r\n near: ( pt, epsilon=Const.epsilon) ->\r\n _p = Point.get(arguments)\r\n return (Math.abs(_p.x-@x) < epsilon) and (Math.abs(_p.y-@y) < epsilon) and (Math.abs(_p.z-@z) < epsilon)\r\n\r\n\r\n # ## Snap this point's position to the nearest integer by its floor\r\n # @return this Point\r\n floor: () ->\r\n @x = Math.floor( @x )\r\n @y = Math.floor( @y )\r\n @z = Math.floor( @z )\r\n return @\r\n\r\n\r\n # ## Snap this point's position to the nearest integer by its ceiling\r\n # @return this Point\r\n ceil: () ->\r\n @x = Math.ceil( @x )\r\n @y = Math.ceil( @y )\r\n @z = Math.ceil( @z )\r\n return @\r\n\r\n\r\n# namespace\r\nthis.Point = Point\r\n\n# ### A vector points to a point. If a point represents a position on a conceptual plane, then a vector is the thought toward it. As a thought, it has direction and reach. A vector expresses the same concept in verb as a point does in noun.\r\nclass Vector extends Point\r\n\r\n # ## Create a new Vector. A Vector extends a Point and includes functions for arithmetics.\r\n # @param `args` Similar to Point constructor, use comma-separated values, an array, or a Point object as parameters.\r\n # @eg `new Vector()` `new Vector(1,2,3)` `new Vector([2,4])` `new Vector({x:3, y:6, z:9})`\r\n # @return a new Vector object\r\n constructor: () ->\r\n super\r\n\r\n # private function to get arguments based on argument types\r\n _getArgs: (args) -> return if typeof args[0] is 'number' and args.length > 1 then args else args[0]\r\n\r\n # ## Add another vector to this vector.\r\n # @param `args` comma-separated values, or as an array, or a Point object.\r\n # @eg `vec.add(1,2)` `vec.add([2,4])` `vec.add({x:3, y:6, z:9})`\r\n # @demo vector.add\r\n # @return this Vector\r\n add: (args) ->\r\n # add scalar\r\n if typeof arguments[0] is 'number' and arguments.length is 1\r\n @x += arguments[0]\r\n @y += arguments[0]\r\n @z += arguments[0]\r\n # add point\r\n else\r\n _p = Point.get(arguments)\r\n @x += _p.x\r\n @y += _p.y\r\n @z += _p.z\r\n\r\n return @\r\n\r\n\r\n # ## Same as `add()` but returns a new Vector. The values of this vector are not changed.\r\n $add: (args) ->\r\n a = @_getArgs( arguments )\r\n new Vector( @ ).add( a )\r\n\r\n\r\n # ## Subtract another vector from this vector.\r\n # @param `args` 0-3 comma-separated values, or as an array, or a Point object.\r\n # @eg `vec.subtract(1,2)` `vec.subtract([2,4])` `vec.subtract({x:3, y:6, z:9})`\r\n # @return this Vector\r\n subtract: (args) ->\r\n # subtract scalar\r\n if typeof arguments[0] is 'number' and arguments.length is 1\r\n @x -= arguments[0]\r\n @y -= arguments[0]\r\n @z -= arguments[0]\r\n # subtract point\r\n else\r\n _p = Point.get(arguments)\r\n @x -= _p.x\r\n @y -= _p.y\r\n @z -= _p.z\r\n\r\n return @\r\n\r\n # ## Same as `subtract()` but returns a new Vector. The values of this vector are not changed.\r\n $subtract: (args) ->\r\n a = @_getArgs( arguments )\r\n return new Vector( @ ).subtract( a )\r\n\r\n\r\n # ## Multiple this vector with a scalar or vector. If there's only one numberic value in the parameter, this vector will be multiplied by that scalar value. Otherwise, this vector's x,y,z values will be multiplied by the corresponding x,y,z in the parameters. Note that this is different to .dot and .cross products.\r\n # @param `args` 0-3 comma-separated values, or as an array, or a Point object.\r\n # @eg `vec.multiply(4)` `vec.multiply(1,2,3)` `vec.multiply([2,4])` `vec.multiply({x:3, y:6, z:9})`\r\n # @return this Vector\r\n multiply: (args) ->\r\n # multiply scalar\r\n if arguments.length is 1 and (typeof arguments[0] is 'number' or (typeof arguments[0] is 'object' and arguments[0].length == 1) )\r\n @x *= arguments[0]\r\n @y *= arguments[0]\r\n @z *= arguments[0]\r\n # multiply point\r\n else\r\n _p = Point.get(arguments)\r\n @x *= _p.x\r\n @y *= _p.y\r\n @z *= _p.z\r\n\r\n return @\r\n\r\n # ## Same as `multiply()` but returns a new Vector. The values of this vector is not changed.\r\n $multiply: (args) ->\r\n a = @_getArgs( arguments )\r\n return new Vector( @ ).multiply( a )\r\n\r\n\r\n # ## Similar as `multiply()` but easier to read semantically. `vec.divide(2,4,5)` is the same as `vec.multiply(0.5, 0.25, 0.2)`\r\n # @eg `vec.divide(10)` `vec.divide(2,4,5)`\r\n # @return this Vector\r\n divide: (args) ->\r\n # divide scalar\r\n if arguments.length is 1 and (typeof arguments[0] is 'number' or (typeof arguments[0] is 'object' and arguments[0].length == 1) )\r\n @x /= arguments[0]\r\n @y /= arguments[0]\r\n @z /= arguments[0]\r\n # divide point\r\n else\r\n _p = Point.get(arguments)\r\n @x /= _p.x\r\n @y /= _p.y\r\n @z /= _p.z\r\n\r\n return @\r\n\r\n # ## Same as `divide()` but returns a new Vector. The values of this vector is not changed.\r\n $divide: (args) ->\r\n a = @_getArgs( arguments )\r\n return new Vector( @ ).divide( a )\r\n\r\n\r\n # ## Apply a function to all points in the `toArray()` list. This is usually applied to `Pair`, `PointSet` and other objects to call a function to all its points.\r\n # @param `name` a function of this class\r\n # @param `args...` optional, comma-separated arguments to pass to the function\r\n # @eg `pair.op(\"add\", 1,2,3)` `pointset.op(\"multiply\", 2)`\r\n op: ( name, args... ) ->\r\n pts = @toArray()\r\n for p in pts\r\n p[name]( args... )\r\n return @\r\n\r\n\r\n # ## Similar to `op()` but apply the function to a new instance.\r\n $op: ( name, args... ) ->\r\n instance = @clone()\r\n pts = instance.toArray()\r\n for p in pts\r\n p[name]( args... )\r\n return instance\r\n\r\n\r\n\r\n # ## Get the angle of this vector on a plane, or get the angle from this vector to another point. If no parameter specified, this will return the angle on xy plane.\r\n # @param `axis` single optional argument to specify axis id (eg, `Const.yz`) to specify a plane\r\n # @param `pt` single optional argument to specify a Point object, to calculate the angle from this Point to another Point instead\r\n # @param `axis, pt` 2 arguments in this sequence, as optional axis id and Point object, to get the angle to a Point on a specific plane\r\n # @eg `vec.angle()` `vec.angle(Const.yz)` `vec.angle(another_pt)` `vec.angle(Const.xz, another_pt)`\r\n # @return a radian value\r\n angle: (args) ->\r\n\r\n # no argument angle from origin\r\n if arguments.length is 0\r\n return Math.atan2( @y, @x )\r\n\r\n # if first argument is axis\r\n if typeof arguments[0] is 'string'\r\n axis = arguments[0]\r\n p = if arguments.length > 1 then @$subtract( arguments[1] ).multiply(-1) else undefined\r\n\r\n # first argument is object or none\r\n else\r\n p = @$subtract( arguments[0]).multiply(-1)\r\n axis = false\r\n\r\n # if has point and no axis, find xy to another point\r\n if p and !axis\r\n return Math.atan2( p.y, p.x )\r\n\r\n # has axis parameter\r\n else if axis is Const.xy\r\n return if p then Math.atan2( p.y, p.x ) else (Math.atan2( @y, @x ))\r\n\r\n else if axis is Const.yz\r\n return if p then Math.atan2( p.z, p.y ) else (Math.atan2( @z, @y ))\r\n\r\n else if axis is Const.xz\r\n return if p then Math.atan2( p.z, p.x ) else (Math.atan2( @z, @x ))\r\n\r\n\r\n # ## Get the change in radian between this and another vector (from origin position)\r\n # @param `vec` another Vector to compare against\r\n # @param axis optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.angleBetween( another_pt )` `vec.angleBetween( another_pt, Const.yz )`\r\n angleBetween: (vec, axis=Const.xy) ->\r\n Util.boundRadian( @angle( axis ), true ) - Util.boundRadian( vec.angle( axis ), true )\r\n\r\n\r\n # ## Get the mangnitude (ie, distance from origin) of this vector, or get the distance from this vector to another point. Default is to get the magnitude on xyz plane.\r\n # @param `axis` single argument as optional axis id (eg, `Const.yz`) to specify a plane\r\n # @param `pt` single argument as optional Point object to calculate the distance from this Point to another Point instead\r\n # @param `sqrt` single argument as optional boolean value to get distance-squared value if set to `false`. Default is true.\r\n # @param `axis, pt, sqrt` 3 optional parameters can be used in this sequence to specify a plane, a Point, and whether to get squared value.\r\n # @eg `vec.magnitude()` `vec.magnitude(false)` `vec.magnitude(Const.yz)` `vec.magnitude(another_pt)` `vec.magnitude(Const.xz, another_pt, false)`.\r\n # @return magnitude value\r\n magnitude: (args) ->\r\n\r\n m = {x:@x*@x, y:@y*@y, z:@z*@z }\r\n\r\n # if last argument is false, then don't use Math.sqrt\r\n useSq = (arguments.length >= 1 and !arguments[ arguments.length-1 ])\r\n _sq = if useSq then ( (x) -> x ) else Math.sqrt\r\n\r\n # no argument angle from origin\r\n if arguments.length is 0\r\n return _sq( m.x + m.y + m.z )\r\n\r\n # if first argument is axis\r\n if typeof arguments[0] is 'string'\r\n axis = arguments[0]\r\n if arguments.length > 1 and arguments[1]\r\n p = @$subtract( arguments[1] )\r\n else\r\n p = undefined\r\n\r\n # first argument is object or none\r\n else\r\n p = @$subtract( arguments[0] )\r\n axis = false\r\n\r\n mag = if p then {x:p.x*p.x, y:p.y*p.y, z:p.z*p.z} else m\r\n\r\n # if has point and no axis, find xyz to another point\r\n if p and !axis\r\n return _sq( mag.x + mag.y + mag.z )\r\n\r\n # has axis parameter\r\n else if axis is Const.xy\r\n return _sq( mag.x + mag.y )\r\n\r\n else if axis is Const.yz\r\n return _sq( mag.y + mag.z )\r\n\r\n else if axis is Const.xz\r\n return _sq( mag.x + mag.z )\r\n\r\n\r\n # ## Get the distance between this and another point. An alias of magnitude.\r\n # @param `pt` another point\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @return distance\r\n distance: (pt, axis=Const.xy) -> @magnitude( axis, pt )\r\n\r\n # ## Normalize this vector to a unit vector, which has magnitude of 1.\r\n # @demo vector.normalize\r\n # @return this vector\r\n normalize: () ->\r\n @set( @$normalize() )\r\n return @\r\n\r\n\r\n # ## Get a normalized unit vector which has magnitude of 1. The original vector is not changed.\r\n # @return a new unit vector\r\n $normalize: () ->\r\n m = @magnitude()\r\n\r\n if m is 0\r\n return new Vector()\r\n else\r\n return new Vector( @x/m, @y/m, @z/m )\r\n\r\n # ## Set this vector's values to its absolute value (always positive).\r\n # @return this vector\r\n abs: () ->\r\n @x = Math.abs(@x)\r\n @y = Math.abs(@y)\r\n @z = Math.abs(@z)\r\n return @\r\n\r\n\r\n # ## Calculate the [dot product](http://en.wikipedia.org/wiki/Dot_product) of this and another vector.\r\n # @param `p` a Point to calculate the dot product\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.dot( another_vec )` `vec.dot( another_vec, Const.xz )`\r\n # @return the dot product which is a scalar (numeric) value\r\n dot: ( p, axis=Const.xyz ) ->\r\n if axis == Const.xyz\r\n return @x*p.x + @y*p.y + @z*p.z\r\n else if axis == Const.xy\r\n return @x*p.x + @y*p.y\r\n else if axis == Const.yz\r\n return @y*p.y + @z*p.z\r\n else if axis == Const.xz\r\n return @x*p.x + @z*p.z\r\n else\r\n return @x*p.x + @y*p.y + @z*p.z\r\n\r\n # ## Calculate [vector projection](http://en.wikipedia.org/wiki/Vector_projection). A vector projection has the same direction as this vector but a different length. So if you draw a line from the projection vector to the vector specified in the parameter, it will be perpendicular to this vector.\r\n # @param `vec` a Vector to calculate the projection\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.projection( another_vec)` `vec.projection( another_vec, Const.xz )`\r\n # @demo vector.projection\r\n # @return the vector projection\r\n projection: ( vec, axis=Const.xyz ) ->\r\n m = vec.magnitude()\r\n a = @$normalize()\r\n b = new Vector( vec.x/m, vec.y/m, vec.z/m )\r\n dot = a.dot( b, axis )\r\n return a.$multiply( m * dot )\r\n\r\n # ## Calculate the [cross product](http://en.wikipedia.org/wiki/Cross_product) of this and another vector.\r\n # @param `p` a Point to calculate the cross product\r\n # @eg `vec.cross( another_vec )`\r\n # @return the cross product which is a vector\r\n cross: ( p ) ->\r\n new Vector( (@y*p.z - @z*p.y), (@z*p.x - @x*p.z), (@x*p.y - @y*p.x) )\r\n\r\n\r\n # ## Get the middle vector between this and another vector\r\n # @param `vec` a Vector to calculate the bisect\r\n # @eg `vec.bisect( another_vec )`\r\n # @return a vector in the middle\r\n bisect: ( vec, isNormalized=false ) ->\r\n if isNormalized\r\n return @$add(vec).divide(2)\r\n else\r\n return @$normalize().add( vec.$normalize() ).divide(2)\r\n\r\n\r\n # ## Get 2 vectors that are perpendicular to this vector\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.perpendicular()` `vec.perpendicular(Const.yz)`\r\n # @return an array of two vectors\r\n perpendicular: ( axis=Const.xy ) ->\r\n switch axis\r\n when Const.xy then return [new Vector( -@y, @x, @z ), new Vector( @y, -@x, @z )]\r\n when Const.yz then return [new Vector( @x, -@z, @y ), new Vector( @x, @z, -@y )]\r\n when Const.xz then return [new Vector( -@z, @y, @x ), new Vector( @z, -@y, @x )]\r\n else return [new Vector( -@y, @x, @z ), new Vector( @y, -@x, @z )]\r\n\r\n\r\n # ## Check if another vector is perpendicular to this vector\r\n # @param `p` a Point to check against\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.isPerpendicular( another_vec )` `vec.isPerpendicular( another_vec, Const.yz )`\r\n # @return a boolean (true or false)\r\n isPerpendicular: ( p, axis=Const.xyz ) -> @dot(p, axis) == 0\r\n\r\n\r\n # ## Get surface normal vector. A [normal](http://en.wikipedia.org/wiki/Normal_%28geometry%29) is a vector perpendicular to a plane or object.\r\n # @param `p` a Point to calculate the surface normal\r\n # @eg `vec.surfaceNormal( another_vec )`\r\n # @return the normal vector\r\n surfaceNormal: ( p ) ->\r\n return @cross( p ).normalize(true)\r\n\r\n\r\n # ## move origin to a new position. In subclasses of `Vector`, such as `Pair` or `PointSet`, this will move all the points.\r\n # @param `args` new position as 1-3 comma-separated values, or as an array, or a Point object.\r\n moveTo: ( args ) ->\r\n target = Point.get(arguments)\r\n d = @$subtract( target )\r\n pts = @toArray()\r\n for p in pts\r\n p.subtract( d )\r\n\r\n return @\r\n\r\n # ## move origin by a certain amount. In subclasses of `Vector`, such as `Pair` or `PointSet`, this will move all the points.\r\n # @param `args` move amount as 1-3 comma-separated values, or as an array, or a Point object.\r\n moveBy: ( args ) ->\r\n inc = Point.get(arguments)\r\n pts = @toArray()\r\n for p in pts\r\n p.add( inc )\r\n\r\n return @\r\n\r\n\r\n # ## Rotate this vector around an anchor point on a 2D plane. In subclasses of `Vector`, such as `Pair` or `PointSet`, this will rotate all the points.\r\n # @param `radian` a radian value specifying the angle. (where 1 degree = PI / 180 radian)\r\n # @param `anchor` a Point object specifying the anchor position\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.rotate2D( Math.PI/2, anchor_pt )` `vec.rotate2D( 30*Const.deg_to_rad, another_pt, Const.xz )`\r\n # @demo vector.rotate2D\r\n # @return this vector\r\n rotate2D: (radian, anchor, axis=Const.xy) ->\r\n if !anchor then anchor = new Point(0,0,0)\r\n mx = Matrix.rotateAnchor2D( radian, anchor, axis )\r\n\r\n pts = @toArray()\r\n for p in pts\r\n Matrix.transform2D( p, mx, axis )\r\n\r\n return @\r\n\r\n\r\n # ## Reflect this vector along a path. In subclasses of `Vector`, such as `Pair` or `PointSet`, this will reflect all the points.\r\n # @param `line` a Line object to specify the path\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.reflect2D( line )` `vec.reflect2D( line, Const.xz )`\r\n # @return this vector\r\n reflect2D: (line, axis=Const.xy) ->\r\n mx = Matrix.reflectAnchor2D( line, axis )\r\n pts = @toArray()\r\n for p in pts\r\n Matrix.transform2D( p, mx, axis )\r\n\r\n return @\r\n\r\n\r\n # ## Rescale this vector from an anchor point. In subclasses of `Vector`, such as `Pair` or `PointSet`, this will scale all the points together.\r\n # @param `sx` x scale value, where 1 = no change\r\n # @param `sy` y scale value, where 1 = no change\r\n # @param `anchor` a Point object specifying the anchor position to scale from\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.scale2D( 0.7, 1.2, anchor_pt )` `vec.scale2D( 1, 3, anchor_pt, Const.xz )`\r\n # @demo vector.scale2D\r\n # @return this vector\r\n scale2D: (sx, sy, anchor, axis=Const.xy) ->\r\n if !anchor then anchor = new Point(0,0,0)\r\n mx = Matrix.scaleAnchor2D( sx, sy, anchor, axis )\r\n pts = @toArray()\r\n for p in pts\r\n Matrix.transform2D( p, mx, axis )\r\n\r\n return @\r\n\r\n\r\n # ## Shear this vector from an anchor point. In subclasses of `Vector`, such as `Pair` or `PointSet`, this will shear all the points together.\r\n # @param `sx` x scale value, where 1 = no change\r\n # @param `sy` y scale value, where 1 = no change\r\n # @param `anchor` a Point object specifying the anchor position to scale from\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.scale2D( 0.7, 1.2, anchor_pt )` `vec.scale2D( 1, 3, anchor_pt, Const.xz )`\r\n # @return this vector\r\n shear2D: (sx, sy, anchor, axis=Const.xy) ->\r\n if !anchor then anchor = new Point(0,0,0)\r\n mx = Matrix.shearAnchor2D( sx, sy, anchor, axis )\r\n pts = @toArray()\r\n for p in pts\r\n Matrix.transform2D( p, mx, axis )\r\n\r\n return @\r\n\r\n # ## Clone this vector\r\n # @return a new vector identical to this vector\r\n clone: () -> return new Vector(@)\r\n\r\n\r\n # ## Describe this point as a text string\r\n # @return \"Vector x, y, z\" text\r\n toString: () -> \"Vector #{ @x }, #{ @y }, #{ @z }\"\r\n\r\n\r\n\r\n\r\n# namespace\r\nthis.Vector = Vector\r\n\n# ### Color is a sensation of electromagnetic radiation, but your mind interprets it with such obstinate attitude that your favorite color may be, god forbids, pink. Or perhaps color is more like music, whose harmony and rhythm evoke emotions, and can be organized in different sequences to create meaningful narratives.\r\n\r\nclass Color extends Vector\r\n\r\n # ## Create a new Color. Color lets you define a color in a specific mode. [This article](https://software.intel.com/en-us/node/503873) from Intel has a good overview of different color models.\r\n # @param `args` Set the three values of a color as comma-separated values, as an array, or as an object with `{x, y, z}` properties. Optionally set `alpha` in a 4th parameter, and color mode string in 5th parameter.\r\n # @eg `new Color()` `new Color(255,100,20)` `new Color([2,4])` `new Color({x:3, y:6, z:9})` `new Color(360,1,1,0.5)`, `new Color(100,50,-50,1,'lab')`\r\n # @return a new Color object\r\n constructor: ( args ) ->\r\n super\r\n\r\n # ## alpha value from 0 to 1, where 0 is fully transparent, and 1 is fully opaque\r\n _args = if ( Array.isArray(arguments[0]) and arguments[0][3] != undefined ) then arguments[0] else arguments\r\n @alpha = if _args.length >=4 then Math.min( 1, Math.max( _args[3], 0) ) else 1\r\n\r\n # ## color mode id such as \"lab\" or \"rgb\"\r\n @mode = 'rgb'\r\n if arguments.length >=5 then @mode = arguments[4]\r\n if typeof arguments[1] == \"string\" then @mode = arguments[1]\r\n\r\n\r\n # ## A property to adject XYZ for Standard Observer 2deg, Daylight/sRGB illuminant D65\r\n @XYZ = {\r\n D65: {x: 95.047, y: 100, z: 108.883}\r\n }\r\n\r\n ## # A static function `Color.parseHex` to parse a hex string and a Color or rgb array\r\n # @param `hex` hexadecial string with or without \"#\" in the beginning. It can be \"FF9900\", \"F90\", or \"FF9900CC\" with alpha.\r\n # @param `asColor` Optional boolean value where the return value will be a `Color` object if set to `true`. Defaults to `false` which returns an array.\r\n # @eg `Color.parseHex(\"#FF9900\")` `Color.parseHex(\"F90\")` `Color.parseHex(\"FF9900CC\")` `Color.parseHex(\"FF9900\", true)`\r\n # @return a Color object, or an array [r, g, b]\r\n @parseHex : (hex, asColor=false) ->\r\n if hex.indexOf('#') == 0 then hex = hex.substr(1) # remove '#' if needed\r\n if hex.length == 3 then hex = \"\"+hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2]\r\n if hex.length == 8\r\n @alpha = hex.substr(6) & 0xFF / 255\r\n hex = hex.substring(0,6)\r\n\r\n hexValue = parseInt( hex, 16 )\r\n rgb = [ hexValue >> 16, hexValue >> 8 & 0xFF, hexValue & 0xFF]\r\n return if asColor then new Color( rgb[0], rgb[1], rgb[2] ) else rgb\r\n\r\n\r\n # ## set a color mode and convert current color to new color mode\r\n # @param `m` a string to specify color mode: 'hsl', 'hsb', 'rgb', 'lab', 'lch', 'xyz'\r\n # @eg `color.setMode('lab')`\r\n # @return this Color object with new color mode\r\n setMode : ( m ) ->\r\n m = m.toLowerCase()\r\n\r\n if m != @mode\r\n switch @mode\r\n when 'hsl' then @copy( Point.get( Color.HSLtoRGB(@x, @y, @z) ) )\r\n when 'hsb' then @copy( Point.get( Color.HSBtoRGB(@x, @y, @z) ) )\r\n when 'lab' then @copy( Point.get( Color.LABtoRGB(@x, @y, @z) ) )\r\n when 'lch' then @copy( Point.get( Color.LCHtoRGB(@x, @y, @z) ) )\r\n when 'xyz' then @copy( Point.get( Color.XYZtoRGB(@x, @y, @z) ) )\r\n\r\n\r\n switch m\r\n when 'hsl' then @copy( Point.get( Color.RGBtoHSL(@x, @y, @z) ) )\r\n when 'hsb' then @copy( Point.get( Color.RGBtoHSB(@x, @y, @z) ) )\r\n when 'lab' then @copy( Point.get( Color.RGBtoLAB(@x, @y, @z) ) )\r\n when 'lch' then @copy( Point.get( Color.RGBtoLCH(@x, @y, @z) ) )\r\n when 'xyz' then @copy( Point.get( Color.RGBtoXYZ(@x, @y, @z) ) )\r\n\r\n# if m != @mode\r\n# if m is 'rgb' # to RGB\r\n# if @mode is 'hsl' then @copy( Point.get( Color.HSLtoRGB(@x, @y, @z) ) )\r\n# if @mode is 'hsb' then @copy( Point.get( Color.HSBtoRGB(@x, @y, @z) ) )\r\n#\r\n# else if m is 'hsb' # to HSB\r\n# if @mode is 'rgb' then @copy( Point.get( Color.RGBtoHSB(@x, @y, @z) ) )\r\n# # # TODO: if @mode is 'hsl' then\r\n#\r\n# else if m is 'hsl' # to HSL\r\n# if @mode is 'rgb' then @copy( Point.get( Color.RGBtoHSL(@x, @y, @z) ) )\r\n# # # TODO: if @mode is 'hsb' then\r\n#\r\n# else if m is 'xyz'\r\n# if @mode is 'rgb' then @copy( Point.get( Color.RGBtoXYZ(@x, @y, @z) ) )\r\n# # # TODO: if @mode is 'hsb' then\r\n\r\n @mode = m\r\n return @\r\n\r\n\r\n # ## Get rgb value as hex string such as '#123456'\r\n hex: () ->\r\n if @mode is 'rgb' then @floor() # make sure to get rgb as integer\r\n cs = @values( (@mode != 'rgb') ) # convert to rgb if needed\r\n\r\n # pad zero\r\n _hexstring = (n) ->\r\n n = n.toString(16)\r\n if n.length < 2\r\n return '0'+n\r\n else\r\n return n\r\n\r\n ct = (_hexstring( n ) for n in cs)\r\n return '#' + ct[0] + ct[1] + ct[2]\r\n\r\n\r\n # ## Get rgb string such as 'rgb(12,34,56)'\r\n rgb: () ->\r\n if @mode is 'rgb' then @floor() # make sure to get rgb as integer\r\n cs = @values( (@mode != 'rgb') ) # convert to rgb if needed\r\n \"rgb(#{ cs[0] }, #{ cs[1] }, #{ cs[2] })\"\r\n\r\n\r\n # ## Get rgba string such as 'rgba(12,34,56, 0.2)'\r\n rgba: () ->\r\n if @mode is 'rgb' then @floor() # make sure to get rgb as integer\r\n cs = @values( (@mode != 'rgb') ) # convert to rgb if needed\r\n \"rgba(#{ cs[0] }, #{ cs[1] }, #{ cs[2] }, #{ @alpha })\"\r\n\r\n\r\n # ## Get color values (based on current color mode) as an array\r\n # @param `toRGB` Optional boolean value to convert to rgb value if set to `true`. Default is false.\r\n # @return an array of colro values\r\n values: ( toRGB=false ) ->\r\n cs = [@x, @y, @z]\r\n if toRGB and @mode != 'rgb' # convert to rgb first\r\n switch @mode\r\n when 'hsl' then cs = Color.HSLtoRGB(@x, @y, @z)\r\n when 'hsb' then cs = Color.HSBtoRGB(@x, @y, @z)\r\n when 'lab' then cs = Color.LABtoRGB(@x, @y, @z)\r\n when 'lch' then cs = Color.LCHtoRGB(@x, @y, @z)\r\n when 'xyz' then cs = Color.XYZtoRGB(@x, @y, @z)\r\n\r\n return (Math.floor( v ) for v in cs)\r\n\r\n\r\n # ## override clone\r\n clone: () ->\r\n c = new Color(@x, @y, @z, @alpha)\r\n c.mode = @mode\r\n return c\r\n\r\n\r\n # ## Describe this color as a text string\r\n # @return \"Color(mode) x, y, z, alpha\" text\r\n toString: () -> \"Color (#{@mode} mode): #{ @x }, #{ @y }, #{ @z } #{ @alpha }\"\r\n\r\n\r\n # color conversion code ported to coffeescript\r\n # http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript\r\n\r\n # ## A static function `Color.RGBtoHSL` to convert RGB to HSL\r\n # @param `r, g, b` red, green, blue values from 0 to 255\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @eg `Color.RGBtoHSL(255,70,0)` `Color.RGBtoHSL(1,0.3,0, true)`\r\n # @return an array of [h, s, l] where h is from 0 to 360, s is from 0 to 1, and l is from 0 to 1.\r\n @RGBtoHSL : (r, g, b, normalizedInput, normalizedOutput) ->\r\n if not normalizedInput\r\n r /= 255\r\n g /= 255\r\n b /= 255\r\n\r\n max = Math.max(r, g, b)\r\n min = Math.min(r, g, b)\r\n h = (max + min) / 2\r\n s = h\r\n l = h\r\n\r\n if max == min\r\n h = 0\r\n s = 0 # achromatic\r\n else\r\n d = max - min\r\n s = if l > 0.5 then d / (2 - max - min) else d / (max + min)\r\n\r\n switch max\r\n when r then h = (g - b) / d + (if g < b then 6 else 0)\r\n when g then h = (b - r) / d + 2\r\n when b then h = (r - g) / d + 4\r\n else h = 0\r\n\r\n return if normalizedOutput then [h/60, s, l] else [ h*60, s, l]\r\n\r\n\r\n # ## A static function `Color.HSLtoRGB` to convert HSL to RGB\r\n # @param `h, s, l` hue, saturation, and lightness. hue value from 0 to 360, saturation and lightness values from 0 to 1\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @eg `Color.HSLtoRGB(360,0.7,0.9)` `Color.HSLtoRGB(1,0.3,0, true)`\r\n # @demo color.HSLtoRGB\r\n # @return an array of [r, g, b] where each value is from 0 to 255\r\n @HSLtoRGB : ( h, s, l, normalizedInput, normalizedOutput) ->\r\n\r\n if s == 0\r\n return if normalizedOutput then [1,1,1] else [255,255,255]\r\n else\r\n\r\n if not normalizedInput\r\n h /= 360 # normalize hue\r\n\r\n q = if l <= 0.5 then l * (1 + s) else l + s - (l * s)\r\n p = 2 * l - q;\r\n\r\n hue2rgb = ( p, q, t ) ->\r\n\r\n if t < 0\r\n t += 1\r\n else if t > 1\r\n t -= 1\r\n\r\n if t * 6 < 1\r\n return p + (q - p) * t * 6\r\n else if t * 2 < 1\r\n return q\r\n else if t * 3 < 2\r\n return p + (q - p) * ((2 / 3) - t) * 6\r\n else\r\n return p\r\n\r\n r = hue2rgb( p, q, ( h + 1/3 ) )\r\n g = hue2rgb( p, q, h )\r\n b = hue2rgb( p, q, ( h - 1/3 ) )\r\n\r\n return if normalizedOutput then [ r, g, b ] else [r*255, g*255, b*255]\r\n\r\n\r\n # ## A static function `Color.RGBtoHSB` to convert RGB to HSB\r\n # @param `r, g, b` red, green, blue values from 0 to 255\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @eg `Color.RGBtoHSB(255,70,0)` `Color.RGBtoHSB(1,0.3,0, true)`\r\n # @return an array of [h, s, b] where h is from 0 to 360, s is from 0 to 1, and b is from 0 to 1.\r\n @RGBtoHSB : (r, g, b, normalizedInput, normalizedOutput) ->\r\n\r\n if not normalizedInput\r\n r /= 255\r\n g /= 255\r\n b /= 255\r\n\r\n max = Math.max(r, g, b)\r\n min = Math.min(r, g, b)\r\n\r\n d = max - min\r\n s = if max is 0 then 0 else d / max\r\n v = max\r\n\r\n if max is min\r\n h = 0\r\n else\r\n switch max\r\n when r then h = (g - b) / d + ( if g < b then 6 else 0 )\r\n when g then h = (b - r) / d + 2\r\n when b then h = (r - g) / d + 4\r\n else h = 0\r\n\r\n return if normalizedOutput then [h / 60, s, v] else [h * 60, s, v]\r\n\r\n\r\n # ## A static function `Color.HSBtoRGB` to convert HSB to RGB\r\n # @param `h, s, b` hue, saturation, and brightness. hue value from 0 to 360, saturation and brightness values from 0 to 1\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @eg `Color.HSBtoRGB(360,0.7,0.9)` `Color.HSBtoRGB(1,0.3,0, true)`\r\n # @demo color.HSBtoRGB\r\n # @return an array of [r, g, b] where each value is from 0 to 255\r\n @HSBtoRGB : (h, s, v, normalizedInput, normalizedOutput) ->\r\n\r\n if not normalizedInput\r\n h /= 360\r\n\r\n i = Math.floor(h * 6)\r\n f = h * 6 - i\r\n p = v * (1 - s)\r\n q = v * (1 - f * s)\r\n t = v * (1 - (1 - f) * s)\r\n\r\n switch i % 6\r\n when 0 then rgb = [v, t, p]\r\n when 1 then rgb = [q, v, p]\r\n when 2 then rgb = [p, v, t]\r\n when 3 then rgb = [p, q, v]\r\n when 4 then rgb = [t, p, v]\r\n when 5 then rgb = [v, p, q]\r\n else rgb = [0,0,0]\r\n\r\n return if normalizedOutput then rgb else [ rgb[0]*255, rgb[1]*255, rgb[2]*255 ]\r\n\r\n\r\n # ## Static function `Color.RGBtoLAB` transforms RGB to LAB\r\n # @param `r, g, b` red, green, and blue values from 0 to 255\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @return an array of [L, a, b] where lightness (L) is from 0 to 100, a and b component values are from -128 to 127. red/green colors are represented in a, and yellow/blue colors are represented in b.\r\n @RGBtoLAB : (r, g, b, normalizedInput, normalizedOutput) ->\r\n if normalizedInput\r\n r *= 255\r\n g *= 255\r\n b *= 255\r\n\r\n xyz = Color.RGBtoXYZ(r,g,b)\r\n return Color.XYZtoLAB( xyz[0], xyz[1], xyz[2] )\r\n\r\n\r\n # ## Static function `Color.LABtoRGB` transforms LAB to RGB\r\n # @param `L, a, b` lightness (L) is from 0 to 100, a and b component values are from -128 to 127. red/green colors are represented in a, and yellow/blue colors are represented in b.\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @demo color.LABtoRGB\r\n # @return an array of [r, g, b] where each value is from 0 to 255\r\n @LABtoRGB : (L, a, b, normalizedInput, normalizedOutput) ->\r\n if normalizedInput\r\n L *= 100\r\n a = (a-0.5) * 127\r\n b = (b-0.5) * 127\r\n\r\n xyz = Color.LABtoXYZ( L, a, b)\r\n rgb = Color.XYZtoRGB( xyz[0], xyz[1], xyz[2] )\r\n return if normalizedOutput then [ rgb[0]/255, rgb[1]/255, rgb[2]/255 ] else rgb\r\n\r\n # ## Static function `Color.RGBtoLCH` transforms RGB to LCH (Cylindrical Lab)\r\n # @param `r, g, b` red, green, and blue values from 0 to 255\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @return an array of [L, c, h] where lightness (l) and chroma (c) is from 0 to 100, and hue (h) is from 0 to 360\r\n @RGBtoLCH : (r, g, b, normalizedInput, normalizedOutput) ->\r\n if normalizedInput\r\n r *= 255\r\n g *= 255\r\n b *= 255\r\n\r\n lab = Color.RGBtoLAB(r,g,b)\r\n lch = Color.LABtoLCH( lab[0], lab[1], lab[2] )\r\n return if normalizedOutput then [ lch[0]/100, lch[1]/100, lch[2]/360 ] else lch\r\n\r\n\r\n # ## Static function `Color.LCHtoRGB` transforms LCH to RGB\r\n # @param `L, c, h` lightness (l) and chroma (c) is from 0 to 100, and hue (h) is from 0 to 360\r\n # @return an array of [r, g, b] where each value is from 0 to 255\r\n @LCHtoRGB : (L, c, h, normalizedInput, normalizedOutput) ->\r\n if normalizedInput\r\n L *= 100\r\n c *= 100\r\n h *= 360\r\n\r\n lab = Color.LCHtoLAB( L, c, h )\r\n xyz = Color.LABtoXYZ( lab[0], lab[1], lab[2])\r\n rgb = Color.XYZtoRGB( xyz[0], xyz[1], xyz[2] )\r\n return if normalizedOutput then [ rgb[0]/255, rgb[1]/255, rgb[2]/255 ] else rgb\r\n\r\n\r\n # ## Static function `Color.XYZtoRGB` to convert XYZ to RGB. This is usually used when converting between LAB and RGB.\r\n # @param `x, y, z` x, y, z values from 0 to 100\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @return an array of [r, g, b] where each value is from 0 to 255\r\n @XYZtoRGB : (x, y, z, normalizedInput, normalizedOutput) ->\r\n\r\n if not normalizedInput\r\n x = x / 100\r\n y = y / 100\r\n z = z / 100\r\n\r\n rgb = [\r\n x * 3.2404542 + y * -1.5371385 + z * -0.4985314\r\n x * -0.9692660 + y * 1.8760108 + z * 0.0415560\r\n x * 0.0556434 + y * -0.2040259 + z * 1.0572252\r\n ]\r\n\r\n # convert xyz to rgb. Note that not all colors are visible in rgb, so here we bound rgb between 0 to 1\r\n for c, i in rgb\r\n if c < 0\r\n rgb[i] = 0\r\n else\r\n rgb[i] = Math.min( 1, if ( c > 0.0031308 ) then 1.055 * ( Math.pow( c, 1/2.4 ) ) - 0.055 else 12.92 * c )\r\n\r\n# r = if ( r > 0.0031308 ) then 1.055 * ( Math.pow( r, 1/2.4 ) ) - 0.055 else (if r < 0 then 0 else 12.92 * r)\r\n# g = if ( g > 0.0031308 ) then 1.055 * ( Math.pow( g, 1/2.4 ) ) - 0.055 else (if g < 0 then 0 else 12.92 * g)\r\n# b = if ( b > 0.0031308 ) then 1.055 * ( Math.pow( b, 1/2.4 ) ) - 0.055 else (if b < 0 then 0 else 12.92 * b)\r\n\r\n return if normalizedOutput then rgb else [ Math.round(rgb[0] * 255), Math.round(rgb[1] * 255), Math.round(rgb[2] * 255) ]\r\n\r\n\r\n # ## A static function `Color.RGBtoXYZ` to convert RGB to XYZ. This is usually used when converting between LAB and RGB.\r\n # @param `r, g, b` red, green, blue values from 0 to 255\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @return an array of [x, y, z] where each value is from 0 to 100\r\n @RGBtoXYZ : (r, g, b, normalizedInput, normalizedOutput) ->\r\n\r\n if not normalizedInput\r\n r = ( r / 255 )\r\n g = ( g / 255 )\r\n b = ( b / 255 )\r\n\r\n r = if ( r > 0.04045 ) then Math.pow( ( r + 0.055 ) / 1.055, 2.4 ) else r / 12.92\r\n g = if ( g > 0.04045 ) then Math.pow( ( g + 0.055 ) / 1.055, 2.4 ) else g / 12.92\r\n b = if ( b > 0.04045 ) then Math.pow( ( b + 0.055 ) / 1.055, 2.4 ) else b / 12.92\r\n\r\n if not normalizedOutput\r\n r = r * 100\r\n g = g * 100\r\n b = b * 100\r\n\r\n return [\r\n r * 0.4124564 + g * 0.3575761 + b * 0.1804375\r\n r * 0.2126729 + g * 0.7151522 + b * 0.0721750\r\n r * 0.0193339 + g * 0.1191920 + b * 0.9503041\r\n ]\r\n\r\n\r\n # ## Static function `Color.XYZtoLAB` to convert XYZ to LAB.\r\n # @param `x, y, z` x, y, z values from 0 to 100\r\n # @return an array of [l, a, b] where lightness (L) is from 0 to 100, a and b values are from -128 to 127\r\n @XYZtoLAB : (x, y, z) ->\r\n\r\n # adjusted\r\n x = x / Color.XYZ.D65.x\r\n y = y / Color.XYZ.D65.y\r\n z = z / Color.XYZ.D65.z\r\n\r\n calc = (n) ->\r\n return if ( n > 0.008856 ) then Math.pow(n, 1/3) else (7.787 * n) + 16/116\r\n\r\n cy = calc( y )\r\n\r\n return [\r\n ( 116 * cy ) - 16\r\n 500 * ( calc(x) - cy )\r\n 200 * ( cy - calc(z) )\r\n ]\r\n\r\n # ## Static function `Color.LABtoXYZ` to convert LAB to XYZ.\r\n # @param `L, a, b` lightness (L) is from 0 to 100, a and b component values are from -128 to 127\r\n # @return an array of [x, y, z] where each value is from 0 to 100\r\n @LABtoXYZ : (L, a, b) ->\r\n y = ( L + 16 ) / 116\r\n x = a / 500 + y\r\n z = y - b / 200\r\n\r\n calc = (n) ->\r\n nnn = Math.pow(n,3)\r\n return if ( nnn > 0.008856 ) then nnn else ( n - 16 / 116 ) / 7.787\r\n\r\n # adjusted\r\n xyz = [\r\n Math.min( Color.XYZ.D65.x, Color.XYZ.D65.x * calc(x) )\r\n Math.min( Color.XYZ.D65.y, Color.XYZ.D65.y * calc(y) )\r\n Math.min( Color.XYZ.D65.y, Color.XYZ.D65.z * calc(z) )\r\n ]\r\n\r\n return xyz\r\n\r\n # ## Static function `Color.XYZtoLUV` to convert XYZ to LUV.\r\n # @param `x, y, z` x, y, z values from 0 to 100\r\n # @return an array of [l, u, v] where lightness is from 0 to 100, u is from -134 to 220, and v is from -140 o 122\r\n @XYZtoLUV : (x, y, z) ->\r\n u = ( 4 * x ) / ( x + ( 15 * y ) + ( 3 * z ) )\r\n v = ( 9 * y ) / ( x + ( 15 * y ) + ( 3 * z ) )\r\n\r\n y = y / 100\r\n y = if ( y > 0.008856 ) then Math.pow( y, 1/3 ) else ( 7.787 * y + 16 / 116 )\r\n\r\n refU = ( 4 * Color.XYZ.D65.x ) / ( Color.XYZ.D65.x + ( 15 * Color.XYZ.D65.y ) + ( 3 * Color.XYZ.D65.z ) )\r\n refV = ( 9 * Color.XYZ.D65.y ) / ( Color.XYZ.D65.x + ( 15 * Color.XYZ.D65.y ) + ( 3 * Color.XYZ.D65.z ) )\r\n\r\n L = ( 116 * y ) - 16\r\n return [\r\n L\r\n 13 * L * ( u - refU )\r\n 13 * L * ( v - refV )\r\n ]\r\n\r\n # ## Static function `Color.LUVtoXYZ` to convert LUV to XYZ.\r\n # @param `L, u, v` lightness (L) is from 0 to 100, u is from -134 to 220, and v is from -140 o 122\r\n # @return an array of [x, y, z] where each value is from 0 to 100\r\n @LUVtoXYZ : (L, u, v) ->\r\n y = ( L + 16 ) / 116\r\n cubeY = y*y*y\r\n y = if ( cubeY > 0.008856 ) then cubeY else ( y - 16 / 116 ) / 7.787\r\n\r\n refU = ( 4 * Color.XYZ.D65.x ) / ( Color.XYZ.D65.x + ( 15 * Color.XYZ.D65.y ) + ( 3 * Color.XYZ.D65.z ) )\r\n refV = ( 9 * Color.XYZ.D65.y ) / ( Color.XYZ.D65.x + ( 15 * Color.XYZ.D65.y ) + ( 3 * Color.XYZ.D65.z ) )\r\n\r\n u = u / ( 13 * L ) + refU\r\n v = v / ( 13 * L ) + refV\r\n\r\n y = y*100\r\n x = -1 * (9 * y * u) / ( (u - 4) * v - u * v )\r\n return [ x, y, ( 9 * y - (15 * v * y) - (v * x) ) / (3 * v ) ]\r\n\r\n\r\n # ## Static function `Color.LABtoLCH` transforms LAB to Cylindrical LCH\r\n # @param `L, a, b` lightness (L) is from 0 to 100, a and b component values are from -128 to 127\r\n # @return an array of [l, c, h] where lightness (l) and chroma (c) is from 0 to 100, and hue (h) is from 0 to 360\r\n @LABtoLCH : (L, a, b) ->\r\n h = Math.atan2( b, a ) # Quadrant by signs\r\n h = if ( h > 0 ) then (180 * h / Math.PI) else 360 - ( 180 * Math.abs( h ) / Math.PI )\r\n return [L, Math.sqrt( a*a + b*b ), h]\r\n\r\n\r\n # ## Static function `Color.LCHtoLAB` transforms Cylindrical LCH to LAB\r\n # @param `L, c, h` lightness (L) and chroma (c) is from 0 to 100, and hue (h) is from 0 to 360\r\n # @return an array of [l, a, b] where lightness (L) is from 0 to 100, a and b values are from -128 to 127\r\n @LCHtoLAB : (L, c, h) ->\r\n radH = Math.PI * h / 180\r\n return [\r\n L\r\n Math.cos( radH ) * c\r\n Math.sin( radH ) * c\r\n ]\r\n\r\n # ## Static function `Color.LUVtoLCH` to convert LUV to LCH.\r\n # @param `L, u, v` lightness (L) is from 0 to 100, u is from -134 to 220, and v is from -140 o 122\r\n # @return an array of [l, c, h] where lightness (l) and chroma (c) is from 0 to 100, and hue (h) is from 0 to 360\r\n @LUVtoLCH : (L, u, v) -> LABtoLCH( L, u, v )\r\n\r\n # ## Static function `Color.LCHtoLUV` transforms Cylindrical LCH to LUV\r\n # @param `L, c, h` lightness (L) and chroma (c) is from 0 to 100, and hue (h) is from 0 to 360\r\n # @return an array of [l, u, v] where lightness is from 0 to 100, u is from -134 to 220, and v is from -140 o 122\r\n @LCHtoLUV : (L, c, h) -> LCHtoLAB( L, c, h )\r\n\r\n\r\n# namespace\r\nthis.Color = Color\n# ### Imagine this shape: find a point in space, and draw a curve around it so that the distance between the point you picked and any points on that curve is the same. So by remembering how a circle can be constructed, and by considering PI not as a number but as a ratio, we can start to recognize all the expressive potentials of a circle.\r\n\r\nclass Circle extends Vector\r\n\r\n # ## Create a new Circle. A Circle is a Vector which defines its center position, with a `radius` property to define its radius.\r\n # @param `args` Similar to Point constructor, use comma-separated values, an array, or a Point object as parameters to specify the center of circle. Optionally include a 4th parameter to set the radius directly, or use `setRadius()` afterwards.\r\n # @eg `new Circle()` `new Circle(1,2,3)` `new Circle(1,2,3,100)`\r\n # @return a new Circle object\r\n constructor: () ->\r\n super\r\n\r\n # ## the radius property\r\n @radius = if arguments[3]? then arguments[3] else 0 # radius as 4th argument\r\n\r\n # ## set radius of the circle\r\n # @param `r` radius value\r\n # @return this Circle\r\n setRadius: ( r ) ->\r\n @radius = r\r\n return @\r\n\r\n\r\n # ## Check if a point is on this Circle on xy axis.\r\n # @param `args` comma-separated values, or an array, or a Point object\r\n # @eg `circle.intersectPoint(1,2,3)` `circle.intersectPoint(pt)`\r\n # @demo circle.intersectPoint\r\n # @return a boolean value to indicate if there is an intersection\r\n intersectPoint: (args) ->\r\n item = new Vector( Point.get(arguments) )\r\n d = item.$subtract( @ )\r\n return (d.x * d.x + d.y * d.y < @radius * @radius )\r\n\r\n\r\n # ## Check intersections between this Circle and an infinite Line on xy axis. Based on [this algorithm](http://stackoverflow.com/questions/13053061/circle-line-intersection-points).\r\n # @param `path` a Pair or Line object to specify an infinite line\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @demo circle.intersectPath\r\n # @returns an Array of intersection points (zero, one, or two points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectPath: ( path, get_pts=true ) ->\r\n if not path instanceof Pair then return false\r\n\r\n d = path.direction()\r\n f = @.$subtract( path )\r\n\r\n a = d.dot(d, Const.xy)\r\n b = f.dot(d, Const.xy)\r\n c = f.dot(f, Const.xy) - ( @radius * @radius )\r\n p = b / a\r\n q = c / a\r\n disc = p * p - q # discriminant\r\n\r\n if disc < 0\r\n return (if get_pts then [] else false)\r\n else\r\n if !get_pts then return true\r\n\r\n discSqrt = Math.sqrt( disc )\r\n t1 = -p + discSqrt\r\n t2 = -p - discSqrt\r\n\r\n p1 = new Point( path.x - d.x * t1, path.y - d.y * t1 )\r\n p2 = new Point( path.x - d.x * t2, path.y - d.y * t2 )\r\n\r\n return if disc == 0 then [p1] else [p1, p2]\r\n\r\n\r\n# a = d.x * d.x + d.y * d.y\r\n# b = d.x * f.x + d.y * f.y\r\n# c = ( f.x * f.x + f.y * f.y ) - ( @radius * @radius )\r\n# p = b / a\r\n# q = c / a\r\n# disc = p * p - q\r\n#\r\n# if disc < 0\r\n# return []\r\n# else\r\n# discSqrt = Math.sqrt( disc )\r\n# t1 = -p + discSqrt\r\n# t2 = -p - discSqrt\r\n#\r\n# p1 = new Point( ray.x - d.x * t1, ray.y - d.y * t1 )\r\n# p2 = new Point( ray.x - d.x * t2, ray.y - d.y * t2 )\r\n#\r\n# return if disc == 0 then [p1] else [p1, p2]\r\n\r\n\r\n # ## Check intersections between this Circle and a Line segment on xy axis.\r\n # @param `line` a Pair or Line object to specify a line segment\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero, one, or two points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectLine: ( line, get_pts=true ) ->\r\n\r\n # check ray\r\n pts = @intersectPath( line )\r\n if pts and pts.length > 0\r\n\r\n # check intersected point is within line bounding box\r\n pi = []\r\n bounds = line.bounds()\r\n for p in pts\r\n if Rectangle.contain( p, bounds, bounds.p1 )\r\n if !get_pts then return true\r\n pi.push( p )\r\n\r\n return (if get_pts then pi else (pi.length>0) )\r\n else\r\n return (if get_pts then [] else false)\r\n\r\n\r\n # ## Check if this cirlce intersects with a set of lines ( useful for polygon or polyline such as `rectangle.sides()` ) on xy axis.\r\n # @param `lines` an array of Line\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @eg `circle.intersectLines( rect.sides() )` `circle.intersectLines( pointset.sides(), true )`\r\n # @returns an Array of intersection points, or a boolean value. (Based on `get_pts` parameter)\r\n intersectLines: (lines, get_pts=true) ->\r\n return Line.intersectLines( @, lines, get_pts )\r\n\r\n\r\n # ## Check if this circle intersects with another circle\r\n # @param `circle` another Circle\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @demo circle.intersectCircle\r\n # @returns an Array of intersection points (zero or two points) or a boolean value, based on `get_pts` parameter.\r\n intersectCircle: (circle, get_pts=true) ->\r\n dv = circle.$subtract( @ )\r\n dr2 = dv.magnitude(false)\r\n dr = Math.sqrt( dr2 )\r\n\r\n ca_r2 = @radius * @radius\r\n cb_r2 = circle.radius * circle.radius\r\n\r\n if dr > @radius + circle.radius # not intersected\r\n return (if get_pts then [] else false)\r\n\r\n else if dr < Math.abs( @radius - circle.radius ) # completely enclosing the other, no intersecting points\r\n return (if get_pts then [ new Vector(this), new Vector(circle) ] else true)\r\n\r\n else # has two intersection points\r\n if !get_pts then return true\r\n\r\n a = (ca_r2 - cb_r2 + dr2) / (2*dr)\r\n h = Math.sqrt( ca_r2 - a*a )\r\n p = dv.$multiply(a/dr).add(@)\r\n\r\n return [\r\n new Vector( (p.x + h*dv.y/dr), (p.y - h*dv.x/dr) )\r\n new Vector( (p.x - h*dv.y/dr), (p.y + h*dv.x/dr) )\r\n ]\r\n\r\n\r\n # ## Check if this cirlce intersect with another element on xy axis\r\n # @param `item` any object that is based on Point. (Vector, Line, Rectangle, Circle, etc)\r\n # @eg `circle.hasIntersect( another_circle )` `circle.hasIntersect(line)` `circle.hasIntersect(rect)`\r\n # @returns an Array of intersection points or a boolean value. (Based on `get_pts` parameter)\r\n hasIntersect: (item, get_pts=false) ->\r\n\r\n # circle intersection check\r\n if item instanceof Circle\r\n return @intersectCircle( item, get_pts )\r\n\r\n # polygon intersection check (TODO any better algorithm?)\r\n else if item instanceof Rectangle or item instanceof PointSet or item instanceof Triangle\r\n return @intersectLines(item.sides(), get_pts)\r\n\r\n # line intersection check\r\n else if item instanceof Pair\r\n ins = @intersectLine(item)\r\n return if !get_pts then (ins.length > 0) else ins\r\n\r\n # point intersection check\r\n else if item instanceof Point\r\n d = item.$subtract( @ )\r\n return (d.x * d.x + d.y * d.y < @radius * @radius)\r\n\r\n else\r\n return if get_pts then [] else false\r\n\r\n\r\n\r\n # ## Describe this point as a text string\r\n # @return \"Vector x, y, z\" text\r\n toString: () -> \"Circle of #{@radius} radius at center #{ @x }, #{ @y }, #{ @z }\"\r\n\r\n# namespace\r\nthis.Circle = Circle\n# ### If a point represents a static concept in space, then a particle resembles an energized thought. It dashes, brakes, and swirls about. By emulating how forces integrate and energies exchange, we may examine dynamic systems and continuous movements from a new perspective.\r\nclass Particle extends Circle\r\n\r\n # derivative of momentum is force (F=dp/dt)\r\n # derivative of position is velocity (v=dx/dt)\r\n # derivative of velocity is acceleration (a=dv/dt)\r\n # Force = mass * acceleration (F=ma)\r\n # Momentum = mass * velocity (p=mv)\r\n\r\n # ## Create a new Particle. Like a Circle, specify its center position with a `radius` property to define its radius.\r\n # @param `args` Similar to Point constructor, use comma-separated values, an array, or a Point object as parameters to specify the center of circle. Optionally include a 4th parameter to set the radius directly, or use `setRadius()` afterwards.\r\n # @eg `new Particle()` `new Particle(1,2,3)` `new Particle(1,2,3,100)`\r\n # @return a new Circle object\r\n constructor: () ->\r\n super\r\n\r\n # ## A property to store this particle's id\r\n @id = 0\r\n\r\n # ## A property to track this particle's states. An object with properties `.age` and `.maxAge` and a boolean proeprty `.active`\r\n @life = {age: 0, maxAge: 0, active: true, complete: false}\r\n\r\n # ## A property to track this particle's momentum as a Vector\r\n @momentum = new Vector()\r\n\r\n # ## A property to track this particle's velocity as a Vector\r\n @velocity = new Vector()\r\n\r\n # ## A property to specify this particle's mass value. Default is 2.\r\n @mass = 2\r\n\r\n # ## A property to specify this particle's friction. Defaulti is 0.\r\n @friction = 0\r\n\r\n # A property to specify how many frames per milliseconds, for timeStep integration. Default is 20 ms (1000/48 (48 fps) = ~20ms).\r\n @frame_ms = 20\r\n\r\n\r\n # ## Play the particle for one time-step.\r\n # @param `time` current time in milliseconds\r\n # @param `timeDiff` time difference between last and current step, ie, the time of a frame.\r\n # @demo particle.play\r\n play: ( time, timeDiff ) ->\r\n t = 0\r\n while timeDiff > 0\r\n dt = Math.min( timeDiff, @frame_ms )\r\n @integrate(t/1000, dt/1000 ); # unit is seconds\r\n timeDiff -= dt\r\n t += dt\r\n @life.age++\r\n\r\n\r\n\r\n # ## Integrate function using Runge-Kutta-4. Override this function to specify other integrator, such as Euler or Verlet.\r\n # @param `t` current time in *seconds*\r\n # @param `dt` time difference between last and current step, in *seconds*\r\n integrate: (t, dt) ->\r\n @integrateRK4(t, dt)\r\n\r\n\r\n # ## Calculate all forces acting on this particle. This is called by integrate function. Override this function to implement specific force calculations.\r\n # @param `state` a object with `position` and `momentum` Vectors\r\n # @param `t` curent time in seconds\r\n # @eg `p.forces( {position: new Vector(), momentum: new Vector()}, t+dt )`\r\n # @return an object with `force` property\r\n forces: (state, t) ->\r\n return {force: new Vector()}\r\n\r\n # ## Apply an impulse to this particle's `momentum` and `velocity` properties\r\n # @param `force_dt` a force Vector\r\n impulse: ( force_dt ) ->\r\n @momentum.add( force_dt )\r\n @velocity = @momentum.$divide( @mass )\r\n\r\n\r\n # For RK4 integration: update position, momentum and velocity. calculate force.\r\n _evaluate : (t, dt=0, derivative=false) ->\r\n\r\n # integrate at time dt\r\n if dt != 0 and derivative\r\n\r\n state = {\r\n position: @$add( derivative.velocity.$multiply( dt ) )\r\n momentum: @momentum.$add( derivative.force.$multiply( dt ) )\r\n }\r\n\r\n else\r\n state = { position: new Vector(@), momentum: new Vector(@momentum) }\r\n\r\n # recalculate velocity\r\n state.velocity = state.momentum.$divide( @mass )\r\n\r\n # calculate force\r\n f = @forces( state, t+dt )\r\n\r\n return { velocity: state.velocity, force: f.force }\r\n\r\n\r\n # ## Runge-Kutta-4 integration\r\n # @param `t` current time in *seconds*\r\n # @param `dt` time difference between last and current step, in *seconds*\r\n integrateRK4: (t, dt) ->\r\n\r\n # rk4 calculations (adapted based on the algorithm on gafferongames.com)\r\n _map = (m1, m2, m3, m4) ->\r\n v = new Vector(\r\n (m1.x + 2*(m2.x+m3.x) + m4.x) / 6\r\n (m1.y + 2*(m2.y+m3.y) + m4.y) / 6\r\n (m1.z + 2*(m2.z+m3.z) + m4.z) / 6\r\n )\r\n\r\n return v\r\n\r\n a = @_evaluate(t, 0)\r\n b = @_evaluate(t, dt*0.5, a)\r\n c = @_evaluate(t, dt*0.5, b)\r\n d = @_evaluate(t, dt, c)\r\n\r\n @add( _map( a.velocity, b.velocity, c.velocity, d.velocity ) )\r\n @momentum.add( _map( a.force, b.force, c.force, d.force ) )\r\n\r\n\r\n # ## Simple Euler integration using momentum\r\n # @param `t` current time in *seconds*\r\n # @param `dt` time difference between last and current step, in *seconds*\r\n integrateEuler: (t, dt) ->\r\n\r\n f = @forces( { position: new Vector(@), momentum: new Vector(@momentum) }, t+dt )\r\n @add( @velocity )\r\n @momentum.add( f.force )\r\n @velocity = @momentum.$divide( @mass )\r\n\r\n\r\n # ## check Collision with a line segment (wall), and calculate the resulting velocity and momentum\r\n # @param `wall` a Line object to check collision against\r\n # @param `precise` a boolean value to specify a precise collision calculation. If `true`, then the particle position will be recalculated to match the exact collision position with the line. Default is true.\r\n # @demo particle.collideLine2d\r\n # @return a boolean value to indicate if collision occurs\r\n collideLine2d: ( wall, precise=true ) ->\r\n\r\n # this can be optimized by calculating the normalized velocity and wall vectors (used in various Line functions)\r\n\r\n curr_pos = new Vector(@)\r\n curr_dist = Math.abs( wall.getDistanceFromPoint( curr_pos ) )\r\n collided = Math.abs(curr_dist) < @radius\r\n\r\n # if precision is on, find the next position and check if the next position completely crossed the wall (when speed is very fast)\r\n if precise\r\n next_pos = @$add( @velocity )\r\n next_dist = Math.abs( wall.getDistanceFromPoint( next_pos ) )\r\n crossed = wall.intersectLine( new Line( curr_pos ).to( next_pos ) )\r\n\r\n if crossed\r\n next_pos = crossed.$add( @velocity.$normalize().$multiply(-@radius/2) )\r\n next_dist = Math.abs( wall.getDistanceFromPoint( next_pos ) )\r\n collided = true\r\n\r\n if collided\r\n\r\n pt_on_wall = wall.getPerpendicularFromPoint( curr_pos ) # normal point on wall\r\n wall_path = wall.$subtract( wall.p1 )\r\n\r\n collideEndPt = false\r\n\r\n # intersecting with wall segment\r\n if !wall.withinBounds( pt_on_wall, Const.xy )\r\n\r\n # check if colliding with end pt\r\n if @intersectPoint( wall )\r\n collideEndPt = true\r\n end_path = @$subtract( wall )\r\n\r\n if @intersectPoint( wall.p1 )\r\n collideEndPt = true\r\n end_path = @$subtract( wall.p1 )\r\n\r\n if collideEndPt\r\n wall_path = new Vector( -end_path.y, end_path.x ) # treating it like colliding with zero-radius point\r\n\r\n else\r\n return false\r\n\r\n # find project and resulting velocity\r\n dot = wall_path.dot( @velocity )\r\n proj = wall_path.$multiply( (dot / wall_path.dot( wall_path )) )\r\n tangent = proj.$subtract( @velocity )\r\n\r\n @velocity = proj.$add(tangent)\r\n @momentum = @velocity.$multiply( @mass )\r\n\r\n\r\n # Recalculate last position before collision if precision needed\r\n if precise and !collideEndPt\r\n\r\n # normal on wall to curr_pos\r\n perpend = new Line( pt_on_wall ).to( curr_pos )\r\n\r\n # line segment of two points on wall\r\n prev_pt_on_wall = wall.getPerpendicularFromPoint( next_pos )\r\n path = new Line( pt_on_wall ).to( prev_pt_on_wall )\r\n pvec = path.direction()\r\n\r\n # interpolate the point where the collision occurs\r\n r = (@radius-curr_dist) / (next_dist-curr_dist)\r\n pt = pvec.$multiply( r ).$add( path )\r\n pt2 = pt.$add( perpend.direction().$normalize().$multiply( @radius ) )\r\n\r\n # set new position\r\n @set( pt2.$add( @velocity.$normalize() ) )\r\n\r\n return collided\r\n\r\n\r\n # ## Check if a particle hits the boundaries within a box, and calculate the resulting velocity and momentum. Precise collision positioning are not implemented.\r\n # @param `bound` a Rectangle object to specify a bounding box`\r\n # @return a boolean value to indicate if collision occurs\r\n collideWithinBounds: ( bound ) ->\r\n\r\n if @x - @radius < bound.x or @x + @radius > bound.p1.x\r\n\r\n if @x - @radius < bound.x # fast but not totally accurate. Would be better to check the trajectory like in collideLine2D.\r\n @x = bound.x + @radius;\r\n else if @x + @radius > bound.p1.x\r\n @x = bound.p1.x - @radius;\r\n\r\n @velocity.x *= -1\r\n @momentum = @velocity.$multiply( @mass )\r\n return true\r\n\r\n else if @y - @radius < bound.y or @y + @radius > bound.p1.y\r\n if @y - @radius < bound.y\r\n @y = bound.y + @radius;\r\n else if @y + @radius > bound.p1.y\r\n @y = bound.p1.y - @radius;\r\n\r\n @velocity.y *= -1\r\n @momentum = @velocity.$multiply( @mass )\r\n return true\r\n\r\n return false\r\n\r\n\r\n # ## Check 2D collision with another particle, and calculate the resulting velocity and momentum. Precise collision positioning are not implemented.\r\n # @param `pb` another Particle\r\n # @return an array of 2 Vectors, representing this and the other particle's resulting velocity. Or `false` if collision doesn't occur.\r\n collideParticle2d: ( pb ) ->\r\n\r\n if @hasIntersect( pb )\r\n return Particle.collideParticle2d( @, pb, true )\r\n\r\n else\r\n return false\r\n\r\n\r\n # ## Static function to calculate velocity and momentum after 2D collision, without precise coliision positioning. Remember to check intersection/collision before calling this.\r\n # @param `pa, pb` two Particles\r\n # @param `update` a boolean value to update the velocity and momentum of the two particle directly if set to `true`. Default is true.\r\n # @return an array of 2 Vectors, representing this and the other particle's resulting velocity.\r\n @collideParticle2d: (pa, pb, update=true, checkOverlap=true) ->\r\n\r\n # normal and tangent vector of 2 particles on contact\r\n normal = pa.$subtract(pb).normalize()\r\n tangent = new Vector( -normal.y, normal.x )\r\n\r\n # dot products\r\n dot1n = normal.dot( pa.velocity )\r\n dot1t = tangent.dot( pa.velocity )\r\n dot2n = normal.dot( pb.velocity )\r\n dot2t = tangent.dot( pb.velocity )\r\n\r\n # final velocity (one dimension)\r\n d1 = ( dot1n * (pa.mass - pb.mass) + 2 * pb.mass * dot2n ) / (pa.mass + pb.mass)\r\n d2 = ( dot2n * (pb.mass - pa.mass) + 2 * pa.mass * dot1n ) / (pa.mass + pb.mass)\r\n\r\n # final veloctiy (vector)\r\n v1n = normal.$multiply( d1 )\r\n v1t = tangent.$multiply( dot1t )\r\n v2n = normal.$multiply( d2 )\r\n v2t = tangent.$multiply( dot2t )\r\n\r\n pav = v1n.$add( v1t )\r\n pbv = v2n.$add( v2t )\r\n\r\n # check if two particles are overlapping, if so, push them apart\r\n if checkOverlap\r\n mag = pa.magnitude( pb );\r\n if mag < pa.radius + pb.radius\r\n dir= pa.$subtract( pb ).normalize()\r\n magDiff = Math.abs(mag - pa.radius - pb.radius) / 1.98;\r\n pa.add( dir.multiply( magDiff ) );\r\n pb.add( dir.multiply( -magDiff ) );\r\n\r\n if update\r\n pa.velocity = pav\r\n pb.velocity = pbv\r\n\r\n pa.momentum = pa.velocity.$multiply( pa.mass )\r\n pb.momentum = pb.velocity.$multiply( pb.mass )\r\n\r\n return [pav, pbv]\r\n\r\n\r\n # ## Static function to calculate gravitational forces between 2 particles. This can be used as an implementation of `forces()` function\r\n # @param `state` a object with `position` and `momentum` Vectors\r\n # @param `t` curent time in seconds\r\n # @param `pa, pb` two Particles\r\n # @param `g` optional gravitational constant. Defaults to 0.0067.\r\n # @return an object with `force` property\r\n @force_gravitation: (state, t, pa, pb, g=0.0067) ->\r\n meterToPixel = 30\r\n\r\n d = pb.$subtract( state.position )\r\n mag = d.magnitude() / meterToPixel\r\n force = if mag == 0 then 0 else t * g * pa.mass * pb.mass / (mag*mag)\r\n d.normalize().multiply( force )\r\n\r\n return {force: d}\r\n\r\n\r\n # ## Static function of Runge-Kutta-4 integrator (adopted from gafferongames.com)\r\n # @param `c, d` the derivative of c is d. If c is position, then d is velocity.\r\n # @param `func` acceleration function(c, d, dt, t)\r\n # @param `dt` change in time\r\n # @param `t` current time\r\n # @return an object with `{c, d}` properties where the derivative of c is d.\r\n @RK4: (c, d, func, dt, t) ->\r\n\r\n c1 = c\r\n d1= d\r\n a1 = func(c1, d1, 0, t)\r\n\r\n c2 = c + 0.5*d1*dt\r\n d2 = d + 0.5*a1*dt\r\n a2 = func(c2, d2, dt/2, t)\r\n\r\n c3 = c + 0.5*d2*dt\r\n d3 = d + 0.5*a2*dt\r\n a3 = func(c3, d3, dt/2, t)\r\n\r\n c4 = c + d3*dt\r\n d4 = d + a3*dt\r\n\r\n dc = (c1 + 2*(c2+c3) + c4) / 6\r\n dd = (d1 + 2*(d2+d3) + d4) / 6\r\n\r\n return { c: c + dc*dt, d: d + dd*dt }\r\n\r\n# namespace\r\nthis.Particle = Particle\n# ### A particle system keeps track of particles, and regulate them with rules specific to a system. It can also hold constant values from gravitational to cosmic, and specify whether a god may play dice here.\r\nclass ParticleSystem\r\n\r\n # ## Create a ParticleSystem to track a set of particles\r\n constructor : () ->\r\n\r\n # ## a property to store particles in this system as an Array\r\n @count = 0\r\n @particles = []\r\n\r\n # ## a property to track time in milliseconds\r\n @time = 0\r\n\r\n # @animateID = -1\r\n\r\n\r\n # ## add a particle to the system\r\n # @param `particle` a Particle\r\n # @return this system\r\n add : ( particle ) ->\r\n particle.id = @count++\r\n @particles.push( particle )\r\n return @\r\n\r\n\r\n # ## remove a particle which has a `particle.life` property. This marks the `particle.life.complete` as `true` for removal in next cycle.\r\n # @param `particle` a Particle\r\n # @return this system\r\n remove: (particle) ->\r\n if particle and particle.life then particle.life.complete = true\r\n return @\r\n\r\n\r\n # ## animate callback function which is called by` Space.play()`. Override this callback function to specify other animation loops\r\n # @param `time, frame, ctx` parameters for current time, fps, and rendering context, which will be passed by `Space` in callback\r\n animate : ( time, frame, ctx ) ->\r\n @time++\r\n\r\n _remove = []; # to be removed\r\n\r\n for p, i in @particles\r\n\r\n # if life is complete, mark for removal\r\n if p.life.complete\r\n _remove.push( i )\r\n\r\n # if active, animate it\r\n else if p.life.active\r\n p.animate( time, frame, ctx )\r\n\r\n # remove completed particles\r\n if _remove.length > 0\r\n for index in _remove\r\n @particles.splice(index, 1)\r\n\r\n\r\n\r\n# namespace\r\nthis.ParticleSystem = ParticleSystem\r\n\r\n\n# ### A pair of vectors is not merely two vectors, for relationships bring forth meanings. Two vectors can be compared, joined, and interpreted in relation to each other. Together they may connect a line, mark an area, track a change.\r\nclass Pair extends Vector\r\n\r\n # ## Create a new Pair. A Pair is a Vector which defines its anchor point, and connected to another Vector through the `to()` function.\r\n # @param `args` Similar to Point constructor, use comma-separated values, an array, or an object as parameters to specify the first point. As a shortcut to `to()`, you can also pass 4 or 6 values to set both anchor and `p1` points directly as a 2d or 3d vector.\r\n # @eg `new Pair()` `new Pair(1,2,3)` `new Pair([2,4])` `new Pair({x:3, y:6, z:9}).to(1,2,3)`, `new Pair(10,10, 20,20)`\r\n # @return a new Pair object\r\n constructor: () ->\r\n super\r\n\r\n # ## A vector object which is other point in this pair.\r\n @p1 = new Vector( @x, @y, @z )\r\n\r\n if arguments.length == 4\r\n @z = 0\r\n @p1.set( arguments[2], arguments[3] )\r\n else if arguments.length == 6\r\n @p1.set( arguments[3], arguments[4], arguments[5] )\r\n\r\n\r\n # ## connect the other point\r\n # @param `args` comma-separated values, or an array, or an object\r\n # @eg `pair.to(1,2,3)` `new Pair(1,2).to(3,4)`\r\n # @return this Pair\r\n to: () ->\r\n @p1 = new Vector( Point.get(arguments) )\r\n return @\r\n\r\n\r\n # ## Get a point from the set of points based on its index position\r\n # @param `index` index position\r\n # @return a point in the pair\r\n getAt: (index) ->\r\n if (index==1 or index==\"p1\") then return @p1;\r\n return @;\r\n\r\n\r\n # ## Same as `getAt()` but return as a new Vector\r\n $getAt: (index) -> return new Vector( @getAt(index) );\r\n\r\n\r\n # ## Update p1's new position by recalculating it as a relative position to the anchor point\r\n # @return this Pair\r\n relative: () ->\r\n @p1.add( @ )\r\n return @\r\n\r\n # ## Return a new vector of p1's new position, by recalculating it as a relative position to the anchor point\r\n # @return a new Vector\r\n $relative: () -> @$add( @p1 )\r\n\r\n\r\n # ## Get a new pair that's the bounding box of this pair. This is the same as calculating its top-left (min) and bottom-right (max) points.\r\n # @return a new Pair\r\n bounds: () ->\r\n return new Pair( @$min(@p1) ).to( @$max(@p1) )\r\n\r\n # ## Check if a point is within the bounds of this pair\r\n # @param `pt` a Point object to check.\r\n # @param `axis` optional axis id such as Const.xy.\r\n # @eg `pair.withinBounds( point )`, `pair.withinBounds( point, Const.yz )`\r\n # @demo pair.withinBounds\r\n # @return a boolean value where `true` means the point is within bounds.\r\n withinBounds: ( pt, axis ) ->\r\n if axis\r\n a = @get2D( axis )\r\n b = @p1.get2D( axis )\r\n\r\n # simplify checking for horizontal and vertical lines, and avoid rounding errors\r\n if a.x == b.x\r\n return pt.y >= Math.min(a.y, b.y) and pt.y <= Math.max(a.y, b.y)\r\n else if a.y == b.y\r\n return pt.x >= Math.min(a.x, b.x) and pt.x <= Math.max(a.x, b.x)\r\n\r\n # bounding box check\r\n else\r\n return ( pt.x >= Math.min(a.x, b.x) and pt.y >= Math.min(a.y, b.y) and pt.x <= Math.max(a.x, b.x) and pt.y <= Math.max(a.y, b.y) )\r\n else\r\n return ( pt.x >= Math.min( @x, @p1.x) and pt.y >= Math.min(@y, @p1.y) and pt.z >= Math.min(@z, @p1.z) and pt.x <= Math.max(@x, @p1.x) and pt.y <= Math.max(@y, @p1.y) and pt.z <= Math.max(@z, @p1.z) )\r\n\r\n # ## Interpolate to find a point which lies somewhere on a straight path between the two points of this pair\r\n # @param `t` a value between 0 to 1.\r\n # @param `relative` an optional boolean value. If `true`, then `this.p1` will be treated as relative to the achor point. Default is `false`.\r\n # @eg `pair.interpolate(0.4)` `pair.interpolate(0.1, true)`\r\n # @demo pair.interpolate\r\n # @return the interpolated point as Vector\r\n interpolate: ( t, relative=false ) ->\r\n p2 = if relative then @$relative() else @p1\r\n\r\n return new Vector(\r\n (1-t) * @x + t * p2.x\r\n (1-t) * @y + t * p2.y\r\n (1-t) * @z + t * p2.z\r\n )\r\n\r\n # ## A convenient method to get the midpoint of this pair of points. Same as @interpolate( 0.5 )\r\n # @return the middle point as Vector\r\n midpoint: () -> @interpolate( 0.5 )\r\n\r\n # ## Get a vector which points to the same direction as this pair, but starts at origin (0,0)\r\n # @param `reverse` optional parameter to reverse the direction if set to `true`. Default is `false`.\r\n # @eg `pair.direction()`, `pair.direction(false)`, `pair.direction().normalize()`\r\n # @return the directional vector\r\n direction: ( reverse ) ->\r\n return if reverse then @.$subtract( @p1 ) else @p1.$subtract( @ )\r\n\r\n\r\n # ## Set or get width and height of this pair\r\n # @param `args` Optional parameter to set the size of this Pair. Can be comma-separated values, or as an array, or a Point object.\r\n # @eg `pair.size()`, `pair.size(100, 50)`\r\n # @return When setting a new size, returns self. When getting size, returns a Vector whose x is the width and y is the height.\r\n size: () ->\r\n if arguments.length > 0\r\n @p1 = @.$add( Point.get(arguments) )\r\n return @\r\n else\r\n return @p1.$subtract( @ ).abs()\r\n\r\n # ## Find distance of this pair from anchor to p1\r\n # @param: `sqrt` optional boolean value to get distance-squared value if set to `false`. Default is true.\r\n # @return distance value\r\n length: ( sqrt = true ) ->\r\n dz = @z - @p1.z\r\n dy = @y - @p1.y;\r\n dx = @x - @p1.x;\r\n d = dx*dx + dy*dy + dz*dz\r\n return if sqrt then Math.sqrt( d ) else d\r\n\r\n\r\n # ## Check if a point lies on the left or right side of this pair's *ray*, and if the 3 points are collinear\r\n # @param `point` a Point object to check against this pair.\r\n # @demo pair.collinear\r\n # @return a value where 0 means collinear, poitive value means the point lies on left, and negative value means it's on right\r\n collinear: (point) ->\r\n return (@p1.x - @x) * (point.y - @y) - (point.x - @x) * (@p1.y - @y)\r\n\r\n # ## Recalculate the origin and vec so that origin is at top-left and vec is at bottom-right\r\n # @return this Pair\r\n resetBounds: () ->\r\n temp = @$min( @p1 )\r\n @p1.set( @$max( @p1 ) )\r\n @set( temp )\r\n return @\r\n\r\n # ## override equal() from parent class\r\n equal: (epsilon=false) ->\r\n if arguments[0] instanceof Pair\r\n return super( arguments[0] ) and @p1.equal( arguments[0].p1 )\r\n else\r\n super\r\n\r\n # ## Override clone() from parent class\r\n clone: () ->\r\n p = new Pair( @ )\r\n p.to( @p1.clone() )\r\n return p\r\n\r\n # ## Override floor() from parent class\r\n floor: () ->\r\n super\r\n @p1.floor()\r\n\r\n # ## Describe this Pair as a text string\r\n # @return \"Pair of vectors from ... to ...\" text\r\n toString: () -> \"Pair of vectors from (#{ @x }, #{ @y }, #{ @z }) to (#{ @p1.x }, #{ @p1.y }, #{ @p1.z })\"\r\n\r\n # ## Override toArray() include `p1` in the array.\r\n toArray: () -> [@, @p1]\r\n\r\n\r\n# namespace\r\nthis.Pair = Pair\n# ### There is a shortest path that connects a pair of points. Trace that unique path, with pencil or thread or mind, and you will make a straight line. A line embodies the simplest movement or change. It is a point set in motion, moving to meet another point and leaving a trail behind.\r\nclass Line extends Pair\r\n\r\n # ## Create a new Line. A Line is a Pair defined by two vectors. It can be treated as an infinite line, or as a line segment with two end points.\r\n # @param `args` Similar to Pair constructor, use comma-separated values, an array, or an object as parameters to specify the first point. As a shortcut to `to()`, you can also pass 4 or 6 values to set both anchor and `p1` points directly as a 2d or 3d vector.\r\n # @eg `new Line()` `new Line(1,2,3)` `new Line([2,4])` `new Line({x:3, y:6, z:9}).to(1,2,3)`\r\n # @return a new Pair object\r\n constructor: () ->\r\n super\r\n\r\n\r\n # ## a static function `Line.slope` to find the slope between two points\r\n # @param `a` a Point\r\n # @param `b` another Point\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @eg `Line.slope(pt1, pt2)`, `Line.slope(pt1, pt2, Const.yz)`\r\n # @return slope value, or false if it divides by 0 (a vertical line)\r\n @slope: ( a, b, axis=Const.xy ) ->\r\n p1 = a.get2D( axis )\r\n p2 = b.get2D( axis )\r\n return if (p2.x - p1.x is 0) then false else (p2.y - p1.y) / (p2.x - p1.x)\r\n\r\n\r\n # ## a static function `Line.intercept` to get x and y intercept\r\n # @param `a` a Point\r\n # @param `b` another Point\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @eg `Line.intercept(pt1, pt2)`, `Line.intercept(pt1, pt2, Const.yz)`\r\n # return: an Object with {xi, yi, slope} properties, or false if it divides by 0 (a vertical line)\r\n @intercept: ( a, b, axis=Const.xy ) ->\r\n p1 = a.get2D( axis )\r\n p2 = b.get2D( axis )\r\n if p2.x - p1.x is 0\r\n return false\r\n else\r\n # y = mx + c\r\n m = ((p2.y - p1.y) / (p2.x - p1.x)) # slope\r\n c = p1.y - m * p1.x\r\n return { slope: m, yi: c, xi: if m==0 then false else -c/m } #[ -c/m, c, m ]\r\n\r\n\r\n # ## a static function `Line.isPerpendicularLine` to check if two lines are perpendicular to each other\r\n # @param `line1` a Line\r\n # @param `line2` another Line\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @eg `Line.isPerpendicularLine(ln1, ln2)`, `Line.isPerpendicularLine(ln1, ln2, Const.yz)`\r\n # return a boolean value where `true` means the two lines are perpendicular\r\n @isPerpendicularLine: (line1, line2, axis=Const.xy) ->\r\n s1 = Line.slope( line1, line1.p1, axis )\r\n s2 = Line.slope( line2, line2.p1, axis )\r\n if s1 is false\r\n return (s2 is 0)\r\n else if s2 is false\r\n return (s1 is 0)\r\n else\r\n return (s1*s2 is -1)\r\n\r\n\r\n # ## Get slope of this line\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @return slope value, or false if it divides by 0 (a vertical line)\r\n slope: ( axis=Const.xy ) -> Line.slope( @, @p1, axis )\r\n\r\n\r\n # ## Get intercepts and slop of this line\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # return: an Object with {xi, yi, slope} properties, or false if it divides by 0 (a vertical line)\r\n intercept: ( axis=Const.xy ) -> Line.intercept( @, @p1, axis )\r\n\r\n\r\n # ## Given an interpolated point on this line, return another line of specific length that is perpendicular to this line.\r\n # @param `t` a value between 0 to 1 to interpolate a point on this line\r\n # @param `len` an optional value to specify a length for the new line. Defaults to 10.\r\n # @param `reverse` a boolean value to reverse the direction of the new line if set to `true`\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @eg `ln.getPerpendicular(0.5)`, `ln.getPerpendicular(0.2, 100, true, Const.yz)`\r\n # @demo line.getPerpendicular\r\n # @return a new Line that's perpendicular to this line\r\n getPerpendicular: ( t, len=10, reverse=false, axis=Const.xy ) ->\r\n pn = @direction().normalize().perpendicular( axis ) # get normal vector\r\n pp = if reverse then pn[1] else pn[0] # from which side of the dividing line\r\n line = new Line( @interpolate( t ) ) # the start-point in the new line\r\n line.to( pp.multiply(len).add( line ) ) # connect the end point\r\n return line\r\n\r\n # ## Find the shortest distance from a point to this line (as infinite line, not line segment)\r\n # @param `pt` a Point\r\n # return the distance, which can be positive or negative value depending on the point's position.\r\n getDistanceFromPoint: ( pt ) ->\r\n path = @$subtract( @p1 )\r\n normal = new Vector( -path.y, path.x ).normalize()\r\n return @$subtract( pt ).dot( normal )\r\n\r\n\r\n # ## Find the perpendicular vector from this line to the point. You can connect the resulting vector with the point's position to draw a perpendicular line\r\n # @param `pt` a Point\r\n # @param `fromProjection` a boolean value defaults to true. If true, the resulting vector is based on this line's position. Otherwise the vector starts from origin (0,0).\r\n # @demo line.getPerpendicularFromPoint\r\n # @return a perpendicular Vector\r\n getPerpendicularFromPoint: ( pt, fromProjection=true ) ->\r\n proj = @p1.$subtract(@).projection( pt.$subtract(@) )\r\n return if !fromProjection then proj else proj.add(@)\r\n\r\n\r\n # ## Get intersection point of this line and another line (as infinite lines, not line segements)\r\n # @param `line` another Line\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @return an intersection point as Vector, or `false` if no intersection, or `null` if two lines are identical\r\n intersectPath: ( line, axis=Const.xy ) ->\r\n\r\n a = @intercept( axis )\r\n b = line.intercept( axis )\r\n\r\n p = @get2D( axis )\r\n ln = line.get2D( axis )\r\n\r\n if a == false\r\n if b == false then return false # no solution\r\n # one of them is vertical line, while the other is not, so they will intersect\r\n y1 = -b.slope * (ln.x - p.x) + ln.y # -slope * p.x + p.y\r\n return if axis == Const.xy then new Vector( p.x, y1 ) else new Vector( p.x, y1 ).get2D( axis, true )\r\n\r\n else\r\n # diff slope, or b slope is vertical line\r\n if b == false\r\n y1 = -a.slope * (p.x - ln.x) + p.y # -slope * p.x + p.y\r\n return new Vector( ln.x, y1 )\r\n\r\n else if b.slope != a.slope\r\n px = (a.slope * p.x - b.slope * ln.x + ln.y - p.y) / (a.slope - b.slope)\r\n py = a.slope * ( px - p.x ) + p.y\r\n if axis == Const.xy\r\n return new Vector( px, py )\r\n else\r\n return new Vector( px, py ).get2D( axis, true ) # flip back to intended axis\r\n\r\n else\r\n if a.yi == b.yi # exactly along the same path\r\n return null\r\n else\r\n return false\r\n\r\n\r\n # ## Get intersection point of this line segement and another line segement (not infintie lines)\r\n # @param `line` another Line\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @demo line.intersectLine\r\n # @return an intersection point as Vector, or `false` if no intersection, or `null` if two lines are identical\r\n intersectLine: (line, axis=Const.xy) ->\r\n # get point from intersectPath()\r\n pt = @intersectPath( line, axis )\r\n\r\n # check line segment intersection\r\n if pt and @withinBounds( pt, axis ) and line.withinBounds( pt, axis )\r\n return pt\r\n else\r\n return if pt == null then null else false\r\n\r\n\r\n # ## A static function `Line.intersectLines` if an element intersects with a list of lines ( useful for polygon or polyline such as `rectangle.sides()` ) on xy axis.\r\n # @param `lines` an array of Line\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @eg `Line.intersectLines( rect, triangle.sides() )` `Line.intersectLines( line, pointset.sides(), true )`\r\n # @returns an Array of intersection points, or a boolean value. (Based on `get_pts` parameter)\r\n @intersectLines: (elem, lines, get_pts=true) ->\r\n if !elem.intersectLine\r\n throw \"No intersectLine function found in \"+ elem.toString()\r\n\r\n pts = []\r\n # check each line\r\n for i, ln of lines\r\n ins = elem.intersectLine(ln, get_pts)\r\n\r\n # store intersection points\r\n if ins\r\n if !get_pts then return true\r\n if ins.length > 0\r\n for p in ins\r\n pts.push( p )\r\n\r\n return if get_pts then pts else false\r\n\r\n\r\n # ## Get intersection point of between two \"grid\" lines. Grid lines are parallel to an axis, such as a horizontal or vertical line on xy plane.\r\n # @param `line` another Line which is parallen to an axis\r\n # @param `path_only` a boolean value to specify whether to check for whole path (`true`) or line segment (`false`). Defaults to `false`.\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @return an intersection point as Vector, or `false` if no intersection\r\n intersectGridLine: (line, path_only=false, axis=Const.xy ) ->\r\n a1 = @get2D( axis )\r\n a2 = @p1.get2D( axis )\r\n\r\n b1 = line.get2D( axis )\r\n b2 = line.p1.get2D( axis )\r\n\r\n if a2.x - a1.x == 0\r\n if b2.y - b1.y == 0 and Util.within( a1.x, b1.x, b2.x )\r\n if path_only or Util.within( b1.y, a1.y, a2.y )\r\n return new Vector( a1.x, b1.y )\r\n\r\n else if a2.y - a1.y == 0\r\n if b2.x - b1.x == 0 and Util.within( a1.y, b1.y, b2.y )\r\n if path_only or Util.within( b1.x, a1.x, a2.x )\r\n return new Vector( b1.x, a1.y )\r\n\r\n else\r\n return false\r\n\r\n\r\n # ## Get a list of evenly distributed points on this line\r\n # @param `num` the number of points to get\r\n # @return an Array of Points\r\n subpoints: (num) -> (@interpolate t/num for t in [0..num] )\r\n\r\n\r\n # ## override clone\r\n clone: (deep) ->\r\n return new Line(@).to(@p1)\r\n\r\n\r\n# namespace\r\nthis.Line = Line\r\n\r\n\r\n\r\n# Old code -- Use Matrix transform functions instead\r\n\r\n# Rotate this line from a hinged point along the line\r\n# param: t is between 0 to 1, radian is the rotation\r\n# see also Matrix.rotateAnchor2D\r\n# rotate: (t, radian, axis=Const.xy) ->\r\n# # get anchor point\r\n# anchor = @interpolate( t )\r\n# # get init angle\r\n# ang = anchor.angle( axis, @ ) + radian\r\n#\r\n# # find rotated line's points\r\n# pa = new Vector( Math.cos( ang ), Math.sin( ang ) )\r\n#\r\n# if axis is Const.yz\r\n# pb = new Vector( 0, -pa.y, -pa.z )\r\n# else if axis is Const.xz\r\n# pb = new Vector( -pa.x, 0, -pa.z )\r\n# else\r\n# pb = new Vector( -pa.x, -pa.y, 0 )\r\n#\r\n# pa.multiply( anchor.$subtract( @ ).magnitude() )\r\n# pa.add( anchor )\r\n#\r\n# pb.multiply( @p1.$subtract( anchor ).magnitude() )\r\n# pb.add( anchor )\r\n#\r\n# # set the points to new position\r\n# @set( pa )\r\n# @p1.set( pb )\r\n#\r\n# return @\r\n\r\n\r\n# Reflect a point to the other side of this line\r\n# see also Vector.reflect2D and Matrix.reflectAnchor2D\r\n# reflect: (point, axis=Const.xy) ->\r\n# ln = @intercept( axis )\r\n# p = point.get2D( axis )\r\n# d = ( p.x + (p.y-ln.yi) * ln.slope ) / (1+ ln.slope*ln.slope)\r\n# ref = {\r\n# x: 2*d - p.x,\r\n# y: 2*d*ln.slope - p.y + 2*ln.yi\r\n# }\r\n#\r\n# if axis == Const.xz\r\n# return new Vector( ref.x, point.y, ref.y )\r\n# else if axis == Const.yz\r\n# return new Vector( point.x, ref.x, ref.y )\r\n# else\r\n# return new Vector( ref.x, ref.y, point.z )\n# ### Imagine making a viewfinder with your hands: touch one hand's thumb with the other hand's index finger, and stretch them wide open. Your fingers are the two vectors that define a rectangle, and the rectangle partitions a space and redefines what's inside and outside.\r\nclass Rectangle extends Pair\r\n\r\n # ## Create a new Rectangle. A Rectangle is a Pair whose rectangular bounding box are defined by two Vectors. Use `toPointSet()` to convert it to a PointSet with 4 points if you need to rotate or shear it.\r\n # @param `args` Similar to Pair constructor, use comma-separated values, an array, or an object as parameters to specify the first point. As a shortcut to `to()`, you can also pass 4 or 6 values to set both anchor and `p1` points directly as a 2d or 3d vector.\r\n # @eg `new Rectangle()` `new Rectangle(1,2,3)` `new Rectangle([2,4])` `new Rectangle({x:3, y:6, z:9}).to(1,2,3)`\r\n # @return a new Rectangle object\r\n constructor: () ->\r\n super\r\n\r\n # ## the center point of rectangle as Vector object\r\n @center = new Vector()\r\n\r\n\r\n # ## A static method `Rectangle.contain` to check if a point is within a bound\r\n # @param `pt` the Point to check\r\n # @param `ptl` a Point to specify top-left position of the rectangular bounds\r\n # @param `pbr` a Point to specify bottom-right position of the rectangular bounds\r\n # @return a boolean value indicating if the point is contained within the rectangular bounds\r\n @contain: (pt, ptl, pbr) ->\r\n return (pt.x >= ptl.x && pt.x <= pbr.x && pt.y >= ptl.y && pt.y <= pbr.y && pt.z >= ptl.z && pt.z <= pbr.z)\r\n\r\n\r\n # ## Describe this rectangle as a text string\r\n # @return \"Rectangle x1, y1, z1, x2, y2, z2, width height\" text\r\n toString : ->\r\n s = @size()\r\n \"Rectangle x1 #{@x}, y1 #{@y}, z1 #{@z}, x2 #{@p1.x}, y2 #{@p1.y}, z2 #{@p1.z}, width #{s.x}, height #{s.y}\"\r\n\r\n\r\n # ## Convert this Rectangle from a pair of points to a `PointSet` which has 4 points. Note that if you want to rotate or shear this rectangle, convert this rectangle to a `PointSet` first.\r\n # @return a PointSet with 4 points. (top-right, bottom-right, bottom-left, top-left)\r\n toPointSet: () ->\r\n c = @corners()\r\n return new PointSet( @ ).to( [c.topRight, c.bottomRight, c.bottomLeft, c.topLeft ] )\r\n\r\n\r\n # ## Similar to `Pair`, this function connects the anchor with another point to define the rectangular bounds. This also calls Pair's `resetBounds()` to make sure anchor point is at top-left and `p1` is at bottom-right\r\n # @param `args` comma-separated values, or an array, or an object\r\n # @eg `rect.to(1,2,3)` `new Rect(pt).to([3,4])`\r\n # @return this Rectangle\r\n to: ( args ) ->\r\n @p1 = new Vector( Point.get(arguments) )\r\n @resetBounds()\r\n @center = @midpoint() # get center point also\r\n return @\r\n\r\n\r\n # ## Set center to new location and move this rectangle, or reset the center point based on current size and position.\r\n # @param `args` comma-separated values, or an array, or an object to specify the new position\r\n # @eg `rect.setCenter()`, `rect.setCenter(100,50)`, `rect.setCenter( pt )`\r\n # @return this Rectangle\r\n setCenter: ( args ) ->\r\n if arguments.length == 0\r\n @center = @midpoint();\r\n return;\r\n\r\n halfsize = @size().$divide(2)\r\n @center.set( Point.get(arguments) )\r\n @set( @center.$subtract( halfsize ) )\r\n @p1.set( @center.$add( halfsize ) )\r\n return @\r\n\r\n\r\n # ## resize to a specific size from top left\r\n # @param `args` comma-separated values, or an array, or an object to specify the new size\r\n # @eg `rect.resizeTo(10,10)` `rect.resizeTo( size_vec )`\r\n # @return this Rectangle\r\n resizeTo: () ->\r\n @p1 = new Vector( Point.get(arguments) )\r\n @relative()\r\n @center = @midpoint() # get center point also\r\n return @\r\n\r\n\r\n # ## resize to a specific size from center point\r\n # @param `args` comma-separated values, or an array, or an object to specify the new size.\r\n # @eg `rect.resizeCenterTo(10,10)` `rect.resizeCenterTo( size_vec )`\r\n # @demo rectangle.resizeCenterTo\r\n # @return this Rectangle\r\n resizeCenterTo: () ->\r\n size = new Vector( Point.get(arguments)).divide( 2 ) # get half size\r\n @set( @center.$subtract(size) )\r\n @p1.set( @center.$add(size) )\r\n return @\r\n\r\n\r\n # ## resize this rectangle so that it will enclose another rectangle. Namely, the resulting rectangle is a *union* of the two initial rectangles.\r\n # @param `rect` another Rectangle or Pair object\r\n # @demo rectangle.enclose\r\n # @return this Rectangle which has the new size\r\n enclose: ( rect ) ->\r\n @set( @$min( rect ) )\r\n @p1.set( @p1.$max( rect.p1 ) )\r\n @center = @midpoint() # get center point also\r\n return @\r\n\r\n\r\n # ## Same as `enclose()` but returns a new Rectangle\r\n # @param `rect` another Rectangle or Pair object\r\n # @return a new Rectangle which has the new size\r\n $enclose: ( rect ) -> return @clone().enclose( rect )\r\n\r\n # ## Check if this rectangle encloses (or is enclosed by) another rect. Use with `isLarger()` to check which rectangle is being enclosed.\r\n # @param `rect` another rectangle\r\n # @return a boolean value to indicate if one rectangle is enclosed by another\r\n isEnclosed: ( rect ) ->\r\n d = @$subtract( rect ).multiply( @p1.$subtract( rect.p1 ) )\r\n d2 = @size().subtract( rect.size() )\r\n return d.x <= 0 and d.y <= 0 and d.z <= 0 and (d2.x * d2.y >= 0)\r\n\r\n\r\n # ## Check if this rectangle is larger than another rectangle\r\n # @param `rect` another rectangle\r\n # @return a boolean value to indicate if this rectangle is larger\r\n isLarger: ( rect ) ->\r\n s1 = @size()\r\n s2 = rect.size()\r\n return s1.x * s1.y > s2.x * s2.y\r\n\r\n\r\n # ## Check if a Point is on this Rectangle\r\n # @param `args` comma-separated values, or an array, or a Point object\r\n # @eg `rect.intersectPoint(1,2,3)` `rect.intersectPoint(pt)`\r\n # @return a boolean value to indicate if there is an intersection\r\n intersectPoint: () ->\r\n pt = Point.get(arguments)\r\n return (pt.x >= @x && pt.x <= @p1.x && pt.y >= @y && pt.y <= @p1.y && pt.z >= @z && pt.z <= @p1.z)\r\n\r\n\r\n # ## Check intersections between this Rectangle and an infinite Line on xy axis.\r\n # @param `path` a Pair or Line object to specify an infinite line\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @demo rectangle.intersectPath\r\n # @returns an Array of intersection points (zero or two points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectPath: ( line, get_pts=true ) ->\r\n sides = @sides()\r\n pts = []\r\n for s in sides\r\n p = s.intersectPath( line )\r\n if p and @intersectPoint( p )\r\n if get_pts\r\n pts.push( p )\r\n else\r\n return true\r\n\r\n return if get_pts then pts else false\r\n\r\n\r\n # ## Check intersections between this Rectangle and a Line segment on xy axis.\r\n # @param `line` a Line to check\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero, one, or two points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectLine: (line, get_pts=true) ->\r\n\r\n # check if fully enclosed\r\n ip1 = @intersectPoint( line )\r\n ip2 = @intersectPoint( line.p1 )\r\n if ip1 and ip2 then return if get_pts then [] else true\r\n\r\n # bounding box check\r\n if !(ip1 or ip2)\r\n lbound = line.bounds()\r\n if !@intersectRectangle( lbound, false )\r\n return if get_pts then [] else false\r\n\r\n # check sides\r\n sides = @sides()\r\n pts = []\r\n for s in sides\r\n p = line.intersectLine( s )\r\n if p\r\n if get_pts\r\n pts.push( p )\r\n else\r\n return true\r\n\r\n return if get_pts then pts else false\r\n\r\n\r\n # ## Check if this Rectangle intersects with a list of Lines ( useful for polygon or polyline such as `rectangle.sides()` ) on xy axis.\r\n # @param `lines` an array of Line\r\n # @param `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points, or a boolean value. (Based on `get_pts` parameter)\r\n intersectLines: (lines, get_pts=true) ->\r\n return Line.intersectLines( @, lines, get_pts )\r\n\r\n\r\n # ## Check if this Rectangle intersects with another Rectangle\r\n # @param `rect` a Rectangle to check\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero or two or four points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectRectangle: ( rect, get_pts=true ) ->\r\n\r\n # rectangle intersection check, check for whether it's completely contain\r\n xi = ( @p1.x >= rect.x ) && ( @x <= rect.p1.x )\r\n yi = ( @p1.y >= rect.y ) && ( @y <= rect.p1.y )\r\n zi = ( @p1.z >= rect.z ) && ( @z <= rect.p1.z )\r\n intersected = (xi && yi && zi)\r\n\r\n if !get_pts then return intersected\r\n if @isEnclosed( rect ) then return (if get_pts then [] else true )\r\n\r\n if !intersected then return []\r\n\r\n # pa = new Vector(@max( rect ))\r\n # pb = new Vector(@p1.min( rect.p1 ))\r\n\r\n sidesA = @sides()\r\n sidesB = rect.sides()\r\n\r\n pts = []\r\n for sa in sidesA\r\n for sb in sidesB\r\n\r\n p = sa.intersectGridLine( sb )\r\n if p then pts.push(p)\r\n\r\n return pts\r\n\r\n\r\n\r\n # ## Check if this Rectangle intersect with another element\r\n # @param `item` any object that is based on Point. (Vector, Line, Rectangle, Circle, etc)\r\n # @eg `rect.hasIntersect( another_circle )` `rect.hasIntersect(line)` `rect.hasIntersect(rect)`\r\n # @returns an Array of intersection points or a boolean value. (Based on `get_pts` parameter)\r\n hasIntersect: ( item, get_pts=false ) ->\r\n\r\n # circle intersection check\r\n if item instanceof Circle\r\n return item.intersectLines( @sides(), get_pts )\r\n\r\n # rectangle bounding box check\r\n else if item instanceof Rectangle\r\n return @intersectRectangle( item, get_pts )\r\n\r\n # polygon intersection check\r\n else if item instanceof PointSet or item instanceof Triangle\r\n return @intersectLines(item.sides(), get_pts)\r\n\r\n # line intersection check\r\n else if item instanceof Pair\r\n return @intersectLine( item, get_pts )\r\n\r\n # point intersection check\r\n else if item instanceof Point\r\n return Rectangle.contain( item, @, @p1 )\r\n\r\n else\r\n return if get_pts then [] else false\r\n\r\n\r\n # ## Get the corners of this rectangle as 4 Vectors\r\n # @return an Object with 4 `Vector` objects as {topLeft, topRight, bottomLeft, bottomRight}\r\n corners: () -> {\r\n topLeft: new Vector( Math.min( @x, @p1.x ), Math.min( @y, @p1.y), Math.max( @z, @p1.z) )\r\n topRight: new Vector( Math.max( @x, @p1.x ), Math.min( @y, @p1.y), Math.min( @z, @p1.z) )\r\n bottomLeft: new Vector( Math.min( @x, @p1.x ), Math.max( @y, @p1.y), Math.max( @z, @p1.z) )\r\n bottomRight: new Vector( Math.max( @x, @p1.x ), Math.max( @y, @p1.y), Math.min( @z, @p1.z) )\r\n }\r\n\r\n\r\n # ## Get the sides of this rectangle as 4 lines\r\n # @return an Array of 4 `Line` objects [top, right, bottom, left]\r\n sides: () ->\r\n c = @corners()\r\n return [\r\n new Line( c.topLeft ).to( c.topRight )\r\n new Line( c.topRight ).to( c.bottomRight )\r\n new Line( c.bottomRight ).to( c.bottomLeft )\r\n new Line( c.bottomLeft ).to( c.topLeft )\r\n ]\r\n\r\n # ## Get 4 rectangles from this rectangle by subdividing the quadrants\r\n # @return an Object with 4 `Rectangle` objects as {topLeft, topRight, bottomLeft, bottomRight}\r\n quadrants: () ->\r\n c = @corners()\r\n return {\r\n topLeft: new this.__proto__.constructor( c.topLeft ).to( @center )\r\n topRight: new this.__proto__.constructor( c.topRight ).to( @center )\r\n bottomLeft: new this.__proto__.constructor( c.bottomLeft ).to( @center )\r\n bottomRight: new this.__proto__.constructor( c.bottomRight ).to( @center )\r\n }\r\n\r\n\r\n # override clone\r\n clone: () ->\r\n p = new Rectangle(@).to(@p1)\r\n p.to( @p1.clone() )\r\n return p\r\n\r\n\r\n# namespace\r\nthis.Rectangle = Rectangle\n# ### A grid divides a space into cells, puts things into groups. Like scattering a handful of peas on the chessboard, we can simplify the description of a state by clarifying its context. A grid thus help us interpret spaces and restate forms.\r\nclass Grid extends Rectangle\r\n\r\n # ## Create a new Grid. Like a Rectangle, a Grid's area are defined by two Vectors.\r\n # @param `args` Similar to Pair constructor, use comma-separated values, an array, or an object as parameters to specify the first point. As a shortcut to `to()`, you can also pass 4 or 6 values to set both anchor and `p1` points directly as a 2d or 3d vector.\r\n # @eg `new Grid()` `new Grid(1,2,3)` `new Grid([2,4])` `new Grid({x:3, y:6, z:9}).to(1,2,3)`\r\n # @return a new Grid object\r\n constructor: () ->\r\n super\r\n\r\n # ## grid cell settings as an object with `.type` property which defines the grid type such as \"fix-fix\", and `.size` property which stores the cell size as a Vector object.\r\n @cell = {\r\n type : 'fix-fix'\r\n size: new Vector()\r\n }\r\n\r\n # ## property to specify number of rows in the grid\r\n @rows = 0\r\n\r\n # ## property to specify number of columns in the grid\r\n @columns = 0\r\n\r\n # ## property to store layout and cell states\r\n @layout = []\r\n\r\n # callback from cell generation\r\n @cellCallback = null\r\n\r\n\r\n # ## Describe this grid as a text string\r\n # @return \"Grid width, height, columns, rows, cell\" text\r\n toString: ->\r\n s = @size()\r\n \"Grid width #{s.x}, height #{s.y}, columns #{@columns}, rows #{@rows}, \" +\r\n \"cell (#{@cell.size.x}, #{@cell.size.y}), type #{@cell.type}\"\r\n\r\n\r\n # ## Initiate a grid\r\n # @param `x` a value to specify cell width (if `xtype` parameter is \"fix\" or \"flex\") or column count (if `xtype` parameter is \"stretch\")\r\n # @param `y` a value to specify cell height (if `ytype` parameter is \"fix\" or \"flex\") or row count (if `ytype` parameter is \"stretch\")\r\n # @param `xtype, ytype` a string to specify how columns and rows should be calculated. Use \"fix\" to specify exact cell width or height in pixels, \"flex\" to specify ideal cell width or height in pixels (which allows for flexible rounding to rows or columns), \"stretch\" to specify number of rows or columns only\r\n # @eg `grid.create(100,50)` `grid.create( 10,10, \"stretch\",\"stretch\")` `grid.create( 20,20, \"flex\",\"fix\")`\r\n # @return this grid\r\n init : ( x, y, xtype='fix', ytype='fix' ) ->\r\n\r\n size = @size()\r\n\r\n @cell.type = xtype + '-' + ytype\r\n @rows = y\r\n @columns = x\r\n\r\n # calculate x and columns\r\n # stretch: always fit number of columns\r\n if xtype is 'stretch'\r\n @cell.size.x = size.x / x\r\n @columns = x\r\n # flex: fit as many as possible\r\n else if xtype is 'flex'\r\n @columns = Math.round( size.x / x )\r\n @cell.size.x =size.x / @columns\r\n # fix: cell width is fixed\r\n else # fix\r\n @cell.size.x = x\r\n @columns = Math.floor( size.x / @cell.size.x )\r\n\r\n # calculate y and rows\r\n # stretch: always fit number of rows\r\n if ytype is 'stretch'\r\n @cell.size.y = size.y / y\r\n @rows = y\r\n # flex: fit as many as possible\r\n else if ytype is 'flex'\r\n @rows = Math.round( size.y / y )\r\n @cell.size.y = size.y / @rows\r\n # fix: cell height is fixed\r\n else # fix\r\n @cell.size.y = y\r\n @rows = Math.floor( size.y / @cell.size.y )\r\n\r\n # init layout arrays\r\n if (@layout.length < 1) then @resetLayout()\r\n\r\n return @\r\n\r\n\r\n # ## Define a callback function for cell creation. This will loop through each cell in the grid and call the callback function.\r\n # @param `callback` a callback function with these parameters `( cell_size, cell_position, cell_row, cell_column, cell_type )`\r\n # @demo grid.generate\r\n # @return this grid\r\n generate : ( callback ) ->\r\n if (typeof callback == \"function\")\r\n @cellCallback = callback\r\n return @\r\n\r\n\r\n # ## Generate the grid by looping through each cell\r\n create : () ->\r\n if !@cellCallback then return @\r\n\r\n for c in [0...@columns]\r\n for r in [0...@rows]\r\n cell = @cell.size.clone()\r\n pos = @$add( cell.$multiply( c, r ) ) # cellsize * row-column + grid-position\r\n isOccupied = if (@layout.length > 0 and @layout[0].length > 0) then @layout[r][c]==1 else false;\r\n @cellCallback( cell, pos, r, c, @cell.type, isOccupied )\r\n\r\n return @\r\n\r\n\r\n # ## Get the cell's size as a Vector\r\n # @return a cloned `cell.size` property as Vector\r\n getCellSize: () -> return @cell.size.clone()\r\n\r\n # ## Give a column and a row, get a rectangle which indicates the cell position and size\r\n # @param `c, r` column and row index, respectively\r\n # @param `allowOutofBound` a boolean value to set if the returned rectangle can be outside of the grid\r\n # @eg `grid.cellToRectangle(2, 3)`, `grid.cellToRectangle(2, 5, true)`\r\n # @return a Rectangle\r\n cellToRectangle : (c, r, allowOutofBound=false) ->\r\n # cellsize * row-column + grid-position\r\n if allowOutofBound or (c >= 0 and c < @columns and r >= 0 and r < @rows)\r\n rect = new Rectangle( @$add( @cell.size.$multiply( c, r ) ) ).resizeTo( @cell.size )\r\n return rect\r\n else\r\n return false\r\n\r\n\r\n # ## Give a x,y position, get the corresponding cell on the grid.\r\n # @param `args` 0-3 comma-separated values, or as an array, or a Point object.\r\n # @eg `grid.positionToCell( 100, 50 )`, `grid.positionToCell( [100, 50] )`, `grid.positionToCell( pt )`,\r\n # @return a Vector object whose `x` is the column index and `y` is the row index\r\n positionToCell : (args) ->\r\n pos = new Vector( @_getArgs( arguments ) )\r\n cellpos = pos.$subtract( @ ).$divide( @cell.size ).floor()\r\n cellpos.max( 0, 0 ).min( @columns-1, @rows-1 );\r\n return cellpos\r\n\r\n\r\n # ## Reset the layout and its cell states\r\n # @param `callback` a function with these parameters ( this_grid, cell_row, cell_column ). This will get called after each cell's reset.\r\n # @return this grid\r\n resetLayout : ( callback ) ->\r\n @layout = []\r\n for r in [0...@rows]\r\n @layout[r] = []\r\n for c in [0...@columns]\r\n @layout[r][c] = 0\r\n if callback then callback( @, r, c )\r\n\r\n return @\r\n\r\n\r\n # ## Mark a certain area in the grid layout as occupied\r\n # @param `x, y` column and row index\r\n # @param `w` column width\r\n # @param `h` row size\r\n # @param `occupy` a boolean value to set if this cell should be occupied. Defaults to `true`\r\n # @eg `grid.occupy(0,0, 5,3)`\r\n # @demo grid.occupy\r\n # @return this grid\r\n occupy : ( x, y, w, h, occupy=true ) ->\r\n if (@rows <= 0 or @columns <=0) then return @\r\n if (@layout.length < 1) then @resetLayout()\r\n for c in [0...w]\r\n for r in [0...h]\r\n @layout[ Math.min( @layout.length-1, y+r) ][ x+c] = (if (occupy) then 1 else 0)\r\n\r\n return @\r\n\r\n\r\n # ## Check a certain area in the grid is unoccupied\r\n # @param `x, y` column and row index\r\n # @param `w` column width\r\n # @param `h` row size\r\n # @eg `grid.canFit(0,0, 5,3)`\r\n # @return a boolean value where `true` means the area is unoccupied\r\n canFit : ( x, y, w, h ) ->\r\n\r\n # each cell in specific rows and columns\r\n for currRow in [y...Math.min(@rows, y+h)]\r\n for currCol in [x...Math.min(@columns, x+w)]\r\n cell = @layout[currRow][currCol]\r\n # if cell is filled\r\n if cell? and cell > 0\r\n return false\r\n\r\n return true\r\n\r\n\r\n # ## Fit this area as much as possible within the grid's free ceels\r\n # @param `cols` number of columns\r\n # @param `rows` number of rows\r\n # @return an object with properties `row` and `column` to specify the top left position, `columnSize` and `rowSize` to specify the resulting size in grid units, and `bound` which is the actual area as a Rectangle object.\r\n fit : ( cols, rows ) ->\r\n\r\n # find column size, bound by maximum columns in the grid\r\n # maxColumns = @layout[0].length\r\n colSize = Math.min( cols, @columns )\r\n\r\n # go through each grid cell\r\n # each row\r\n for currRow in [0...@rows]\r\n colCount = colSize # counter to find available columns\r\n freeCol = 0 # start position of first free column\r\n\r\n # each column\r\n for currCol in [0...@columns]\r\n cell = @layout[currRow][currCol]\r\n\r\n # if cell is filled\r\n if cell? and cell > 0\r\n freeCol++ # this column is not free\r\n colCount = colSize # reset colCount if it's counting\r\n\r\n # if cell is not filled\r\n else\r\n # see if the next one fits\r\n colCount--\r\n\r\n # can fit all\r\n if colCount <= 0\r\n\r\n # mark this area as occupied\r\n @occupy( freeCol, currRow, colSize, rows )\r\n\r\n # calculate the bounding box\r\n b = new Rectangle( @$add( @cell.size.$multiply( freeCol, currRow ) ) ) # top left\r\n b.resizeTo( @cell.size.$multiply( colSize, rows ) ) # size\r\n\r\n return {\r\n row: currRow\r\n column: freeCol\r\n columnSize: colSize\r\n rowSize: rows\r\n bound: b\r\n }\r\n\r\n # cannot fit\r\n return false\r\n\r\n\r\n # ## Given a cell's position, get an array of the neighboring cells that surround it\r\n # @param `c` column index\r\n # @param `r` row index\r\n # @eg `grid.neighbors( 3, 2 )`, `(grid.neighbors(3, 2))[Const.top_right]`\r\n # @return an array of neighbors starting from top-left going clockwise. The array values can be Vectors whose `x` is column index and `y` is row index, or `false` if the neighbor cell is out of bounds. You may access the cells semantically by using Const.top_right etc.\r\n neighbors: (c, r) ->\r\n temp = [ [c-1, r-1], [c, r-1], [c+1, r-1], [c+1, r], [c+1, r+1], [c, r+1], [c-1, r+1], [c-1, r] ];\r\n ns = []\r\n for n in temp\r\n if n[0] >= 0 and n[0] < @columns and n[1] >= 0 and n[1] < @rows\r\n ns.push( new Vector( n[0], n[1], @layout[ n[1] ][ n[0] ] ) )\r\n else\r\n ns.push( false )\r\n return ns;\r\n\r\n\r\n\r\n# namespace\r\nthis.Grid = Grid\n# ### Like stargazing, like connecting the dots, like pareidolia, a set of points in space always flickers in our imagination and illuminates potential forms. Perhaps, creativity is the process in which one seeks hidden relationships in these disparate points or ideas, and conjures meanings or polygons.\r\nclass PointSet extends Vector\r\n\r\n # ## Create a new PointSet. A PointSet is a set of points which can repsent a polygon or a polyline or a time series.\r\n # @param `args` Similar to Point constructor, use comma-separated values, an array, or an object as parameters to specify the anchor point. Use `to()` to add points to the set.\r\n # @eg `new PointSet()` `new PointSet(1,2,3)` `new PointSet([2,4])` `new PointSet({x:3, y:6, z:9}).to(1,2,3)` `new PointSet(1,2,3).to([p1, p2, p3, p4, p5])`\r\n # @return a new PointSet object\r\n constructor: () ->\r\n super\r\n\r\n # ## The points in this set as an array\r\n @points = []\r\n\r\n\r\n # ## Describe this rectangle as a text string\r\n # @return \"PointSet [p1... p2... p3...]\" text\r\n toString:() ->\r\n str = \"PointSet [ \"\r\n for p in @points\r\n str += \"#{p.x},#{p.y},#{p.z}, \"\r\n return str+\" ]\"\r\n\r\n\r\n # ## Get a copy of the `points` property as an array\r\n toArray:() -> @points.slice()\r\n\r\n\r\n # ## Add a point or an array of points to this PointSet\r\n # @param `args` either an Array of Points, or a single point defined by comma-separated values, an array, or an object.\r\n # @eg `pset.to( 1,2,3 )` `pset.to([1,2,3]` `pset.to({x:3, y:6, z:9})` `pset.to([p1, p2, p3, p4...])`\r\n # @return this PointSet\r\n to: ( args ) ->\r\n\r\n if arguments.length > 0\r\n # if it's an array of objects.\r\n if Array.isArray( arguments[0] ) and arguments[0].length > 0 and typeof arguments[0][0] is 'object'\r\n for p in arguments[0]\r\n @points.push( new Vector(p) )\r\n\r\n else\r\n @points.push( new Vector( Point.get(arguments ) ) )\r\n\r\n return @\r\n\r\n\r\n # ## Get a point from the set of points based on its index position\r\n # @param `index` index position\r\n # @return a point in the set\r\n getAt: ( index ) ->\r\n return @points[ Math.min( @points.length-1, Math.max(0, index) ) ];\r\n\r\n\r\n # ## Same as `getAt()` but returns a new Vector\r\n $getAt: ( index ) -> return new Vector( @getAt( index ) );\r\n\r\n\r\n # ## Set a point at a specific index position\r\n # @param `index` index position\r\n # @param `p` new point\r\n # @return this set\r\n setAt: ( index, p ) ->\r\n @points[ index ] = p;\r\n return this;\r\n\r\n\r\n # ## Get the number of points in the set\r\n count: () -> return this.points.length;\r\n\r\n # ## Add a point whose position is calculated relative to this PointSet's anchor point\r\n # @param `args` 0-3 comma-separated values, or as an array, or a Point object.\r\n # @eg `pset.connectFromAnchor(1,2)` `pset.connectFromAnchor([2,4])` `pset.connectFromAnchor({x:3, y:6, z:9})`\r\n # @return this PointSet\r\n connectFromAnchor: ( args ) ->\r\n\r\n if arguments.length > 0\r\n if Array.isArray( arguments[0] ) and arguments[0].length > 0 # if it's Array.\r\n for p in arguments[0]\r\n @points.push( @$add(p) )\r\n\r\n else\r\n @points.push( @$add( Point.get(arguments ) ) )\r\n\r\n return @\r\n\r\n\r\n # ## Remove a point or a series of points from this Points set\r\n # @param `index` an index which can be positive or negative integer. If index is negative, the points are removed from the end. For example, `-2` will remove the last 2 points.\r\n # @eg `pset.disconnect(3)`, `pset.disconnect(-2)`\r\n # @return this PointSet\r\n disconnect: (index=-1) ->\r\n if index < 0\r\n @points = @points.slice( 0, @points.length+index )\r\n else\r\n @points = @points.slice( index+1 )\r\n\r\n return @\r\n\r\n\r\n # ## Remove all the points\r\n # @return this PointSet\r\n clear: () ->\r\n @points = []\r\n return @\r\n\r\n\r\n # ## Get an array of Lines that represents this PointSet's sides\r\n # @param `close_path` a boolean value to include the side from last point to first point when set to `true`\r\n # @demo pointset.sides\r\n # @return an array of Lines\r\n sides: ( close_path=true ) ->\r\n lastP = null\r\n sides = []\r\n for p in @points\r\n if lastP then sides.push( new Line(lastP).to(p) )\r\n lastP = p\r\n\r\n if @points.length > 1 and close_path\r\n sides.push( new Line( lastP ).to( @points[0] ) )\r\n\r\n return sides\r\n\r\n # ## Get the angles of each vertice connected by 2 sides\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @return an array of objects `{p0, p1, p2, angle}`\r\n angles: ( axis=Const.xy ) ->\r\n angles = []\r\n for i in [1...@points.length-1] by 1\r\n v1 = @points[i-1].$subtract( @points[i] )\r\n v2 = @points[i+1].$subtract( @points[i] )\r\n angles.push( { p0: @points[i-1], p1: @points[i], p2: @points[i+1], angle: v1.angleBetween( v2 ) } )\r\n\r\n return angles\r\n\r\n\r\n # ## Get the bounding box for this point set.\r\n # @return a Rectangle which is the bounding box of the PointSet\r\n bounds: () ->\r\n Util.boundingBox( @points )\r\n\r\n\r\n # ## Get this PointSet's centroid, which is the averge positions of its points.\r\n # @return the centroid point as Vector\r\n centroid: () ->\r\n Util.centroid( @points )\r\n\r\n\r\n # ## Get a convex hull of the point set using Melkman's algorithm\r\n # @param `sort` a boolean value to sort the `points` by x position first if set to true\r\n # @demo pointset.convexHull\r\n # @return an array of Vectors to define the convex hull\r\n convexHull: ( sort=true ) ->\r\n\r\n if @points.length < 3 then return []\r\n\r\n # sort points array first or not\r\n if sort\r\n pts = @points.slice()\r\n pts.sort( (a, b) -> return a.x - b.x )\r\n else\r\n pts = @points\r\n\r\n # if pt is on left of ray ab. Similar to Pari.collinear()\r\n left = (a, b, pt) ->\r\n (b.x - a.x) * (pt.y - a.y) - (pt.x - a.x) * (b.y - a.y) > 0\r\n\r\n # double end queue\r\n dq = []\r\n\r\n # first 3 points\r\n if left( pts[0], pts[1], pts[2])\r\n dq.push( pts[0] )\r\n dq.push( pts[1] )\r\n else\r\n dq.push( pts[1] )\r\n dq.push( pts[0] )\r\n\r\n dq.unshift( pts[2] )\r\n dq.push( pts[2] )\r\n\r\n # remaining points\r\n i = 3\r\n while i < pts.length\r\n pt = pts[i]\r\n\r\n if left( pt, dq[0], dq[1] ) and left(dq[dq.length-2], dq[dq.length-1], pt)\r\n i++\r\n continue\r\n\r\n while !left(dq[dq.length-2], dq[dq.length-1], pt)\r\n dq.pop()\r\n dq.push( pt )\r\n\r\n while !left( dq[0], dq[1], pt)\r\n dq.shift()\r\n dq.unshift( pt )\r\n\r\n i++\r\n\r\n # returns the hull's points\r\n return dq\r\n\r\n\r\n # overrides clone\r\n clone: () ->\r\n new PointSet(@).to( Util.clonePoints( @points ) )\r\n\r\n\r\n# namespace\r\nthis.PointSet = PointSet\n# ### A straight line or a moving particle, swayed by external forces or internal constraints, gradually deviates from its ideal path and becomes a curve. A river meanders and a strain of hair curls. A curve expresses the effects of forces and constraints.\r\nclass Curve extends PointSet\r\n\r\n # ## Create a new Curve. A Curve uses a set of anchor and/or control points to interpolate a curve.\r\n # @param `args` Similar to PointSet constructor, use comma-separated values, an array, or an object as parameters to specify the anchor point. Use `to()` to add points to the set.\r\n # @eg `new PointSet()` `new PointSet(1,2,3)` `new PointSet([2,4])` `new PointSet({x:3, y:6, z:9}).to(1,2,3)` `new PointSet(1,2,3).to([p1, p2, p3, p4, p5])`\r\n # @return a new Curve object\r\n constructor: () ->\r\n super\r\n\r\n # ## a boolean value to specify if this Curve is 2D or 3D. Default is `false` (2D).\r\n @is3D = false\r\n\r\n\r\n # A private function to pre-calculate the interpolation steps\r\n _getSteps: (steps) ->\r\n ts = []\r\n for s in [0..steps] by 1\r\n t = s/steps\r\n ts.push( [t, t*t, t*t*t] )\r\n return ts\r\n\r\n\r\n # ## Given an index for the starting position in `points` array, get the control and/or end points of a curve segment\r\n # @param `index` start index in `points` array. Default is 0.\r\n # @param `copyStart` an optional boolean value to indicate if the start index should be used twice. Default is false.\r\n # @return an object with 4 points `{p0, p1, p2, p3}`\r\n controlPoints: ( index=0, copyStart=false ) ->\r\n\r\n _index = (i) =>\r\n idx = if i < @points.length-1 then i else @points.length-1\r\n return idx\r\n\r\n # Get points based on index\r\n p0 = @points[index] # control pt 1\r\n if !p0.x? then return false\r\n\r\n index = if copyStart then index else index+1\r\n\r\n p1 = @points[ _index(index++) ] # t = 0\r\n p2 = @points[ _index(index++) ] # t = 1\r\n p3 = @points[ _index(index++) ] # control pt 2\r\n\r\n return {\r\n p0: p0\r\n p1: p1\r\n p2: p2\r\n p3: p3\r\n }\r\n\r\n\r\n # ## Create a Catmull-Rom curve. Catmull-Rom is a kind of Cardinal curve with smooth-looking curve.\r\n # @param `step` the number of line segments. Defaults to 10 steps.\r\n # @return an array of Points\r\n catmullRom: ( steps=10 ) ->\r\n\r\n if @points.length < 2 then return []\r\n\r\n ps = []\r\n ts = @_getSteps( steps )\r\n\r\n # use first point twice\r\n c = @controlPoints( 0, true )\r\n for i in [0..steps] by 1\r\n ps.push( @catmullRomPoint( ts[i], c ) )\r\n\r\n # go through all the points\r\n k = 0\r\n while k < @points.length-2\r\n c = @controlPoints( k )\r\n if c\r\n for i in [0..steps] by 1\r\n ps.push( @catmullRomPoint( ts[i], c ) )\r\n k++\r\n\r\n return ps\r\n\r\n\r\n # ## Interpolate to get a point on Catmull-Rom curve\r\n # @param `step` the point to interpolate, as an array of `[t, t*t, t*t*t]` where `t` is between 0 to 1\r\n # @param `ctrls` the control points which can be provided by `controlPoints()` function\r\n # @return a Point on the curve\r\n catmullRomPoint: ( step, ctrls ) ->\r\n # Basis Matrix (http://mrl.nyu.edu/~perlin/courses/fall2002/hw/12.html)\r\n # {-0.5, 1.5, -1.5, 0.5}\r\n # { 1 , -2.5, 2 ,-0.5},\r\n # {-0.5, 0 , 0.5, 0 },\r\n # { 0 , 1 , 0 , 0 }\r\n\r\n t = step[0]\r\n t2 = step[1]\r\n t3 = step[2]\r\n\r\n h1 = ( -0.5*t3 + t2 - 0.5*t )\r\n h2 = ( 1.5*t3 - 2.5*t2 + 1 )\r\n h3 = ( -1.5*t3 + 2*t2 + 0.5*t )\r\n h4 = ( 0.5*t3 - 0.5*t2 )\r\n\r\n x = ( h1*ctrls.p0.x + h2* ctrls.p1.x + h3*ctrls.p2.x + h4*ctrls.p3.x )\r\n y = ( h1*ctrls.p0.y + h2* ctrls.p1.y + h3*ctrls.p2.y + h4*ctrls.p3.y )\r\n z = if !@is3D then 0 else ( h1*ctrls.p0.z + h2* ctrls.p1.z + h3*ctrls.p2.z + h4*ctrls.p3.z )\r\n\r\n return new Point(x,y,z)\r\n\r\n\r\n # ## Create a Cardinal spline curve\r\n # @param `step` the number of line segments. Defaults to 10 steps.\r\n # @param `tension` optional value between 0 to 1 to specify a \"tension\". Default to 0.5 which is the tension for Catmull-Rom curve\r\n # @demo curve.cardinal\r\n # @return an array of Points\r\n cardinal: ( steps=10, tension=0.5 ) ->\r\n\r\n if @points.length < 2 then return []\r\n\r\n ps = []\r\n ts = @_getSteps( steps )\r\n\r\n # use first point twice\r\n c = @controlPoints( 0, true )\r\n for i in [0..steps] by 1\r\n ps.push( @cardinalPoint( ts[i], c, tension ) )\r\n\r\n # go through all the points\r\n k = 0\r\n while k < @points.length-2\r\n c = @controlPoints( k )\r\n if c\r\n for i in [0..steps] by 1\r\n ps.push( @cardinalPoint( ts[i], c, tension ) )\r\n k++\r\n\r\n return ps\r\n\r\n\r\n # ## Interpolate to get a point on Cardinal curve\r\n # @param `step` the point to interpolate, as an array of `[t, t*t, t*t*t]` where `t` is between 0 to 1\r\n # @param `ctrls` the control points which can be provided by `controlPoints()` function\r\n # @param `tension` optional value between 0 to 1 to specify a \"tension\". Default to 0.5 which is the tension for Catmull-Rom curve\r\n # @return a Point on the curve\r\n cardinalPoint: ( step, ctrls, tension=0.5 ) ->\r\n\r\n # Basis Matrix (http://algorithmist.wordpress.com/2009/10/06/cardinal-splines-part-4/)\r\n # [ -s 2-s s-2 s ]\r\n # [ 2s s-3 3-2s -s ]\r\n # [ -s 0 s 0 ]\r\n # [ 0 1 0 0 ]\r\n\r\n t = step[0]\r\n t2 = step[1]\r\n t3 = step[2]\r\n\r\n h1 = tension * ( -1*t3 + 2*t2 - t )\r\n h2 = tension * ( -1*t3 + t2 )\r\n h2a = (2*t3 - 3*t2 + 1)\r\n h3 = tension * ( t3 - 2*t2 + t )\r\n h3a = (-2*t3 + 3*t2)\r\n h4 = tension * ( t3 - t2 )\r\n\r\n x = ctrls.p0.x*h1 + ctrls.p1.x*h2 + h2a*ctrls.p1.x + ctrls.p2.x*h3 + h3a*ctrls.p2.x + ctrls.p3.x*h4\r\n y = ctrls.p0.y*h1 + ctrls.p1.y*h2 + h2a*ctrls.p1.y + ctrls.p2.y*h3 + h3a*ctrls.p2.y + ctrls.p3.y*h4\r\n z = if !@is3D then 0 else ctrls.p0.z*h1 + ctrls.p1.z*h2 + h2a*ctrls.p1.z + ctrls.p2.z*h3 + h3a*ctrls.p2.z + ctrls.p3.z*h4\r\n\r\n return new Point(x,y,z)\r\n\r\n\r\n # ## Create a Bezier curve. In a cubic bezier curve, the first and 4th points are end points, and 2nd and 3rd points are control points.\r\n # @param `step` the number of line segments. Defaults to 10 steps\r\n # @demo curve.bezier\r\n # @return an array of Points\r\n bezier: ( steps=10 ) ->\r\n\r\n if @points.length < 4 then return []\r\n\r\n ps = []\r\n ts = @_getSteps( steps )\r\n\r\n # go through all the points\r\n k = 0\r\n while k <= @points.length-3\r\n c = @controlPoints( k )\r\n if c\r\n for i in [0..steps] by 1\r\n ps.push( @bezierPoint( ts[i], c ) )\r\n # go to the next set of point, but assume current end pt is next start pt\r\n k+=3\r\n\r\n return ps\r\n\r\n\r\n # ## Interpolate to get a point on a cubic Bezier curve\r\n # @param `step` the point to interpolate, as an array of `[t, t*t, t*t*t]` where `t` is between 0 to 1\r\n # @param `ctrls` the control and end points which can be provided by `controlPoints()` function. The first and 4th points are end points, and 2nd and 3rd points are control points.\r\n # @return a Point on the curve\r\n bezierPoint: (step, ctrls) ->\r\n # Bezier basis matrix\r\n # { -1, 3, -3, 1 }\r\n # { 3, -6, 3, 0 }\r\n # { -3, 3, 0, 0 }\r\n # { 1, 0, 0, 0 }\r\n\r\n t = step[0]\r\n t2 = step[1]\r\n t3 = step[2]\r\n\r\n h1 = ( -1*t3 + 3*t2 - 3*t + 1 )\r\n h2 = ( 3*t3 - 6*t2 + 3*t )\r\n h3 = ( -3*t3 + 3*t2 )\r\n h4 = t3\r\n\r\n x = ( h1*ctrls.p0.x + h2* ctrls.p1.x + h3*ctrls.p2.x + h4*ctrls.p3.x )\r\n y = ( h1*ctrls.p0.y + h2* ctrls.p1.y + h3*ctrls.p2.y + h4*ctrls.p3.y )\r\n z = if !@is3D then 0 else ( h1*ctrls.p0.z + h2* ctrls.p1.z + h3*ctrls.p2.z + h4*ctrls.p3.z )\r\n\r\n return new Point(x,y,z)\r\n\r\n\r\n # ## Create a B-Spline cuve\r\n # @param `step` the number of line segments. Defaults to 10 steps.\r\n # @param `tension` optional value between 0 to 1 to specify a \"tension\". Or `false` to have normal tension. Default is false.\r\n # @demo curve.bspline\r\n # @return an array of Points\r\n bspline: ( steps=10, tension=false ) ->\r\n\r\n if @points.length < 2 then return []\r\n\r\n ps = []\r\n ts = @_getSteps( steps )\r\n\r\n # go through all the points\r\n k = 0\r\n while k < @points.length-2\r\n c = @controlPoints( k )\r\n if c\r\n if !tension\r\n for i in [0..steps] by 1\r\n ps.push( @bsplinePoint( ts[i], c ) )\r\n else\r\n for i in [0..steps] by 1\r\n ps.push( @bsplineTensionPoint( ts[i], c, tension ) )\r\n k++\r\n\r\n return ps\r\n\r\n\r\n # ## Interpolate to get a point on B-Spline curve\r\n # @param `step` the point to interpolate, as an array of `[t, t*t, t*t*t]` where `t` is between 0 to 1\r\n # @param `ctrls` the control points which can be provided by `controlPoints()` function\r\n # @return a Point on the curve\r\n bsplinePoint: (step, ctrls) ->\r\n # Basis matrix:\r\n # { -1.0/6.0, 3.0/6.0, -3.0/6.0, 1.0/6.0 },\r\n # { 3.0/6.0, -6.0/6.0, 3.0/6.0, 0.0 },\r\n # { -3.0/6.0, 0.0, 3.0/6.0, 0.0 },\r\n # { 1.0/6.0, 4.0/6.0, 1.0/6.0, 0.0 }\r\n\r\n t = step[0]\r\n t2 = step[1]\r\n t3 = step[2]\r\n\r\n h1 = ( -0.16666666666*t3 + 0.5*t2 - 0.5*t + 0.16666666666 )\r\n h2 = ( 0.5*t3 - t2 + 0.66666666666 )\r\n h3 = ( -0.5*t3 + 0.5*t2 + 0.5*t + 0.16666666666 )\r\n h4 = (0.16666666666*t3)\r\n\r\n x = ( h1*ctrls.p0.x + h2* ctrls.p1.x + h3*ctrls.p2.x + h4*ctrls.p3.x )\r\n y = ( h1*ctrls.p0.y + h2* ctrls.p1.y + h3*ctrls.p2.y + h4*ctrls.p3.y )\r\n z = if !@is3D then 0 else ( h1*ctrls.p0.z + h2* ctrls.p1.z + h3*ctrls.p2.z + h4*ctrls.p3.z )\r\n\r\n return new Point(x,y,z)\r\n\r\n\r\n # ## Interpolate to get a point on B-Spline curve with tension (Duff)\r\n # @param `step` the point to interpolate, as an array of `[t, t*t, t*t*t]` where `t` is between 0 to 1\r\n # @param `ctrls` the control points which can be provided by `controlPoints()` function\r\n # @param `tension` optional value between 0 to 1 to specify a \"tension\". Default to 1 which is the normal tension.\r\n # @return a Point on the curve\r\n bsplineTensionPoint: (step, ctrls, tension=1) ->\r\n # Basis matrix:\r\n # [ -1/6a, 2 - 1.5a, 1.5a - 2, 1/6a ]\r\n # [ 0.5a, 2a-3, 3-2.5a 0 ]\r\n # [ -0.5a, 0, 0.5a, 0 ]\r\n # [ 1/6a, 1 - 1/3a, 1/6a, 0 ]\r\n\r\n t = step[0]\r\n t2 = step[1]\r\n t3 = step[2]\r\n\r\n h1 = tension * ( -0.16666666666*t3 + 0.5*t2 - 0.5*t + 0.16666666666 )\r\n h2 = tension * ( -1.5*t3 + 2*t2 - 0.33333333333 )\r\n h2a = (2*t3 - 3*t2 + 1)\r\n h3 = tension * ( 1.5*t3 - 2.5*t2 + 0.5*t + 0.16666666666 )\r\n h3a = (-2*t3 + 3*t2)\r\n h4 = tension * (0.16666666666*t3)\r\n\r\n x = ( h1*ctrls.p0.x + h2*ctrls.p1.x + h2a*ctrls.p1.x + h3*ctrls.p2.x + h3a*ctrls.p2.x + h4*ctrls.p3.x )\r\n y = ( h1*ctrls.p0.y + h2*ctrls.p1.y + h2a*ctrls.p1.y + h3*ctrls.p2.y + h3a*ctrls.p2.y + h4*ctrls.p3.y )\r\n z = if !@is3D then 0 else ( h1*ctrls.p0.z + h2* ctrls.p1.z + h2a*ctrls.p1.y + h3*ctrls.p2.z + h3a*ctrls.p2.z + h4*ctrls.p3.z )\r\n\r\n return new Point(x,y,z)\r\n\r\n\r\n# namespace\r\nthis.Curve = Curve\n# ### There are so many ways to construct, and to dissect, a triangle. Various center points, circle inner or outer, imaginary lines cutting through its interiors, bisecting angles or sides, and yet it seems perfectly poised with its three sides and 180 degrees internal angles. A triangle encapsulates tension and plasticity.\r\nclass Triangle extends Vector\r\n\r\n # ## Create a new triangle\r\n # @param Set the triangle's anchor point using 0 to 3 values. Can be comma-separated values, as an array, or as an object with `{x, y, z}` properties.\r\n # @eg `new Triangle()` `new Triangle(1,2,3)` `new Triangle([2,4])` `new Triangle({x:3, y:6, z:9})`\r\n # @return a new Triangle object\r\n constructor: () ->\r\n super\r\n\r\n # ## a vertice (corner point) of the triangle as Vector object\r\n @p1 = new Vector( @x-1, @y-1, @z)\r\n\r\n # ## another vertice (corner point) of the triangle as Vector object\r\n @p2 = new Vector( @x+1, @y+1, @z)\r\n\r\n\r\n # ## Connect triangle's anchor point with the other two points\r\n # @param Parameters can be 2 objects or 2 arrays, or 4 or 6 numeric values to specify x, y, and optionally z positions\r\n # @eg `tri.to( p1, p2)` `tri.to([1,2], [3,4]` `tri.to(1,2,3,4)` `tri.to(1,3,5,2,4,6)`\r\n # @return this triangle\r\n to:( args ) ->\r\n\r\n if arguments.length > 0\r\n\r\n # by object or array\r\n if typeof arguments[0] is 'object' and arguments.length == 2\r\n @p1.set( arguments[0] )\r\n @p2.set( arguments[1] )\r\n\r\n # by 4 or 6 numeric values\r\n else\r\n if arguments.length < 6\r\n @p1.set( [arguments[0], arguments[1]] )\r\n @p2.set( [arguments[2], arguments[3]] )\r\n else\r\n @p1.set( [arguments[0], arguments[1], arguments[2]] )\r\n @p2.set( [arguments[3], arguments[4], arguments[5]] )\r\n\r\n return @\r\n\r\n\r\n # ## Convert this triangle's points to an array of Vectors\r\n # @return an array of 3 vectors\r\n toArray: () -> [@, @p1, @p2 ]\r\n\r\n\r\n # ## Get a text string that describes this triangle\r\n toString:() -> \"Triangle (#{@x}, #{@y}, #{@z}), (#{@p1.x}, #{@p1.y}, #{@p1.z}), (#{@p2.x}, #{@p2.y}, #{@p2.z})\"\r\n\r\n\r\n # ## Get a point from the set of points based on its index position\r\n # @param `index` index position as number (0, 1, 2) or as string \"p0\", \"p1\", \"p2\"\r\n # @return a point in the triangle\r\n getAt: (index) ->\r\n if (index==1 or index==\"p1\") then return @p1;\r\n if (index==2 or index==\"p2\") then return @p2;\r\n return @;\r\n\r\n\r\n # ## Same as `getAt()` but return as a new Vector\r\n $getAt: (index) -> return new Vector( @getAt(index) );\r\n\r\n\r\n # ## Convert this Triangle to a `PointSet`\r\n # @return a PointSet with 3 points.\r\n toPointSet: () ->\r\n p0 = new Vector(@)\r\n return new PointSet( p0 ).to( [p0, @p1, @p2 ] )\r\n\r\n\r\n # ## Get an array of Lines that represents this triangle's 3 sides\r\n # @return an array of 3 lines\r\n sides: () ->\r\n return [\r\n new Line(@).to(@p1)\r\n new Line(@p1).to(@p2)\r\n new Line(@p2).to(@)\r\n ]\r\n\r\n\r\n # ## Get the triangle's 3 angles\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @return an array of 3 angles\r\n angles: ( axis=Const.xy ) ->\r\n angles = [\r\n @p2.$subtract( @ ).angleBetween( @p1.$subtract( @ ), axis )\r\n @$subtract( @p1 ).angleBetween( @p2.$subtract( @p1 ), axis )\r\n ]\r\n angles.push( Math.PI - angles[0] - angles[1] )\r\n return angles\r\n\r\n\r\n # ## Get the medial, which is an inner triangle formed by connecting the midpoints of this triangle's sides\r\n # @return the medial triangle\r\n medial: () ->\r\n sides = @sides()\r\n pts = ( side.midpoint() for side in sides )\r\n return new Triangle( pts[0] ).to( pts[1], pts[2] )\r\n\r\n\r\n # ## Get this triangle's perimeter, which is the length of its 3 sides\r\n # @return an object with 3 properties, where `.value` is the perimeter value, `.sides` is an array of 3 sides, `lengths` is an array of the 3 sides' lengths\r\n perimeter: () ->\r\n sides = @sides()\r\n lens = [\r\n sides[0].length()\r\n sides[1].length()\r\n sides[2].length()\r\n ]\r\n return {\r\n sides: sides\r\n value: lens[0] + lens[1] + lens[2]\r\n lengths: lens\r\n }\r\n\r\n\r\n # ## Get this triangle's area using Heron's formula for calculating polygon area\r\n # @return an object with 2 properties, where `.value` is the area value, and `.perimeter` is an object returned by `perimeter()` function\r\n area: () ->\r\n p = @perimeter()\r\n hp = p.value / 2\r\n return {\r\n value: Math.sqrt( (hp * (hp-p.lengths[0]) * (hp-p.lengths[1]) * (hp-p.lengths[2]) ))\r\n perimeter: p\r\n }\r\n\r\n\r\n # ## Given a point of the triangle, the opposite side is the side which the point doesn't touch\r\n # @param specify a point by its id `\"p0\"` (the anchor point), `\"p1\"`, or `\"p2\"`\r\n # @eg `tri.oppositeSide(\"p1\")`\r\n # @demo triangle.oppositeSide\r\n # @return a Line which represents the opposite side\r\n oppositeSide: ( id ) ->\r\n if id==\"p1\"\r\n return new Line(@).to(@p2)\r\n else if id == \"p2\"\r\n return new Line(@).to(@p1)\r\n else\r\n return new Line(@p1).to(@p2)\r\n\r\n\r\n # ## Given a point of the triangle, the adjacent sides are the two side which the point touches\r\n # @param specify a point by its id `\"p0\"` (the anchor point), `\"p1\"`, or `\"p2\"`\r\n # @eg `tri.adjacentSides(\"p1\")`\r\n # @return an array of 2 Line which represents the adjacent sides\r\n adjacentSides: (id) ->\r\n if id==\"p1\"\r\n return [new Line(@p1).to(@), new Line(@p1).to(@p2)]\r\n else if id == \"p2\"\r\n return [new Line(@p2).to(@), new Line(@p2).to(@p1)]\r\n else\r\n return [new Line(@).to(@p1), new Line(@).to(@p2)]\r\n\r\n\r\n # ## Get a bisector, which is a path that splits a triangle's angle in half.\r\n # @param the first paramter specifies a point by its id `\"p0\"`, `\"p1\"`, or `\"p2\"`. The second parameter determines if the path should be a simple vector from origin (`false`) or a line connected to the triangle's point (`true`). Optionally include a third parameter to set the length of the path.\r\n # @eg `tri.bisector(\"p1\")`, `tri.bisector(\"p0\", true)`, `tri.bisector(\"p2\", false, 10)`\r\n # @return either a Line or a Vector, based on the second parameter\r\n bisector: (id, asLine=false, size=100) ->\r\n ad = @adjacentSides(id)\r\n p = new Vector(ad[0])\r\n ad[0].moveTo(0,0)\r\n ad[1].moveTo(0,0)\r\n bp = ad[0].p1.bisect(ad[1].p1) # bisect vector from origin\r\n\r\n return if asLine then new Line(p).to( bp.multiply(size).add(p) ) else bp\r\n\r\n\r\n # ## Get a triangle's altitude, which is a line from a triangle's point to its opposite side, and perpendicular to its opposite side.\r\n # @param specify a point by its id `\"p0\"` (the anchor point), `\"p1\"`, or `\"p2\"`\r\n # @eg `tri.altitude(\"p1\")` gets a line from p1 to the side formed by p0 and p2\r\n # @return a Line representing an altitude\r\n altitude: ( id ) ->\r\n if id==\"p1\" or id==\"p2\"\r\n return new Line(@[id]).to( @oppositeSide(id).getPerpendicularFromPoint( @[id] ) )\r\n else\r\n return new Line(@).to( @oppositeSide().getPerpendicularFromPoint( @ ) )\r\n\r\n\r\n # ## Get a triangle's centroid, which is the averge positions of its three points.\r\n # @return the centroid point as Vector\r\n centroid : () ->\r\n c0 = @$divide(3)\r\n c1 = @p1.$divide(3)\r\n c2 = @p2.$divide(3)\r\n return new Vector(c0.x+c1.x+c2.x, c0.y+c1.y+c2.y, c0.z+c1.z+c2.z)\r\n\r\n\r\n # ## Get orthocenter, which is the intersection point of a triangle's 3 altitudes (the 3 lines that are perpendicular to its 3 opposite sides).\r\n # @return the orthocenter point as Vector\r\n orthocenter: () ->\r\n a = @altitude()\r\n b = @altitude(\"p1\")\r\n return a.intersectPath( b, Const.xyz )\r\n\r\n\r\n # ## Get incenter, which is the center point of its inner circle, and also the intersection point of its 3 angle bisector lines (each of which cuts one of the 3 angles in half).\r\n # @demo triangle.incenter\r\n # @return the incenter point as Vector\r\n incenter: () ->\r\n a = @bisector(\"p0\", true)\r\n b = @bisector(\"p1\", true)\r\n return a.intersectPath( b, Const.xyz )\r\n\r\n\r\n # ## Get an interior circle, which is the largest circle completed enclosed by this triangle\r\n # @return a Circle\r\n incircle: () ->\r\n center = @incenter()\r\n area = @area()\r\n radius = 2 * area.value / area.perimeter.value\r\n return new Circle(center).setRadius( radius )\r\n\r\n\r\n # ## Get circumcenter, which is the intersection point of its 3 perpendicular bisectors lines ( each of which divides a side in half and is perpendicular to the side)\r\n # @return an object with { `center`: circumcenter point as Vector, `bisector`: an array of bisectors }\r\n circumcenter: () ->\r\n medial = @medial()\r\n\r\n # find perpendicular bisectors\r\n pbs = [\r\n new Line( medial ).to( @.$subtract( medial ).perpendicular()[0].$add(medial) )\r\n new Line( medial.p1 ).to( @p1.$subtract( medial.p1 ).perpendicular()[0].$add(medial.p1) )\r\n new Line( medial.p2 ).to( @p2.$subtract( medial.p2 ).perpendicular()[0].$add(medial.p2) )\r\n ]\r\n\r\n return {\r\n center: pbs[0].intersectPath( pbs[1], Const.xyz )\r\n bisectors: pbs\r\n }\r\n\r\n\r\n # ## Get circumcircle, which is the smaller circle that encloses this triangle completely\r\n # @return a Circle\r\n circumcircle: () ->\r\n center = @circumcenter()\r\n r = @magnitude( center.center )\r\n return new Circle( center.center ).setRadius( r )\r\n\r\n\r\n intersectPoint: (p) ->\r\n sides = @sides()\r\n hp = ( s.collinear(p) > 0 for s in sides ) # check left or right sides of the half plane\r\n return hp[0] == hp[1] and hp[1] == hp[2]\r\n\r\n\r\n # ## Check intersections between this Triangle and an infinite Line on xy axis.\r\n # @param `path` a Pair or Line object to specify an infinite line\r\n # @param `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero or two points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectPath: (path, get_pts=true, axis=Const.xy) ->\r\n sides = @sides()\r\n pts = []\r\n for s in sides\r\n p = s.intersectPath( path )\r\n if p and s.withinBounds( p, axis )\r\n if !get_pts then return true\r\n pts.push( p )\r\n\r\n return if get_pts then pts else false\r\n\r\n\r\n # ## Check intersections between this Triangle and a Line segment on xy axis.\r\n # @param `line` a Line to check\r\n # @param `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero, one, or two points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectLine: (line, get_pts=true, axis=Const.xy) ->\r\n ins = @intersectPath( line, true, axis )\r\n pts = []\r\n for p in ins\r\n if line.withinBounds( p )\r\n if !get_pts then return true\r\n pts.push( p )\r\n\r\n return if get_pts then pts else false\r\n\r\n\r\n # ## Check if this Triangle intersects with a set of Lines on xy axis\r\n # @param `lines` an array of Line\r\n # @param `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points, or a boolean value. (Based on `get_pts` parameter)\r\n intersectLines: (lines, get_pts=true) ->\r\n return Line.intersectLines( @, lines, get_pts )\r\n\r\n\r\n # ## Moller-Trumbore algorithm for 3D ray triangle intersection\r\n intersectPath3D: (path, get_pts) ->\r\n e1 = @p1.$subtract(@)\r\n e2 = @p2.$subtract(@)\r\n dir = path.direction().normalize()\r\n\r\n pvec = dir.cross(e2)\r\n det = e1.dot(pvec)\r\n\r\n # 3D only, in 2D the det is always 0\r\n if (det > -Const.epsilon and det < Const.epsilon ) then return false\r\n\r\n inv_det = 1 / det\r\n\r\n tvec = path.$subtract(@)\r\n u = tvec.dot(pvec) * inv_det\r\n if (u < 0 or u > 1) then return false\r\n\r\n qvec = tvec.cross( e1 )\r\n v = dir.dot(qvec) * inv_det\r\n if (v < 0 or v > 1) then return false\r\n\r\n t = e2.dot( qvec ) * inv_det\r\n if t > Const.epsilon\r\n return if get_pts then [u,v,t] else true\r\n else\r\n return false\r\n\r\n\r\n # ## Check if this Triangle intersects with a Rectangle\r\n # @param `rect` a Rectangle to check\r\n # @param `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero or two or four points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectRectangle: (rect, get_pts=true) ->\r\n return rect.intersectLines( @sides(), get_pts )\r\n\r\n\r\n # ## Check if this Triangle intersects with another Circle\r\n # @param `circle` a Circle to check\r\n # @param `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero or two or four points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectCircle: (circle, get_pts=true) ->\r\n return circle.intersectLines( @sides(), get_pts )\r\n\r\n\r\n # ## Check if this Triangle intersects with another Triangle\r\n # @param `tri` a Triangle to check\r\n # @param `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero or two or four points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectTriangle: (tri, get_pts=true) ->\r\n return tri.intersectLines( @sides(), get_pts )\r\n\r\n\r\n # overrides clone\r\n clone: () -> new Triangle(@).to( @p1, @p2 )\r\n\r\n\r\n# namespace\r\nthis.Triangle = Triangle\r\n\r\n"]} \ No newline at end of file +{"version":3,"sources":["pt-core.coffee"],"names":[],"mappings":";AACA;AAAA,IAAA,iMAAA;EAAA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,SAAC,IAAD,EAAO,OAAP;;MAAO,UAAQ;;AACjC,WAAO,IAAI,CAAC,cAAL,CAAqB,IAAC,CAAA,KAAD,CAAA,CAArB,EAA+B,OAA/B;EADW;;qBAQpB,eAAA,GAAiB,SAAC,MAAD,EAAS,OAAT;;MAAS,UAAQ;;AAChC,WAAO,MAAM,CAAC,cAAP,CAAuB,IAAC,CAAA,KAAD,CAAA,CAAvB,EAAiC,OAAjC;EADQ;;qBAQjB,iBAAA,GAAmB,SAAC,GAAD,EAAM,OAAN;;MAAM,UAAQ;;AAC/B,WAAO,GAAG,CAAC,cAAJ,CAAoB,IAAC,CAAA,KAAD,CAAA,CAApB,EAA8B,OAA9B;EADU;;qBAKnB,KAAA,GAAO,SAAA;WAAU,IAAA,QAAA,CAAS,IAAT,CAAW,CAAC,EAAZ,CAAgB,IAAC,CAAA,EAAjB,EAAqB,IAAC,CAAA,EAAtB;EAAV;;;;GAnVc;;AAuVvB,IAAI,CAAC,QAAL,GAAgB","file":"pt-core.js","sourceRoot":"/source/","sourcesContent":["\n### Licensed under the Apache License, Version 2.0. (http://www.apache.org/licenses/LICENSE-2.0). Copyright 2015-2016 William Ngan. (https://github.com/williamngan/pt/) ###\n\n# ### A list of useful constant values for calculations and labeling.\r\nclass Const\r\n\r\n # ## represents the xy plane\r\n @xy = 'xy'\r\n\r\n # ## represents the yz plane\r\n @yz = 'yz'\r\n\r\n # ## reporesents the xz plane\r\n @xz = 'xz'\r\n\r\n # ## represents xyz space\r\n @xyz = 'xyz'\r\n\r\n # ## represents identical point or value\r\n @identical = -1\r\n\r\n # ## represents right position or direction\r\n @right = 3\r\n\r\n # ## represents bottom right position or direction\r\n @bottom_right = 4\r\n\r\n # ## represents bottom position or direction\r\n @bottom = 5\r\n\r\n # ## represents bottom left position or direction\r\n @bottom_left = 6\r\n\r\n # ## represents left position or direction\r\n @left = 7\r\n\r\n # ## represents top left position or direction\r\n @top_left = 0\r\n\r\n # ## represents top position or direction\r\n @top = 1\r\n\r\n # ## represents top right position or direction\r\n @top_right = 2\r\n\r\n # ## an array of strings to label position constants above. Eg, `Const.sideLabels[ Const.top_left]` will return the string \"top left\"\r\n @sideLabels = [\"identical\", \"right\", \"bottom right\", \"bottom\", \"bottom left\", \"left\", \"top left\", \"top\", \"top right\"]\r\n\r\n # ## represents an arbitrary very small number. It is set as 0.0001 here.\r\n @epsilon = 0.0001\r\n\r\n # ## pi radian (180 deg)\r\n @pi = Math.PI\r\n\r\n # ## two pi radian (360deg)\r\n @two_pi = 6.283185307179586\r\n\r\n # ## half pi radian (90deg)\r\n @half_pi = 1.5707963267948966\r\n\r\n # ## pi/4 radian (45deg)\r\n @quarter_pi = 0.7853981633974483\r\n\r\n # ## pi/180 = 1 degree in radian\r\n @one_degree = 0.017453292519943295\r\n\r\n # ## multiply this constant with a radian to get a degree\r\n @rad_to_deg = 57.29577951308232\r\n\r\n # ## multiply this constant with a degree to get a radian\r\n @deg_to_rad = 0.017453292519943295\r\n\r\n # ## Gravity acceleration (unit = m/s^2) and gravity force (unit = Newton) on 1kg of mass.\r\n @gravity = 9.81\r\n\r\n # ## 1 Newton = 0.10197 Kilogram-force\r\n @newton = 0.10197\r\n\r\n # ## Gaussian constant (1 / Math.sqrt(2 * Math.PI))\r\n @gaussian = 0.3989422804014327\r\n\r\n\r\n\r\n# namespace\r\nthis.Const = Const\n# ### Functions to calculate various Matrix transformations\r\nclass Matrix\r\n\r\n # ## Get a 3x3 matrix for 2D rotation around an anchor point\r\n # @param `radian` rotation angle in radian\r\n # @param `anchor` anchor point of rotation\r\n # @return an array representing a 3x3 matrix. Apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @rotateAnchor2D: ( radian, anchor, axis=Const.xy ) ->\r\n a = anchor.get2D( axis )\r\n cosA = Math.cos( radian )\r\n sinA = Math.sin( radian )\r\n return [\r\n cosA, sinA, 0\r\n -sinA, cosA, 0\r\n a.x*(1-cosA) + a.y*sinA, a.y*(1-cosA)-a.x*sinA, 1\r\n ]\r\n\r\n\r\n # ## Get a 3x3 matrix to reflect a point along a line. See also `Line.reflect()` for a potentially simpler calculation\r\n # @param `line` the path to define the reflection\r\n # @return an array representing a 3x3 matrix. apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @reflectAnchor2D: ( line, axis=Const.xy ) ->\r\n inc = line.intercept( axis )\r\n ang2 = Math.atan( inc.slope ) * 2\r\n cosA = Math.cos( ang2 )\r\n sinA = Math.sin( ang2 )\r\n return [\r\n cosA, sinA, 0\r\n sinA, -cosA, 0\r\n -inc.yi*sinA, inc.yi + inc.yi*cosA, 1\r\n ]\r\n\r\n\r\n # ## Get a 3x3 matrix for 2D shear from an anchor point\r\n # @param `sx, sy` shear scale values, usually between -1 to 1, where 0 means no change in shear.\r\n # @param `anchor` anchor point of shearing\r\n # @return an array representing a 3x3 matrix. apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @shearAnchor2D: (sx, sy, anchor, axis=Const.xy ) ->\r\n a = anchor.get2D( axis )\r\n tx = Math.tan( sx )\r\n ty = Math.tan( sy )\r\n\r\n return [\r\n 1, tx, 0\r\n ty, 1, 0\r\n -a.y*ty, -a.x*tx, 1\r\n ]\r\n\r\n\r\n # ## Get a 3x3 matrix for 2D scale from an anchor point\r\n # @param `sx, sy` horizontal and vertical scale values, which are usually between 0 to N, where 1 means no change in scale.\r\n # @param `anchor` anchor point of scaling\r\n # @return an array representing a 3x3 matrix. apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @scaleAnchor2D: (sx, sy, anchor, axis=Const.xy ) ->\r\n a = anchor.get2D( axis )\r\n return [\r\n sx, 0, 0,\r\n 0, sy, 0,\r\n -a.x*sx + a.x, -a.y*sy + a.y, 1\r\n ]\r\n\r\n\r\n # ## Get a 3x3 scale matrix\r\n # @param `x, y` horizontal and vertical scale values, which are usually between 0 to N, where 1 means no change in scale.\r\n # @return an array representing a 3x3 matrix. apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @scale2D: ( x, y ) ->\r\n return [\r\n x, 0, 0,\r\n 0, y, 0,\r\n 0, 0, 1\r\n ]\r\n\r\n\r\n # ## Get a 3x3 shear matrix\r\n # @param `x, y` shear scale values, usually between -1 to 1, where 0 means no change in shear.\r\n # @return an array representing a 3x3 matrix. apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @shear2D: (x, y ) ->\r\n return [\r\n 1, Math.tan(x), 0\r\n Math.tan(y), 1, 0\r\n 0, 0, 1\r\n ]\r\n\r\n # ## Get a 3x3 rotate matrix\r\n # @param `cosA, sinA` cosine and sine of the rotation angle.\r\n # @return an array representing a 3x3 matrix. apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @rotate2D: ( cosA, sinA ) ->\r\n return [\r\n cosA, sinA, 0,\r\n -sinA, cosA, 0,\r\n 0, 0, 1\r\n ]\r\n\r\n\r\n # ## Get a 3x3 translate matrix.\r\n # @param `x, y` horizontal and vertical offsets to move by\r\n # @return an array representing a 3x3 matrix. apply this matrix to a homongeneous vector (x,y,1) to rotate it.\r\n @translate2D: ( x, y ) ->\r\n return [\r\n 1, 0, 0\r\n 0, 1, 0\r\n x, y, 1\r\n ]\r\n\r\n\r\n # ## Calculate a 2D transform by applying matrix to a homogeneous vector\r\n # @param `pt` a Point to transform\r\n # @param `m` an array representing 3x3 matrix\r\n # @param `byValue` a boolean value to update the values of `pt` parameter directly if set to true. If false, returns a new Vector object instead. Default is false.\r\n # @return a Vector object, or the `pt` object if `byValue` is true\r\n @transform2D: (pt, m, axis=Const.xy, byValue=false) ->\r\n v = pt.get2D( axis )\r\n x = v.x * m[0] + v.y * m[3] + m[6];\r\n y = v.x * m[1] + v.y * m[4] + m[7];\r\n # z = v.x * m[2] + v.y * m[5] + m[8];\r\n v.x = x\r\n v.y = y\r\n # v.z = z\r\n v = v.get2D(axis, true)\r\n\r\n if !byValue\r\n pt.set(v)\r\n return pt\r\n\r\n return v\r\n\r\n\r\n# namescope\r\nthis.Matrix = Matrix\n# ### A collection of static methods and helper classes to get things done.\r\nclass Util\r\n\r\n # ## A static function to convert degrees to radian\r\n # @param `degree` angle in degrees. ie, 180 degrees = Math.PI radian\r\n @toRadian : ( angle ) -> angle * Const.deg_to_rad\r\n\r\n\r\n # ## A static function to convert radian to degrees\r\n # @param `radian` angle in radian. ie, Math.PI radian = 180 degrees\r\n @toDegree : ( radian ) -> radian * Const.rad_to_deg\r\n\r\n\r\n # ## A static function to convert a color value (0-255) to hex \"FF\". See also `Color.hex()` and `Color.rgba()`\r\n # @param `number` a value between 0 to 255\r\n # @return a string with 2 hex digits, such as \"FF\" or \"00\"\r\n @toHexColor: (number) ->\r\n h = Math.floor(number).toString(16)\r\n return if h.length is 1 then \"0\"+h else h\r\n\r\n\r\n # ## A static function to convert a hex string to rgb value or string. See also `Color.parseHex()`\r\n # @param hexString hex string such as \"FF9900\" or \"#FF9900\"\r\n # @param asRGBA a boolean value to set if the return value should be `rgba(...)` string\r\n # @param opacity optional opacity value between 0 to 1 for `rgba(...)` output\r\n # @eg `Util.toRGBColor(\"\")`\r\n @toRGBColor: (hexString, asRGBA=false, opacity=1) ->\r\n if hexString[0] == \"#\" then hexString = hexString.substr(1)\r\n\r\n if hexString.length == 3\r\n r = parseInt( hexString[0]+hexString[0], 16 )\r\n g = parseInt( hexString[1]+hexString[1], 16 )\r\n b = parseInt( hexString[2]+hexString[2], 16 )\r\n else if hexString.length >= 6\r\n r = parseInt( hexString[0]+hexString[1], 16 )\r\n g = parseInt( hexString[2]+hexString[3], 16 )\r\n b = parseInt( hexString[4]+hexString[5], 16 )\r\n else\r\n r = 0\r\n g = 0\r\n b = 0\r\n\r\n return if asRGBA then \"rgba(#{r},#{g},#{b},#{opacity})\" else [r,g,b,opacity]\r\n\r\n\r\n # ## A static function to limit a value (such as an angle, can be negative) as the modulus between 0 to max, or between -max/2 to max/2\r\n # @param `val` the value to be bound\r\n # @param `max` maximum value as boundary\r\n # @param `positive` a boolean value. If set to `true`, the return value will be between 0 to max; if `false`, return value will be between -max/2 to max/2. Default is `false`.\r\n # @return a value either (0 to max) or (-max/2 to max/2)\r\n @bound : ( val, max, positive=false ) ->\r\n a = val % max\r\n half = max / 2\r\n\r\n if a>half\r\n a -= max\r\n else if a < -half\r\n a += max\r\n\r\n if positive\r\n if a<0 then return a+max else return a\r\n else\r\n return a\r\n\r\n\r\n # ## A static function to limit an angle\r\n # @param `ang` an angle to be bound\r\n # @param `positive` a boolean value. If set to `true`, the return value will be between 0 to max; if `false`, return value will be between -max/2 to max/2. Default is `false`.\r\n # @return an angle either between 0 to 360, or between -180 to 180 degrees\r\n @boundAngle : ( ang, positive ) ->\r\n Util.bound( ang, 360, positive)\r\n\r\n\r\n # ## A static function similar to `Util.boundAngle` but limit a radian angle between 0 to 2*PI, or between -PI to PI\r\n @boundRadian : ( radian, positive ) ->\r\n Util.bound( radian, Const.two_pi, positive )\r\n\r\n\r\n # ## A static function to get a bounding box for a list of points\r\n # @param `points` an array of points\r\n # @param `is3D` a boolean value to specify if the points are 3D. Default is false which means the points are 2D.\r\n # @return an Rectangle object as bounding box\r\n @boundingBox: ( points, is3D=false ) ->\r\n minPt = new Point( Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY)\r\n maxPt = new Point( Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY)\r\n for p in points\r\n if p.x < minPt.x then minPt.x = p.x\r\n if p.y < minPt.y then minPt.y = p.y\r\n if p.x > maxPt.x then maxPt.x = p.x\r\n if p.y > maxPt.y then maxPt.y = p.y\r\n\r\n if is3D\r\n if p.z < minPt.z then minPt.z = p.z\r\n if p.z > maxPt.z then maxPt.z = p.z\r\n\r\n return new Rectangle( minPt ).to( maxPt )\r\n\r\n\r\n # ## A static function to get linear interpolation between two values\r\n # @param `a, b` first and second values\r\n # @param `t` a value between 0 to 1\r\n # return the interpolated value\r\n @lerp: ( a, b, t ) -> return (1-t) * a + t * b\r\n\r\n\r\n # ## Get a centroid point which is the averge positions of a list of points.\r\n # @param `points` an array of points\r\n # @return the centroid point as Vector\r\n @centroid: (points) ->\r\n c = new Vector()\r\n for p in points\r\n c.add( p )\r\n return c.divide( points.length )\r\n\r\n\r\n # ## Check if two numbers are equal within a threshold\r\n # @param `a, b` two numbers to compare\r\n # @param `threshold` the smallest difference allowed to be considered as same. Default is `Const.epsilon`.\r\n # @return a boolean value where `true` means they are the same\r\n @same : (a, b, threshold=Const.epsilon ) ->\r\n ( Math.abs( a - b ) < threshold )\r\n\r\n\r\n # ## Check is a number is within the range of two number\r\n # @param `p` the number to check\r\n # @param `a, b` two numbers to set the range\r\n # @return a boolean value where `true` means the number is within range\r\n @within: ( p, a, b) ->\r\n return p >= Math.min(a, b) and p <= Math.max(a, b)\r\n\r\n\r\n # ## Get a random value in between a range\r\n # @param `a, b` two numbers to set a range. `b` is optional and defaults to 0.\r\n # @return a random number within the range\r\n @randomRange : (a, b=0) ->\r\n r = if a > b then ( a - b ) else ( b - a )\r\n return a + Math.random() * r\r\n\r\n\r\n # ## Simple mixin implementataion\r\n # @param `klass` the class to inject\r\n # @param `mix` is the source mixin object\r\n # @return the klass with mixin\r\n @mixin : ( klass, mix ) ->\r\n for k,v of mix\r\n if mix.hasOwnProperty( k )\r\n klass.prototype[k] = mix[k]\r\n return klass\r\n\r\n\r\n # ## A helper function to extend a class\r\n # @param `klass` constructor function\r\n # @param `parent` class to inherit\r\n # @eg `function V() { Vector.call(this, arguments); }; Util.extend(V, Vector);`\r\n # @return the extended class\r\n @extend: (klass, parent) ->\r\n klass.prototype = Object.create(parent.prototype)\r\n klass.prototype.constructor = klass\r\n return klass\r\n\r\n\r\n # ## Given an array of Points (eg, in results of toArray() ), return an array of the points as copy\r\n @clonePoints: (array) -> ( p.clone() for p in array )\r\n\r\n\r\n # ## Rotate from an origin using canvas rendering context\r\n # @param `ctx` canvas rendering context\r\n # @param `bound` the bounding box as Rectangle object\r\n # @param `radian` the angle in radian to rotate\r\n # @param `origin` an optional Point object to specify the anchor point of rotation. If origin is false or not set, the anchor is at the center of the `bound` bounding box\r\n # @param `mask` an optional Rectangle object as mask\r\n @contextRotateOrigin : (ctx, bound, radian, origin=false, mask) ->\r\n\r\n size = bound.size()\r\n\r\n if !origin\r\n origin = size.$multiply(0.5)\r\n origin.add(bound)\r\n\r\n if mask\r\n msz = mask.size()\r\n Form.rect(ctx, mask)\r\n ctx.clip()\r\n\r\n ctx.translate( origin.x, origin.y )\r\n ctx.rotate( radian )\r\n ctx.translate( -origin.x, -origin.y)\r\n\r\n\r\n # ## A static function to pre-calculate a sine and cosine table. To use this, convert radian to angle as an integer, and then get table index by finding modulus `angle%360`\r\n # @return an object with `{sin, cos}` properties.\r\n @sinCosTable: () ->\r\n cos = []\r\n sin = []\r\n for i in [0..360] by 1\r\n cos[i] = Math.cos( i * Math.PI / 180 )\r\n sin[i] = Math.sin( i * Math.PI / 180 )\r\n return {sin: sin, cos: cos}\r\n\r\n\r\n # ## A static function which check if a random number from 0 to 1 is smaller than a user defined number\r\n # @param `p` a value between 0 to 1\r\n # @return a boolean value where true means a random number is smaller than the supplied parameter\r\n @chance: (p) -> return (Math.random() < p);\r\n\r\n\r\n # ## A static function to calculate Gaussian curve\r\n @gaussian: (x, mean=0, sigma=1) ->\r\n x = (x - mean) / sigma\r\n return Const.gaussian * Math.exp( -0.5 * x * x) / sigma\r\n\r\n\r\n # ## Map a value from one range to another\r\n # @param `n` a value in the first range\r\n # @param `min1` lower bound of the first range\r\n # @param `max1` upper bound of the first range\r\n # @param `min2` lower bound of the second range\r\n # @param `max2` upper bound of the second range\r\n # @return a remapped value in the second range\r\n @mapToRange: (n, min1, max1, min2, max2) ->\r\n if (min1 == max1) then throw \"[min1, max1] must be a non-degenerate interval (that is, min1 != max1)\"\r\n return ( (n - min1) / (max1 - min1) ) * (max2 - min2) + min2;\r\n\r\n\r\n# namespace\r\nthis.Util = Util;\r\n\n# ### Use a timer not to measure time, but to introduce rhythm. The conceptual hums of \"one two three, one two three\", when transfigured into patterns of sounds or words or dances, gives rise to various forms of aesthetic experiences. If time is a river, then timers are the mills we build along its banks.\r\nclass Timer\r\n\r\n # ## Create a Timer\r\n # @param `d` duration of the timer in milliseconds\r\n constructor: ( d=1000 ) ->\r\n @duration = d\r\n @_time = 0\r\n @_ease = (t,b,c,d) -> t/d\r\n @_intervalID = -1\r\n\r\n\r\n # ## Start or restart the timer\r\n # @param `reset` a boolean value to restart the timer from the beginning if set to `true`.\r\n start: (reset) ->\r\n diff = Math.min( Date.now() - @_time, @duration)\r\n\r\n if reset or diff >= @duration\r\n @_time = Date.now()\r\n\r\n\r\n # set an easing function to use in `check()`. See `Easing` class for a set of predefined easing functions\r\n # @param `ease` an easing function with 4 parameters `(current_time, start_value, change_in_value, duration_time)` and must return a number between 0 to 1\r\n setEasing: (ease) ->\r\n @_ease = ease\r\n\r\n\r\n # ## Check % of time that has elapsed currently.\r\n # @return a number between 0 to 1\r\n check: () ->\r\n diff = Math.min( Date.now() - @_time, @duration)\r\n return @_ease( diff, 0, 1, @duration )\r\n\r\n\r\n # Track time (using `setInterval()`)\r\n # @param `callback` a callback function which may include a `(t)` parameter to get current elapsed percentage (value between 0 to 1)\r\n # @return the intervalID from `setInterval()`\r\n track: ( callback ) ->\r\n clearInterval( @_intervalID )\r\n @start(true)\r\n me = @\r\n @_intervalID = setInterval( ( () ->\r\n t = me.check()\r\n callback( t )\r\n if t >= 1 then clearInterval( me._intervalID )\r\n ), 25 )\r\n return @_intervalID\r\n\r\n\r\n\r\n# namespace\r\nthis.Timer = Timer\n# ### Fishes forget their rivers and lakes, said Chuang Tzu. Spaces or contexts give meanings to ideas and lives, but are often overlooked. In Pt, space represents an abstract context in which a point can be made visible in one form or another, and can be specified as an html canvas, a soundscape, or a graffiti robot on a wall. Space is where a concept meets its expression.\r\n\r\nclass Space\r\n\r\n # ## Create a Space which is the context for displaying and animating elements. Extend this to create specific Spaces, for example, a space for HTML Canvas or SVG.\r\n # @param `id` an id property to identify this space\r\n constructor : ( id ) ->\r\n\r\n if typeof id != 'string' or id.length == 0\r\n throw \"id parameter is not valid\"\r\n return false\r\n\r\n # ## A property to identify this space by name\r\n @id = id\r\n\r\n # ## A property to indicate the size of this space as a Vector\r\n @size = new Vector()\r\n\r\n # ## A property to indicate the center of this space as a Vector\r\n @center = new Vector()\r\n\r\n # animation properties\r\n @_timePrev = 0 # record prev time\r\n @_timeDiff = 0 # record prev time difference\r\n @_timeEnd = -1 # end in milliseconds, -1 to play forever, 0 to end immediately\r\n\r\n # ## A set of items in this space. An item should implement a function `animate()` and optionally another callback `onSpaceResize(w,h,evt)`, and will be assigned a property `animateID` automatically. (See `add()`)\r\n @items = {}\r\n\r\n # item properties\r\n @_animID = -1\r\n @_animCount = 0 # player key as increment\r\n @_animPause = false\r\n @_refresh = true # refresh on each frame\r\n\r\n\r\n # ## set whether the rendering should be repainted on each frame\r\n # @param `b` a boolean value to set whether to repaint each frame\r\n # @demo space.refresh\r\n # @return this space\r\n refresh: (b) ->\r\n @_refresh = b\r\n return @\r\n\r\n\r\n # ## set custom render function (on resize and other events)\r\n # @return this space\r\n render: ( context ) ->\r\n return @\r\n\r\n\r\n # ## resize the space. (not implemented)\r\n resize: (w, h) ->\r\n\r\n\r\n # ## clear all contents in the space (not implemented)\r\n clear: () ->\r\n\r\n\r\n # ## Add an item to this space. An item must define a callback function `animate( time, fps, context )` and will be assigned a property `animateID` automatically. An item can also optionally define a callback function `onSpaceResize( w, h, evt )`. Subclasses of Space may define other callback functions.\r\n # @param an object with an `animate( time, fps, context )` function, and optionall a `onSpaceResize( w, h, evt )` function\r\n # @demo space.add\r\n # @return this space\r\n add : (item) ->\r\n if item.animate? and typeof item.animate is 'function'\r\n k = @_animCount++\r\n @items[k] = item\r\n item.animateID = k\r\n\r\n # if player has onSpaceResize defined, call the function\r\n if item.onSpaceResize? then item.onSpaceResize(@size.x, @size.y)\r\n else\r\n throw \"a player object for Space.add must define animate()\"\r\n\r\n return @\r\n\r\n\r\n # ## Remove an item from this Space\r\n # @param an object with an auto-assigned `animateID` property\r\n # @return this space\r\n remove : (item) ->\r\n delete @items[ item.animateID ]\r\n return @\r\n\r\n\r\n # ## Remove all items from this Space\r\n # @return this space\r\n removeAll : () ->\r\n @items = {}\r\n return @\r\n\r\n\r\n # ## Main play loop. This implements window.requestAnimationFrame and calls it recursively. Override this `play()` function to implemenet your own animation loop.\r\n # @param `time` current time\r\n # @return this space\r\n play : (time=0) ->\r\n\r\n # use fat arrow here, because rAF callback will change @ to window\r\n @_animID = requestAnimationFrame( (t) => @play(t) )\r\n\r\n # if pause\r\n if @_animPause then return\r\n\r\n # calc time passed since prev frame\r\n @_timeDiff = time - @_timePrev\r\n\r\n # animate this frame\r\n try\r\n @_playItems( time )\r\n catch err\r\n cancelAnimationFrame( @_animID )\r\n console.error( err.stack )\r\n throw err\r\n\r\n\r\n # store time\r\n @_timePrev = time\r\n\r\n return @\r\n\r\n\r\n # Main animate function. This calls all the items to perform\r\n # @param `time` current time\r\n # @return this space\r\n _playItems : (time) ->\r\n\r\n # clear before draw if refresh is true\r\n if @_refresh then @clear()\r\n\r\n # animate all players\r\n for k, v of @items\r\n v.animate( time, @_timeDiff, @ctx )\r\n\r\n # stop if time ended\r\n if @_timeEnd >= 0 and time > @_timeEnd\r\n cancelAnimationFrame( @_animID )\r\n\r\n return @\r\n\r\n\r\n # ## Pause the animation\r\n # @param `toggle` a boolean value to set if this function call should be a toggle (between pause and resume)\r\n # @return this space\r\n pause: ( toggle=false) ->\r\n @_animPause = if toggle then !@_animPause else true\r\n return @\r\n\r\n\r\n # ## Resume the paused animation\r\n # @return this space\r\n resume: () ->\r\n @_animPause = false\r\n return @\r\n\r\n\r\n # ## Specify when the animation should stop: immediately, after a time period, or never stops.\r\n # @param `t` a value in millisecond to specify a time period to play before stopping, or `-1` to play forever, or `0` to end immediately. Default is 0 which will stop the animation immediately.\r\n # @return this space\r\n stop : ( t=0 ) ->\r\n @_timeEnd = t\r\n return @\r\n\r\n\r\n # ## Play animation loop, and then stop after `duration` time has passed.\r\n # @param `duration` a value in millisecond to specify a time period to play before stopping, or `-1` to play forever\r\n playTime: (duration=5000) ->\r\n @play()\r\n @stop( duration )\r\n\r\n\r\n\r\n # ## Bind event listener in canvas element, for events such as mouse events\r\n # @param `evt` Event object\r\n # @param `callback` a callback function for this event\r\n bindCanvas: ( evt, callback ) ->\r\n if @space.addEventListener then @space.addEventListener( evt, callback )\r\n\r\n\r\n # ## A convenient method to bind (or unbind) all mouse events in canvas element. All item added to `items` property that implements an `onMouseAction` callback will receive mouse event callbacks. The types of mouse actions are: \"up\", \"down\", \"move\", \"drag\", \"drop\", \"over\", and \"out\".\r\n # @param `bind` a boolean value to bind mouse events if set to `true`. If `false`, all mouse events will be unbound. Default is true.\r\n # @demo canvasspace.bindMouse\r\n bindMouse: ( _bind=true ) ->\r\n if @space.addEventListener and @space.removeEventListener\r\n if _bind\r\n @space.addEventListener( \"mousedown\", @_mouseDown.bind(@) )\r\n @space.addEventListener( \"mouseup\", @_mouseUp.bind(@) )\r\n @space.addEventListener( \"mouseover\", @_mouseOver.bind(@) )\r\n @space.addEventListener( \"mouseout\", @_mouseOut.bind(@) )\r\n @space.addEventListener( \"mousemove\", @_mouseMove.bind(@) )\r\n else\r\n @space.removeEventListener( \"mousedown\", @_mouseDown.bind(@) )\r\n @space.removeEventListener( \"mouseup\", @_mouseUp.bind(@) )\r\n @space.removeEventListener( \"mouseover\", @_mouseOver.bind(@) )\r\n @space.removeEventListener( \"mouseout\", @_mouseOut.bind(@) )\r\n @space.removeEventListener( \"mousemove\", @_mouseMove.bind(@) )\r\n\r\n\r\n # ## A convenient method to bind (or unbind) all mobile touch events in canvas element. All item added to `items` property that implements an `onTouchAction` callback will receive touch event callbacks. The types of touch actions are the same as the mouse actions: \"up\", \"down\", \"move\", and \"out\".\r\n # @param `bind` a boolean value to bind touch events if set to `true`. If `false`, all touch events will be unbound. Default is true.\r\n bindTouch: ( _bind=true ) ->\r\n if @space.addEventListener and @space.removeEventListener\r\n if _bind\r\n @space.addEventListener( \"touchstart\", @_mouseDown.bind(@) )\r\n @space.addEventListener( \"touchend\", @_mouseUp.bind(@) )\r\n @space.addEventListener( \"touchmove\",\r\n ((evt) =>\r\n evt.preventDefault();\r\n @_mouseMove(evt)\r\n ) )\r\n @space.addEventListener( \"touchcancel\", @_mouseOut.bind(@) )\r\n else\r\n @space.removeEventListener( \"touchstart\", @_mouseDown.bind(@) )\r\n @space.removeEventListener( \"touchend\", @_mouseUp.bind(@) )\r\n @space.removeEventListener( \"touchmove\", @_mouseMove.bind(@) )\r\n @space.removeEventListener( \"touchcancel\", @_mouseOut.bind(@) )\r\n\r\n\r\n # ## A convenient method to convert the touch points in a touch event to an array of `Vectors`.\r\n # @param evt a touch event which contains touches, changedTouches, and targetTouches list.\r\n # @param which a string to select a touches list: \"touches\", \"changedTouches\", or \"targetTouches\". Default is \"touches\"\r\n # @return an array of Vectors, whose origin position (0,0) is offset to the top-left of this space.\r\n touchesToPoints: ( evt, which=\"touches\" ) ->\r\n if (!evt or !evt[which]) then return []\r\n return ( new Vector(t.pageX - this.boundRect.left, t.pageY - this.boundRect.top) for t in evt[which] )\r\n\r\n\r\n # go through all item in `items` and call its onMouseAction callback function\r\n _mouseAction: (type, evt) ->\r\n if (evt.touches || evt.changedTouches)\r\n for k, v of @items\r\n if v.onTouchAction?\r\n _c = evt.changedTouches and evt.changedTouches.length > 0\r\n px = if (_c) then evt.changedTouches.item(0).pageX else 0;\r\n py = if (_c) then evt.changedTouches.item(0).pageY else 0;\r\n v.onTouchAction( type, px, py, evt )\r\n else\r\n for k, v of @items\r\n if v.onMouseAction?\r\n px = evt.offsetX || evt.layerX;\r\n py = evt.offsetY || evt.layerY;\r\n v.onMouseAction( type, px, py, evt )\r\n\r\n\r\n # mouse down action\r\n _mouseDown: (evt) ->\r\n @_mouseAction( \"down\", evt )\r\n @_mdown = true\r\n\r\n\r\n # mouse up action\r\n _mouseUp: (evt) ->\r\n @_mouseAction( \"up\", evt )\r\n if @_mdrag then @_mouseAction( \"drop\", evt )\r\n @_mdown = false\r\n @_mdrag = false\r\n\r\n\r\n # mouse move action\r\n _mouseMove: (evt) ->\r\n @_mouseAction( \"move\", evt )\r\n if @_mdown\r\n @_mdrag = true\r\n @_mouseAction( \"drag\", evt )\r\n\r\n\r\n # mouse over action\r\n _mouseOver: (evt) ->\r\n @_mouseAction( \"over\", evt )\r\n\r\n\r\n # mouse out action\r\n _mouseOut: (evt) ->\r\n @_mouseAction( \"out\", evt )\r\n if @_mdrag then @_mouseAction( \"drop\", evt )\r\n @_mdrag = false\r\n\r\n\r\n# namespace\r\nthis.Space = Space\r\n\r\n\n# ### CanvasSpace is a space that represents a html canvas. It creates a new canvas or get an existing one in DOM by its id attribute. It also provide methods specific to html canvas, such as tracking resize and mouse position.\r\n\r\nclass CanvasSpace extends Space\r\n\r\n # ## Create a CanvasSpace which represents a HTML Canvas Space\r\n # @param `elem` Either a string which refers to the \"id\" attribute of a Canvas element, or the Canvas element itself. It can either refer to an existing ``, or a `
` container in which a new `` will be created. If left empty, a `
` will be added to DOM. Use css to customize its appearance if needed.\r\n # @param `callback` an optional callback `function(boundingBox, spaceElement)` to be called when canvas is appended and ready. A \"ready\" event will also be fired from the `` element when it's appended, which can be traced with `spaceInstance.space.addEventListener(\"ready\")`\r\n constructor : ( elem, callback ) ->\r\n if (!elem) then elem = 'pt'\r\n\r\n isElement = elem instanceof Element\r\n\r\n super( if (isElement) then \"pt_custom_space\" else elem )\r\n\r\n # ## A property to store canvas DOM element\r\n @space = null\r\n @bound = null\r\n @boundRect = {top: 0, left: 0, width: 0, height: 0}\r\n\r\n @pixelScale = 1\r\n @_autoResize = true\r\n\r\n _selector = null\r\n\r\n if (isElement)\r\n _selector = elem\r\n else\r\n @id = if (@id[0] == \"#\") then @id.substr(1) else @id\r\n _selector = document.querySelector(\"#\"+@id)\r\n _existed = true\r\n\r\n\r\n # if selector is not defined, create a canvas\r\n if !_selector\r\n @bound = @_createElement( \"div\", @id+\"_container\" )\r\n @space = @_createElement(\"canvas\", @id)\r\n @bound.appendChild( @space )\r\n document.body.appendChild( @bound )\r\n _existed = false\r\n\r\n # if selector is not canvas, create a canvas inside it\r\n else if _selector.nodeName.toLowerCase() != \"canvas\"\r\n @bound = _selector\r\n @space = @_createElement(\"canvas\", @id+\"_canvas\" )\r\n @bound.appendChild( @space )\r\n\r\n # if selector is an existing canvas\r\n else\r\n @space = _selector\r\n @bound = @space.parentElement\r\n\r\n # size is known so set it immediately\r\n if _existed\r\n b = @bound.getBoundingClientRect()\r\n @resize( b.width, b.height )\r\n\r\n # Track mouse dragging\r\n @_mdown = false\r\n @_mdrag = false\r\n\r\n # no mutation observer, so we set a timeout for ready event\r\n setTimeout( @_ready.bind(@, callback), 50 )\r\n\r\n # A property to store canvas background color\r\n @bgcolor = \"#F3F7FA\"\r\n\r\n # A property to store canvas rendering contenxt\r\n @ctx = @space.getContext( '2d' )\r\n\r\n\r\n\r\n\r\n # A private function to create the canvas element. This will create a
if elem parameter is not set.\r\n _createElement: ( elem=\"div\", id ) ->\r\n d = document.createElement( elem )\r\n d.setAttribute(\"id\", id )\r\n return d\r\n\r\n\r\n # A private function to handle callbacks after DOM element is mounted\r\n _ready: ( callback ) ->\r\n\r\n if @bound\r\n # measurement of the bounds and resize to fit\r\n @boundRect = @bound.getBoundingClientRect()\r\n @resize( @boundRect.width, @boundRect.height )\r\n @autoResize( @_autoResize )\r\n\r\n if @bgcolor then @clear( @bgcolor )\r\n @space.dispatchEvent( new Event('ready') )\r\n\r\n if (callback and typeof callback == \"function\") then callback( @boundRect, @space )\r\n\r\n else\r\n throw \"Cannot initiate #\"+@id+\" element\"\r\n\r\n\r\n # ## `display(...)` is deprecated as of 0.2.0. You can now set the canvas element directly in the constructor, and customize it using `setup()`.\r\n display: () ->\r\n console.warn( \"space.display(...) function is deprecated as of version 0.2.0. You can now set the canvas element in the constructor. Please see the release note for details.\" )\r\n return @\r\n\r\n # ## Set up various options for CanvasSpace. The `opt` parameter is an object with the following fields. This is usually set during instantiation, eg `new CanvasSpace(...).setup( { opt } )`\r\n # @param `opt.bgcolor` a hex or rgba string to set initial background color of the canvas. You may also change it later with `clear()`\r\n # @param `opt.resize` a boolean to set whether `` size should auto resize to match its container's size. You can also set it manually with `autoSize()`\r\n # @param `opt.retina` a boolean to set if device pixel scaling should be used. This may make drawings on retina displays look sharper but may reduce performance slightly. Default is `true`.\r\n # @return this CanvasSpace\r\n setup: ( opt ) ->\r\n\r\n # graphics context\r\n # if opt.context then @ctx = @space.getContext( opt.context )\r\n\r\n # background color\r\n if opt.bgcolor then @bgcolor = opt.bgcolor;\r\n\r\n # auto resize canvas to fit its container\r\n @_autoResize = if (opt.resize != false) then true else false\r\n\r\n # check for retina pixel ratio\r\n @pixelScale = 1\r\n if (opt.retina != false)\r\n r1 = window.devicePixelRatio or 1\r\n r2 = @ctx.webkitBackingStorePixelRatio or @ctx.mozBackingStorePixelRatio or @ctx.msBackingStorePixelRatio or @ctx.oBackingStorePixelRatio or @ctx.backingStorePixelRatio || 1;\r\n @pixelScale = r1/r2\r\n\r\n return this\r\n\r\n\r\n # window resize handler\r\n _resizeHandler: (evt) =>\r\n @boundRect = @bound.getBoundingClientRect()\r\n @resize( @boundRect.width, @boundRect.height, evt )\r\n\r\n\r\n # ## Set whether the canvas element should resize when its container is resized. Default will auto size\r\n # @param `auto` a boolean value indicating if auto size is set. Default is `true`.\r\n # @return this CanvasSpace\r\n autoResize: (auto=true) ->\r\n # listen/unlisten for window resize event and callback\r\n if (auto)\r\n window.addEventListener( 'resize', @_resizeHandler )\r\n else\r\n window.removeEventListener( 'resize', @_resizeHandler )\r\n\r\n return @\r\n\r\n # ## This overrides Space's `resize` function. It's a callback function for window's resize event. Keep track of this with `onSpaceResize(w,h,evt)` callback in your added objects.\r\n # @demo canvasspace.resize\r\n # @return this CanvasSpace\r\n resize: (w, h, evt) ->\r\n\r\n w = Math.floor(w)\r\n h = Math.floor(h)\r\n\r\n @size.set(w, h)\r\n @center = new Vector( w/2, h/2 )\r\n @boundRect.width = w\r\n @boundRect.height = h\r\n\r\n # if retina, resize the canvas size and rescale\r\n @space.width = w * @pixelScale\r\n @space.height = h * @pixelScale\r\n @space.style.width = w + \"px\"\r\n @space.style.height = h + \"px\"\r\n\r\n if (@pixelScale != 1)\r\n @ctx.scale( @pixelScale, @pixelScale )\r\n\r\n\r\n # player resize callback\r\n for k, p of @items\r\n if p.onSpaceResize? then p.onSpaceResize(w, h, evt)\r\n\r\n # repaint canvas\r\n @render( @ctx )\r\n\r\n return @\r\n\r\n\r\n # ## Clear the canvas with its background color. Overrides Space's `clear` function.\r\n # @param `bg` Optionally specify a custom background color. If evaluated to false, it will use its `bgcolor` property as background color.\r\n # @return this CanvasSpace\r\n clear: ( bg ) ->\r\n\r\n if bg then @bgcolor = bg\r\n\r\n lastColor = @ctx.fillStyle\r\n\r\n if @bgcolor\r\n @ctx.fillStyle = @bgcolor;\r\n @ctx.fillRect( 0, 0, @size.x, @size.y )\r\n else\r\n @ctx.clearRect( 0, 0, @size.x, @size.y )\r\n\r\n @ctx.fillStyle = lastColor\r\n\r\n return @\r\n\r\n\r\n\r\n # ## Overrides Space's `animate` function for canvas\r\n # @param `time` current time\r\n # @return this CanvasSpace\r\n animate : (time) ->\r\n\r\n\r\n @ctx.save()\r\n\r\n if @_refresh then @clear()\r\n\r\n # animate all players\r\n for k, v of @items\r\n v.animate( time, @_timeDiff, @ctx )\r\n\r\n # stop if time ended\r\n if @_timeEnd >= 0 and time > @_timeEnd\r\n cancelAnimationFrame( @_animID )\r\n\r\n @ctx.restore()\r\n\r\n return @\r\n\r\n\r\n# namescape\r\nthis.CanvasSpace = CanvasSpace\n# ### DOMSpace is a space that represents a html dom. It is similar to CanvasSpace but usually used as a space for SVG or HTML.\r\n\r\nclass DOMSpace extends Space\r\n\r\n # ## Create a DOMSpace which represents a HTML DOM\r\n # @param `elem` Either a string which refers to the \"id\" attribute of a DOM element, or the DOM element itself.\r\n # @param `callback` an optional callback `function(boundingBox, spaceElement)` to be called when element is appended and ready. A \"ready\" event will also be fired from the space's element when it's appended, which can be tracked with `spaceInstance.space.addEventListener(\"ready\")`\r\n # @param `spaceElement` an optional string of space's dom element name, such as `\"div\"` or `\"svg\"` or . Default is `\"div\"`\r\n constructor: ( elem, callback, spaceElement=\"div\" ) ->\r\n if (!elem) then elem = 'pt'\r\n \r\n isElement = elem instanceof Element\r\n\r\n super( if (isElement) then \"pt_custom_space\" else elem )\r\n\r\n # ## A property to store the DOM element\r\n @space = null\r\n @bound = null\r\n @boundRect = {top: 0, left: 0, width: 0, height: 0}\r\n\r\n @css = {};\r\n\r\n _selector = null\r\n\r\n if (isElement)\r\n _selector = elem\r\n else\r\n @id = if (@id[0] == \"#\") then @id.substr(1) else @id\r\n _selector = document.querySelector(\"#\"+@id)\r\n\r\n\r\n # if selector is not defined, create the spaceElement element\r\n if !_selector\r\n @space = @_createElement(spaceElement, @id)\r\n document.body.appendChild( @space )\r\n @bound = @space.parentElement\r\n\r\n # if selector is an existing element\r\n else\r\n @space = _selector\r\n @bound = @space.parentElement\r\n\r\n # Track mouse dragging\r\n @_mdown = false\r\n @_mdrag = false\r\n\r\n # no mutation observer, so we set a timeout for ready event\r\n setTimeout( @_ready.bind(@, callback), 50 )\r\n\r\n # A property to store background color\r\n @bgcolor = false\r\n\r\n # A property to store rendering contenxt\r\n @ctx = {}\r\n\r\n\r\n # A private function to create the dom element. This will create a
if elem parameter is not set.\r\n _createElement: ( elem=\"div\", id ) ->\r\n d = document.createElement( elem )\r\n d.setAttribute(\"id\", id )\r\n return d\r\n\r\n\r\n # A private function to handle callbacks after DOM element is mounted\r\n _ready: ( callback ) ->\r\n\r\n if @bound\r\n # measurement of the bounds and resize to fit\r\n @boundRect = @bound.getBoundingClientRect()\r\n @resize( @boundRect.width, @boundRect.height )\r\n @autoResize( @_autoResize )\r\n\r\n if @bgcolor\r\n @setCSS( \"backgroundColor\", @bgcolor )\r\n\r\n\r\n @updateCSS()\r\n\r\n @space.dispatchEvent( new Event('ready') )\r\n \r\n if (callback) then callback( @boundRect, @space )\r\n \r\n else\r\n throw \"Cannot initiate #\"+@id+\" element\"\r\n \r\n\r\n setCSS: ( key, val, isPx=false) ->\r\n @css[key] = (if isPx then \"#{val}px\" else val)\r\n return this\r\n\r\n\r\n updateCSS: () ->\r\n for k,v of @css\r\n @space.style[k] = v\r\n\r\n\r\n # ## `display(...)` is deprecated as of 0.2.0. You can now set the DOM element directly in the constructor, and customize it using `setup()`.\r\n display: () ->\r\n console.warn( \"space.display(...) function is deprecated as of version 0.2.0. You can now set the DOM element in the constructor. Please see the release note for details.\" )\r\n return @\r\n\r\n # ## Set up various options for DOMSpace. The `opt` parameter is an object with the following fields. This is usually set during instantiation, eg `new DOMSpace(...).setup( { opt } )`\r\n # @param `opt.bgcolor` a hex or rgba string to set initial background color of the element\r\n # @param `opt.resize` a boolean to set whether th element's size should auto resize to match its container's size. You can also set it manually with `autoSize()`\r\n # @return this DOMSpace\r\n setup: ( opt ) ->\r\n\r\n # background color\r\n if opt.bgcolor then @bgcolor = opt.bgcolor\r\n\r\n # auto resize element to fit its container\r\n @_autoResize = if (opt.resize != false) then true else false\r\n\r\n return @\r\n\r\n\r\n # window resize handler\r\n _resizeHandler: (evt) =>\r\n\r\n @boundRect = @bound.getBoundingClientRect()\r\n @resize( @boundRect.width, @boundRect.height, evt )\r\n\r\n\r\n\r\n # ## This overrides Space's `resize` function. It's a callback function for window's resize event when `autoResize` is true. Keep track of this with `onSpaceResize(w,h,evt)` callback in your added objects.\r\n # @return this DOMSpace\r\n resize: (w, h, evt) ->\r\n\r\n @size.set(w, h)\r\n @center = new Vector( w/2, h/2 )\r\n\r\n # player resize callback\r\n for k, p of @items\r\n if p.onSpaceResize? then p.onSpaceResize(w, h, evt)\r\n\r\n return @\r\n\r\n\r\n # ## Set whether the svg element should resize when its container is resized.\r\n # @param `auto` a boolean value indicating if auto size is set. Default is `true`.\r\n # @return this CanvasSpace\r\n autoResize: (auto=true) ->\r\n\r\n # listen/unlisten for window resize event and callback\r\n if (auto)\r\n @css['width'] = '100%'\r\n @css['height'] = '100%'\r\n window.addEventListener( 'resize', @_resizeHandler )\r\n else\r\n delete @css['width']\r\n delete @css['height']\r\n window.removeEventListener( 'resize', @_resizeHandler )\r\n\r\n return @\r\n\r\n\r\n # ## Clear the space. This removes all the child nodes inside `space`\r\n clear: () ->\r\n @space.innerHML = \"\"\r\n\r\n\r\n # ## Overrides Space's `animate` function\r\n # @param `time` current time\r\n # @return this CanvasSpace\r\n animate : (time) ->\r\n\r\n # animate all players\r\n for k, v of @items\r\n v.animate( time, @_timeDiff, @ctx )\r\n\r\n # stop if time ended\r\n if @_timeEnd >= 0 and time > @_timeEnd\r\n cancelAnimationFrame( @_animID )\r\n\r\n return @\r\n\r\n\r\n @attr: (elem, data) ->\r\n for k, v of data\r\n elem.setAttribute( k, v );\r\n\r\n\r\n @css: (data) ->\r\n str = \"\"\r\n for k, v of data\r\n if (v) then str += \"#{k}: #{v}; \"\r\n return str;\r\n\r\n\r\n# namescape\r\nthis.DOMSpace = DOMSpace\n# ### `SVGForm` visualizes forms in the `SVGSpace`.\r\nclass SVGForm\r\n\r\n @_domId = 0\r\n\r\n # ## Create a new Form which is based on SVG\r\n # @param `space` A space that has a valid context for this form. In this case, the space should represent an svg.\r\n # @return a new Form object\r\n constructor: ( space ) ->\r\n\r\n # ## a property to reference the space's rendering context\r\n @cc = space.ctx || {}\r\n\r\n # keep track of dom id names\r\n @cc.group = @cc.group || null\r\n @cc.groupID = \"ptx\"\r\n @cc.groupCount = 0\r\n @cc.currentID = \"ptx0\"\r\n\r\n # default style or false for no fill\r\n @cc.style = {\r\n fill: \"#999\"\r\n stroke: \"#666\"\r\n \"stroke-width\": 1\r\n \"stroke-linejoin\": false\r\n \"stroke-linecap\": false\r\n }\r\n @cc.font = \"11px sans-serif\"\r\n\r\n # ## a property to specify the current font size\r\n @cc.fontSize = 11\r\n\r\n # ## a property to specify the current font face\r\n @cc.fontFace = \"sans-serif\"\r\n\r\n\r\n # ## Set current fill style\r\n # @param `c` fill color. Default is `false` (transparent)\r\n # @eg `form.fill(\"#F90\")` `form.fill(\"rgba(0,0,0,.5\")` `form.fill(false)`\r\n # @return this Form\r\n fill: (c) ->\r\n @cc.style.fill = if c then c else false\r\n return @\r\n\r\n\r\n # ## Set current stroke style\r\n # @param `c` stroke color. Default is false (transparent)\r\n # @param `width` Optional value (can be floating point) to set line width\r\n # @param `joint` Optional string to set line joint style. Can be \"miter\", \"bevel\", or \"round\".\r\n # @param `cap` Optional string to set line joint style. Can be \"butt \", \"round\", or \"square\".\r\n # @eg `form.stroke(\"#F90\")` `form.stroke(\"rgba(0,0,0,.5\")` `form.stroke(false)` `form.stroke(\"#000\", 0.5, 'round')`\r\n # @return this Form\r\n stroke: (c, width, joint, cap) ->\r\n @cc.style.stroke = if c then c else false\r\n if width then @cc.style[\"stroke-width\"] = width\r\n if joint then @cc.style[\"stroke-linejoin\"] = joint\r\n if cap then @cc.style[\"stroke-linecap\"] = cap\r\n return @\r\n\r\n\r\n # ## Set this form's group scope by an ID, and optionally define the group's parent element. A group scope keeps track of DOM elements by their generated IDs, and updates their properties as needed. See also `enterScope()`.\r\n # @param `group_id` a string to use as prefix for the group's id. For example, group_id \"hello\" will create elements with id like \"hello-1\", \"hello-2\", etc\r\n # @param `group` optional dom element to define this group's parent element\r\n # @eg `form.scope(\"dot\")` `form.scope(\"dot\", elem)`\r\n # @demo svgform.scope\r\n # @return context object\r\n scope: ( group_id, group=false ) ->\r\n if (group) then @cc.group = group\r\n @cc.groupID = group_id\r\n @cc.groupCount = 0\r\n\r\n @nextID()\r\n return @cc\r\n\r\n\r\n # ## Set the current group scope to an item added into space, in order to keep track of any point, circle, etc created within it. The item must have an `animateID` property, so that elements created within the item will have generated IDs like \"item-{animateID}-{count}\".\r\n # @param `item` an item that's added to space (see `space.add(...)`) and has an `animateID` property\r\n # @return context object\r\n enterScope: ( item ) ->\r\n if (!item || item.animateID == null )\r\n throw \"getScope()'s item must be added to a Space, and has an animateID property. Otherwise, use scope() instead.\"\r\n return @scope( SVGForm._scopeID( item ) )\r\n\r\n\r\n # ## `getScope(...)` function is deprecated as of 0.2.0. Use `enterScope()` instead.\r\n getScope: ( item ) ->\r\n if !@_warn1\r\n console.warn( \"form.getScope(...) function is deprecated as of version 0.2.0. It is renamed as `enterScope()`.\" )\r\n @_warn1 = true\r\n return @enterScope( item )\r\n\r\n\r\n # ## Get next available id in the current group\r\n # @return an id string\r\n nextID: () ->\r\n @cc.groupCount++\r\n @cc.currentID = @cc.groupID+\"-\"+@cc.groupCount\r\n return @cc.currentID\r\n\r\n\r\n # ## A static function to context\r\n @id: (ctx) ->\r\n return ctx.currentID || \"p-\"+SVGForm._domId++\r\n\r\n\r\n # compose a scope id\r\n @_scopeID: (item) ->\r\n return \"item-\"+item.animateID\r\n\r\n # ## A static function to help adding style object to an element. This put all styles into `style` attribute instead of individual attributes, so that the styles can be parsed by Adobe Illustrator.\r\n # @param `elem` a dom element to add to\r\n # @param `styles` an object of style properties\r\n # @eg `SVGForm.style(elem, {fill: \"#f90\", stroke: false})`\r\n @style: (elem, styles) ->\r\n st = []\r\n\r\n for k,v of styles\r\n if (!v)\r\n if (k==\"fill\")\r\n st.push( \"fill: none\" )\r\n else if (k==\"stroke\")\r\n st.push( \"stroke: none\" )\r\n else\r\n st.push( k+\":\"+v )\r\n\r\n return DOMSpace.attr( elem, {style: st.join(\";\")} )\r\n\r\n\r\n # ## A static function to draw a point\r\n # @param `ctx` rendering context object\r\n # @param `pt` a Point object\r\n # @param `halfsize` radius or half size of the point. Default is 2.\r\n # @param `fill` not used - already defined in ctx\r\n # @param `stroke` not used - already defined in ctx\r\n # @param `circle` a boolean value to specify if the points should be drawn as a circle. Default to false.\r\n @point: (ctx, pt, halfsize=2, fill=true, stroke=true, circle=false ) ->\r\n\r\n elem = SVGSpace.svgElement( ctx.group, (if (circle) then \"circle\" else \"rect\"), SVGForm.id(ctx) )\r\n if (!elem) then return;\r\n\r\n if (circle)\r\n DOMSpace.attr( elem, {\r\n cx: pt.x\r\n cy: pt.y\r\n r: halfsize\r\n })\r\n else\r\n DOMSpace.attr( elem, {\r\n x: pt.x - halfsize\r\n y: pt.y - halfsize\r\n width: halfsize + halfsize\r\n height: halfsize + halfsize\r\n })\r\n\r\n SVGForm.style(elem, ctx.style)\r\n return elem\r\n\r\n\r\n # ## Draw a point\r\n # @param `p` a Point object\r\n # @param `halfsize` radius or half size of the point. Default is 2.\r\n # @param `isCircle` a boolean value to specify if the point should be drawn as a circle. Default is false.\r\n # @return this Form\r\n point: (p, halfsize=2, isCircle=false) ->\r\n @nextID()\r\n SVGForm.point(@cc, p, halfsize, true, true, isCircle )\r\n return @\r\n\r\n\r\n # ## A static function similar to `SVGForm.point()` but draw a series of points\r\n # @param `ctx` rendering context object\r\n # @param `pts` an array of Points\r\n # @param `halfsize, fill, stroke, circle` same parameters as in `SVGForm.point()`\r\n @points: (ctx, pts, halfsize=2, fill=true, stroke=true, circle=false ) ->\r\n return (SVGForm.point( ctx, p, halfsize, fill, stroke, circle ) for p in pts)\r\n\r\n\r\n # ## Draw a series of points\r\n # @param `ps` an array of Points\r\n # @param `halfsize` radius or half size of the point. Default is 2.\r\n # @param `isCircle` a boolean value to specify if the point should be drawn as a circle. Default is false.\r\n # @return this Form\r\n points: (ps, halfsize=2, isCircle=false) ->\r\n for p in ps\r\n @point(p, halfsize, isCircle )\r\n return @\r\n\r\n\r\n # ## A static function to draw a line\r\n # @param `ctx` rendering context object\r\n # @param `pair` a Pair object\r\n @line: (ctx, pair) ->\r\n if !pair.p1 then throw \"#{pair.toString()} is not a Pair\"\r\n elem = SVGSpace.svgElement( ctx.group, \"line\", SVGForm.id(ctx) )\r\n\r\n DOMSpace.attr( elem, {\r\n x1: pair.x\r\n y1: pair.y\r\n x2: pair.p1.x\r\n y2: pair.p1.y\r\n })\r\n\r\n SVGForm.style(elem, ctx.style)\r\n return elem\r\n\r\n\r\n # ## Draw a line\r\n # @param `p` a Pair object\r\n # @return this Form\r\n line: (p) ->\r\n @nextID()\r\n SVGForm.line( @cc, p )\r\n return @\r\n\r\n\r\n # ## A static function to draw a line\r\n # @param `ctx` rendering context object\r\n # @param `pairs` an array of Pair objects\r\n @lines: (ctx, pairs) ->\r\n return ( SVGForm.line( ctx, ln ) for ln in pairs )\r\n\r\n\r\n # ## Draw a series of lines\r\n # @param `ps` an array of Lines\r\n # @return this Form\r\n lines: (ps) ->\r\n for p in ps\r\n @line(p)\r\n return @\r\n\r\n\r\n # ## A static function to draw a rectangle\r\n # @param `ctx` rendering context object\r\n # @param `pair` a Pair object\r\n # @param `fill` not used - already defined in ctx\r\n # @param `stroke` not used - already defined in ctx\r\n @rect: (ctx, pair, fill=true, stroke=true) ->\r\n if !pair.p1 then throw \"#{pair.toString() is not a Pair}\"\r\n elem = SVGSpace.svgElement( ctx.group, \"rect\", SVGForm.id(ctx) )\r\n\r\n size = pair.size()\r\n DOMSpace.attr( elem, {\r\n x: pair.x\r\n y: pair.y\r\n width: size.x\r\n height: size.y\r\n })\r\n\r\n SVGForm.style(elem, ctx.style)\r\n return elem\r\n\r\n\r\n # ## Draw a rectangle\r\n # @param `p` a Pair object\r\n # @return this Form\r\n rect: (p, checkBounds=true) ->\r\n @nextID()\r\n r = if (checkBounds) then p.bounds() else p\r\n SVGForm.rect( @cc, r )\r\n return @\r\n\r\n\r\n # ## A static function to draw a circle\r\n # @param `ctx` rendering context object\r\n # @param `c` a Circle object\r\n # @param `fill` not used - already defined in ctx\r\n # @param `stroke` not used - already defined in ctx\r\n @circle: (ctx, c, fill=true, stroke=false) ->\r\n\r\n elem = SVGSpace.svgElement( ctx.group, \"circle\", SVGForm.id(ctx) )\r\n if (!elem) then return\r\n\r\n DOMSpace.attr( elem, {\r\n cx: c.x\r\n cy: c.y\r\n r: c.radius\r\n })\r\n\r\n SVGForm.style(elem, ctx.style)\r\n return elem\r\n\r\n\r\n # ## Draw a circle\r\n # @param `c` a Circle object\r\n # @demo svgform.circle\r\n # @return this Form\r\n circle: (c) ->\r\n @nextID()\r\n SVGForm.circle( @cc, c )\r\n return @\r\n\r\n\r\n\r\n # ## A static function to draw a polygon\r\n # @param `ctx` rendering context object\r\n # @param `pts` an array of Points\r\n # @param `closePath` a boolean value to specify if the path should be closed (joining last point with first point)\r\n # @param `fill` not used - already defined in ctx\r\n # @param `stroke` not used - already defined in ctx\r\n @polygon: ( ctx, pts, closePath=true, fill=true, stroke=true) ->\r\n\r\n elem = SVGSpace.svgElement( ctx.group, (if (closePath) then \"polygon\" else \"polyline\"), SVGForm.id(ctx) )\r\n if (!elem) then return\r\n\r\n if pts.length <= 1 then return;\r\n\r\n points = (\"#{pts[i].x},#{pts[i].y}\" for i in [0...pts.length] by 1)\r\n DOMSpace.attr( elem, {\r\n points: points.join(\" \")\r\n })\r\n\r\n SVGForm.style(elem, ctx.style)\r\n return elem\r\n\r\n\r\n # ## Draw a polygon\r\n # @param `ps` an array of Points\r\n # @param `closePath` a boolean value to specify if the path should be closed (joining last point with first point)\r\n # @return this Form\r\n polygon: (ps, closePath) ->\r\n @nextID()\r\n SVGForm.polygon( @cc, ps, closePath)\r\n return @\r\n\r\n # ## A static function to draw a triangle\r\n # @param `ctx` rendering context object\r\n # @param `tri` a Triangle object\r\n # @param `fill` not used - already defined in ctx\r\n # @param `stroke` not used - already defined in ctx\r\n @triangle: ( ctx, tri, fill=true, stroke=false) ->\r\n return SVGForm.polygon(ctx, tri.toArray() )\r\n\r\n\r\n # ## Draw a triangle\r\n # @param `tri` a Triangle object\r\n # @return this Form\r\n triangle: (tri) ->\r\n @nextID()\r\n SVGForm.triangle( @cc, tri )\r\n return @\r\n\r\n\r\n # ## A static function to draw a curve as straight polygon segments. In future, this should be converted to bezier curves.\r\n # @param `ctx` rendering context object\r\n # @param `pts` an array of Points\r\n @curve: ( ctx, pts, closePath=false ) ->\r\n SVGForm.polygon( ctx, pts, closePath )\r\n\r\n\r\n # ## Draw a curve\r\n # @param `ps` an array of Points\r\n # @return this Form\r\n curve: (ps, closePath=false ) ->\r\n @nextID()\r\n SVGForm.curve( @cc, ps, closePath )\r\n return @\r\n\r\n\r\n # ## A static function to draw text\r\n # @param `ctx` rendering context object\r\n # @param `pt` a Point object to specify the anchor point\r\n # @param `txt` a string of text to draw\r\n # @param `maxWidth` not applicable in svg\r\n # @param `dx` optional shift in x position\r\n # @param `dy` optional shift in y position\r\n @text: ( ctx, pt, txt, maxWidth=0, dx=0, dy=0 ) ->\r\n elem = SVGSpace.svgElement( ctx.group, \"text\", SVGForm.id(ctx) )\r\n if (!elem) then return\r\n\r\n DOMSpace.attr( elem, {\r\n \"pointer-events\": \"none\",\r\n x: pt.x,\r\n y: pt.y,\r\n dx: 0,\r\n dy: 0\r\n })\r\n\r\n elem.textContent = txt\r\n\r\n SVGForm.style(elem, {\r\n fill: ctx.style.fill\r\n stroke: ctx.style.stroke\r\n \"font-family\": ctx.fontFace or false\r\n \"font-size\": ctx.fontSize or false\r\n })\r\n return elem\r\n\r\n\r\n # ## Draw text\r\n # @param `p` a Point to specify anchor position\r\n # @param `txt` a string of text\r\n # @param `maxWidth` not applicable in svg\r\n # @param `xoff, yoff` x and y positional offset values\r\n text: (p, txt, maxWidth=1000, xoff, yoff) ->\r\n @nextID()\r\n SVGForm.text( @cc, p, txt, maxWidth, xoff, yoff)\r\n return @\r\n\r\n\r\n\r\n # ## Set font size and font face\r\n # @param `size` an integer value to specify font size in pixels\r\n # @param `face` optional name to change the font face, such as \"sans-serif\" or \"Helvetica\"\r\n # @eg `form.font(24)` `form.font(12, \"Georgia\")`\r\n # @return this Form\r\n font: (size, face=false) ->\r\n @cc.fontFace = face\r\n @cc.fontSize = size\r\n @cc.font = \"#{size}px #{face}\"\r\n return @\r\n\r\n\r\n # ## Draw a shape. Defaults to `sketch()`. Override this function to draw differently.\r\n # @return this Form\r\n draw: ( shape ) ->\r\n @sketch( shape )\r\n\r\n\r\n # ## Default draw based on the types of shape (Point, Line, Circle, etc)\r\n # @param `shape` any shape such as `Point` or `Line`, or an array of Points\r\n # @return this Form\r\n sketch: ( shape ) ->\r\n shape.floor()\r\n\r\n if shape instanceof Circle\r\n SVGForm.circle(@cc, shape, @filled, @stroked)\r\n\r\n else if shape instanceof Rectangle\r\n SVGForm.rect( @cc, shape, @filled, @stroked)\r\n\r\n else if shape instanceof Triangle\r\n SVGForm.triangle( @cc, shape, @filled, @stroked)\r\n\r\n else if shape instanceof Line or shape instanceof Pair\r\n SVGForm.line(@cc, shape)\r\n\r\n else if shape instanceof PointSet\r\n SVGForm.polygon(@cc, shape.points )\r\n\r\n else if shape instanceof Vector or shape instanceof Point\r\n SVGForm.point(@cc, shape)\r\n\r\n\r\n return @\r\n\r\n\r\n# namespace\r\nthis.SVGForm = SVGForm\n# ### SVGSpace is an extension of DOMSpace that represents an svg element in DOM. Also refers to DOMSpace for inherited methods.\r\nclass SVGSpace extends DOMSpace\r\n\r\n # ## Create a SVGSpace which represents a svg element\r\n # @param `id` Either a string which refers to the \"id\" attribute of a DOM element, or the DOM element itself. It can either refer to an existing ``, or a `
` container in which a new `` will be created. If left empty, a `
` will be added to DOM. Use css to customize its appearance if needed.\r\n # @param `callback` an optional callback `function(boundingBox, spaceElement)` to be called when element is appended and ready. A \"ready\" event will also be fired from the space's element when it's appended, which can be tracked with `spaceInstance.space.addEventListener(\"ready\")`\r\n constructor: ( id, callback ) ->\r\n super( id, callback, 'svg')\r\n\r\n if @space.nodeName.toLowerCase() != \"svg\"\r\n s = @_createElement(\"svg\", @id+\"_svg\" )\r\n @space.appendChild( s )\r\n @bound = @space\r\n @space = s\r\n\r\n # size is known so set it immediately\r\n b = @bound.getBoundingClientRect()\r\n @resize( b.width, b.height )\r\n\r\n\r\n\r\n # A private function to create the svg namespaced element. This will create a if elem parameter is not set.\r\n _createElement: ( elem=\"svg\", id ) ->\r\n d = document.createElementNS( \"http://www.w3.org/2000/svg\", elem )\r\n if (id) then d.setAttribute(\"id\", id )\r\n return d\r\n\r\n\r\n # ## A static helper method to add a svg element inside a node. Usually you don't need to use this directly. See methods in `SVGForm` instead.\r\n # @param `parent` the parent node element, or `null` to use current `` as parent.\r\n # @param `name` a string of element name, such as `\"rect\"` or `\"circle\"`\r\n # @param `id` id attribute of the new element\r\n @svgElement: (parent, name, id) ->\r\n\r\n if (!parent || !parent.appendChild)\r\n parent = @space\r\n if !parent then throw( \"parent parameter needs to be a DOM node\" )\r\n\r\n elem = document.querySelector(\"#\"+id);\r\n\r\n if (!elem)\r\n elem = document.createElementNS( \"http://www.w3.org/2000/svg\", name)\r\n elem.setAttribute(\"id\",id)\r\n elem.setAttribute(\"class\",id.substring(0, id.indexOf(\"-\")))\r\n parent.appendChild( elem )\r\n\r\n return elem\r\n\r\n\r\n # ## Remove an item from this Space\r\n # @param an object with an auto-assigned `animateID` property\r\n # @demo svgspace.remove\r\n # @return this space\r\n remove : (item) ->\r\n temp = @space.querySelectorAll( \".\"+SVGForm._scopeID(item) )\r\n\r\n for t in temp\r\n t.parentNode.removeChild(t)\r\n\r\n delete @items[ item.animateID ]\r\n return @\r\n\r\n\r\n # ## Remove all items from this Space\r\n # @return this space\r\n removeAll: () ->\r\n while (@space.firstChild)\r\n @space.removeChild(@space.firstChild)\r\n return @\r\n\r\n\r\n# namescape\r\nthis.SVGSpace = SVGSpace\n# ### Form makes visible the invisible. It transforms a point into an inkblot, or an arrow, or a musical note. By separating forms from its concepts, we may create a myriad of expressions on a single concept, or apply a unified style to various concepts. The Form class provides basic method to draw points, lines, and other primitives on CanvasSpace. Extend this class to visualize in different ways in different contexts.\r\nclass Form\r\n\r\n # ## Create a new Form which is based on HTML Canvass\r\n # @param `space` A space that has a valid context for this form. In this case, the space should represent an html canvas.\r\n # @return a new Form object\r\n constructor: ( space ) ->\r\n\r\n # ## a property to reference the space\r\n @space = space\r\n\r\n # ## a property to reference the canvas rendering context\r\n @cc = space.ctx\r\n\r\n # default style\r\n @cc.fillStyle = '#999'\r\n @cc.strokeStyle = '#666'\r\n @cc.lineWidth = 1\r\n @cc.font = \"11px sans-serif\"\r\n\r\n # ## a boolean property to set if the next drawing should be filled with current fill style\r\n @filled = true\r\n\r\n # ## a boolean property to set if the next drawing should be stroked with current stroke style\r\n @stroked = true\r\n\r\n # ## a property to specify the current font size\r\n @fontSize = 11\r\n\r\n # ## a property to specify the current font face\r\n @fontFace = \"sans-serif\"\r\n\r\n\r\n # ## A static function to get 2d context from a canvas element in the DOM\r\n # @param `canvas_id` the id attribute of the canvas element\r\n # @eg `Form.context('my_canvas')`\r\n # @return a canvas rendering context object\r\n @context : ( canvas_id ) ->\r\n # get canvas and its 2d context\r\n elem = document.getElementById( canvas_id )\r\n cc = if elem and elem.getContext then elem.getContext('2d') else false\r\n if !cc then throw \"Cannot initiate canvas 2d context\"\r\n cc\r\n\r\n\r\n # ## A static function to draw a line\r\n # @param `ctx` canvas rendering context\r\n # @param `pair` a Pair object\r\n @line: (ctx, pair) ->\r\n if !pair.p1 then throw \"#{pair.toString()} is not a Pair\"\r\n ctx.beginPath()\r\n ctx.moveTo( pair.x, pair.y )\r\n ctx.lineTo( pair.p1.x, pair.p1.y )\r\n ctx.stroke()\r\n\r\n\r\n\r\n # ## A static function to draw a line\r\n # @param `ctx` canvas rendering context\r\n # @param `pairs` an array of Pair objects\r\n @lines: (ctx, pairs) ->\r\n for ln in pairs\r\n Form.line( ctx, ln )\r\n\r\n\r\n # ## A static function to draw a rectangle\r\n # @param `ctx` canvas rendering context\r\n # @param `pair` a Pair object\r\n # @param `fill` a boolean value to specify if the points should be filled. Default to true.\r\n # @param `stroke` a boolean value to specify if the points should be stroked. Default to false.\r\n @rect: (ctx, pair, fill=true, stroke=false) ->\r\n if !pair.p1 then throw \"#{pair.toString() is not a Pair}\"\r\n ctx.beginPath()\r\n ctx.moveTo( pair.x, pair.y )\r\n ctx.lineTo( pair.x, pair.p1.y )\r\n ctx.lineTo( pair.p1.x, pair.p1.y )\r\n ctx.lineTo( pair.p1.x, pair.y )\r\n ctx.closePath()\r\n if stroke then ctx.stroke()\r\n if fill then ctx.fill()\r\n\r\n\r\n # ## A static function to draw a circle\r\n # @param `ctx` canvas rendering context\r\n # @param `c` a Circle object\r\n # @param `fill` a boolean value to specify if the points should be filled. Default to true.\r\n # @param `stroke` a boolean value to specify if the points should be stroked. Default to false.\r\n @circle: (ctx, c, fill=true, stroke=false) ->\r\n ctx.beginPath()\r\n ctx.arc( c.x, c.y, c.radius, 0, Const.two_pi, false )\r\n if fill then ctx.fill()\r\n if stroke then ctx.stroke()\r\n return\r\n\r\n\r\n # ## A static function to draw an arc\r\n # @param `ctx` canvas rendering context\r\n # @param `pt` a Point\r\n # @param `radius` radius of the arc's circle\r\n # @param `start` start angle\r\n # @param `stroke` end angle\r\n @arc: (ctx, pt, radius, start, end ) ->\r\n ctx.beginPath()\r\n ctx.arc( pt.x, pt.y, radius, start, end)\r\n ctx.stroke()\r\n\r\n\r\n # ## A static function to draw a triangle\r\n # @param `ctx` canvas rendering context\r\n # @param `tri` a Triangle object\r\n # @param `fill` a boolean value to specify if the points should be filled. Default to true.\r\n # @param `stroke` a boolean value to specify if the points should be stroked. Default to false.\r\n @triangle: ( ctx, tri, fill=true, stroke=false) ->\r\n ctx.beginPath()\r\n ctx.moveTo( tri.x, tri.y )\r\n ctx.lineTo( tri.p1.x, tri.p1.y )\r\n ctx.lineTo( tri.p2.x, tri.p2.y )\r\n ctx.closePath()\r\n if fill then ctx.fill()\r\n if stroke then ctx.stroke()\r\n return\r\n\r\n\r\n # ## A static function to draw a point\r\n # @param `ctx` canvas rendering context\r\n # @param `pt` a Point object\r\n # @param `halfsize` radius or half size of the point. Default is 2.\r\n # @param `fill` a boolean value to specify if the points should be filled. Default to true.\r\n # @param `stroke` a boolean value to specify if the points should be stroked. Default to false.\r\n # @param `circle` a boolean value to specify if the points should be drawn as a circle. Default to false.\r\n @point: (ctx, pt, halfsize=2, fill=true, stroke=false, circle=false ) ->\r\n\r\n if circle\r\n ctx.beginPath()\r\n ctx.arc( pt.x, pt.y, halfsize, 0, Const.two_pi, false )\r\n\r\n else\r\n x1 = pt.x-halfsize\r\n y1 = pt.y-halfsize\r\n x2 = pt.x+halfsize\r\n y2 = pt.y+halfsize\r\n\r\n ctx.beginPath()\r\n ctx.moveTo( x1, y1 )\r\n ctx.lineTo( x1, y2 )\r\n ctx.lineTo( x2, y2 )\r\n ctx.lineTo( x2, y1 )\r\n ctx.closePath()\r\n\r\n if fill then ctx.fill()\r\n if stroke then ctx.stroke()\r\n return pt\r\n\r\n\r\n # ## A static function similar to `Form.point()` but draw a series of points\r\n # @param `ctx` canvas rendering context\r\n # @param `pts` an array of Points\r\n # @param `halfsize, fill, stroke, circle` same parameters as in `Form.point()`\r\n @points: (ctx, pts, halfsize=2, fill=true, stroke=false, circle=false ) ->\r\n for p in pts\r\n Form.point( ctx, p, halfsize, fill, stroke, circle )\r\n\r\n\r\n # ## A static function to draw a polygon\r\n # @param `ctx` canvas rendering context\r\n # @param `pts` an array of Points\r\n # @param `closePath` a boolean value to specify if the path should be closed (joining last point with first point)\r\n # @param `fill` a boolean value to specify if the points should be filled. Default to true.\r\n # @param `stroke` a boolean value to specify if the points should be stroked. Default to true.\r\n @polygon: ( ctx, pts, closePath=true, fill=true, stroke=true) ->\r\n if pts.length <= 1 then return;\r\n ctx.beginPath()\r\n ctx.moveTo( pts[0].x, pts[0].y )\r\n for i in [1...pts.length] by 1\r\n ctx.lineTo( pts[i].x, pts[i].y )\r\n\r\n if closePath then ctx.closePath()\r\n if fill then ctx.fill()\r\n if stroke then ctx.stroke()\r\n return\r\n\r\n # ## A static function to draw a curve\r\n # @param `ctx` canvas rendering context\r\n # @param `pts` an array of Points\r\n @curve: ( ctx, pts ) ->\r\n Form.polygon( ctx, pts, false, false, true )\r\n\r\n\r\n # ## A static function to draw text\r\n # @param `ctx` canvas rendering context\r\n # @param `pt` a Point object to specify the anchor point\r\n # @param `txt` a string of text to draw\r\n # @param `maxWidth` specify a maximum width per line\r\n @text: ( ctx, pt, txt, maxWidth ) ->\r\n ctx.fillText( txt, pt.x, pt.y, maxWidth )\r\n\r\n\r\n\r\n # ## Set current fill style\r\n # @param `c` fill color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle)) Default is `false` (transparent)\r\n # @eg `form.fill(\"#F90\")` `form.fill(\"rgba(0,0,0,.5\")` `form.fill(false)`\r\n # @demo form.fill\r\n # @return this Form\r\n fill: (c) ->\r\n @cc.fillStyle = if c then c else \"transparent\"\r\n @filled = !!c\r\n return @\r\n\r\n\r\n # ## Set current stroke style\r\n # @param `c` stroke color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/strokeStyle)) Default is false (transparent)\r\n # @param `width` Optional value (can be floating point) to set line width\r\n # @param `joint` Optional string to set line joint style. Can be \"miter\", \"bevel\", or \"round\".\r\n # @param `cap` Optional string to set line cap style. Can be \"butt\", \"round\", or \"square\".\r\n # @eg `form.stroke(\"#F90\")` `form.stroke(\"rgba(0,0,0,.5\")` `form.stroke(false)` `form.stroke(\"#000\", 0.5, 'round')`\r\n # @return this Form\r\n stroke: (c, width, joint, cap) ->\r\n @cc.strokeStyle = if c then c else \"transparent\"\r\n @stroked = !!c\r\n if width then @cc.lineWidth = width\r\n if joint then @cc.lineJoin = joint\r\n if cap then @cc.lineCap = cap\r\n return @\r\n\r\n\r\n # ## Set font size and font face\r\n # @param `size` an integer value to specify font size in pixels\r\n # @param `face` optional name to change the font face, such as \"sans-serif\" or \"Helvetica\"\r\n # @eg `form.font(24)` `form.font(12, \"Georgia\")`\r\n # @demo form.font\r\n # @return this Form\r\n font: (size, face=@fontFace) ->\r\n @fontSize = size\r\n @cc.font = \"#{size}px #{face}\"\r\n return @\r\n\r\n\r\n # ## Draw a shape. Defaults to `sketch()`. Override this function to draw differently.\r\n # @return this Form\r\n draw: ( shape ) ->\r\n @sketch( shape )\r\n\r\n\r\n # ## Default draw based on the types of shape (Point, Line, Circle, etc)\r\n # @param `shape` any shape such as `Point` or `Line`, or an array of Points\r\n # @return this Form\r\n sketch: ( shape ) ->\r\n shape.floor()\r\n\r\n if shape instanceof Circle\r\n Form.circle(@cc, shape, @filled, @stroked)\r\n\r\n else if shape instanceof Rectangle\r\n Form.rect( @cc, shape, @filled, @stroked)\r\n\r\n else if shape instanceof Triangle\r\n Form.triangle( @cc, shape, @filled, @stroked)\r\n\r\n else if shape instanceof Line or shape instanceof Pair\r\n Form.line(@cc, shape)\r\n\r\n else if shape instanceof PointSet\r\n Form.polygon(@cc, shape.points )\r\n\r\n else if shape instanceof Vector or shape instanceof Point\r\n Form.point(@cc, shape)\r\n\r\n\r\n return @\r\n\r\n\r\n # ## Draw a point\r\n # @param `p` a Point object\r\n # @param `halfsize` radius or half size of the point. Default is 2.\r\n # @param `isCircle` a boolean value to specify if the point should be drawn as a circle. Default is false.\r\n # @return this Form\r\n point: (p, halfsize=2, isCircle=false) ->\r\n Form.point(@cc, p, halfsize, @filled, @stroked, isCircle )\r\n return @\r\n\r\n # ## Draw a series of points\r\n # @param `ps` an array of Points\r\n # @param `halfsize` radius or half size of the point. Default is 2.\r\n # @param `isCircle` a boolean value to specify if the point should be drawn as a circle. Default is false.\r\n # @demo form.points\r\n # @return this Form\r\n points: (ps, halfsize=2, isCircle=false) ->\r\n Form.points(@cc, ps, halfsize, @filled, @stroked, isCircle )\r\n return @\r\n\r\n\r\n # ## Draw a line\r\n # @param `p` a Pair object\r\n # @return this Form\r\n line: (p) ->\r\n Form.line(@cc, p)\r\n return @\r\n\r\n # ## Draw a series of lines\r\n # @param `ps` an array of Lines\r\n # @return this Form\r\n lines: (ps) ->\r\n Form.lines(@cc, ps)\r\n return @\r\n\r\n\r\n # ## Draw a rectangle\r\n # @param `p` a Pair object\r\n # @return this Form\r\n rect: (p) ->\r\n Form.rect( @cc, p, @filled, @stroked )\r\n return @\r\n\r\n\r\n # ## Draw a circle\r\n # @param `p` a Circle object\r\n # @return this Form\r\n circle: (p) ->\r\n Form.circle( @cc, p, @filled, @stroked )\r\n return @\r\n\r\n # ## Draw an arc\r\n # @param `p` a Circle object\r\n # @param `start` start angle\r\n # @param `end` end angle\r\n # @return this Form\r\n arc: (p, start, end) ->\r\n Form.arc( @cc, p, p.radius, start, end);\r\n return @\r\n\r\n # ## Draw a triangle\r\n # @param `p` a Triangle object\r\n # @return this Form\r\n triangle: (p) ->\r\n Form.triangle( @cc, p, @filled, @stroked )\r\n return @\r\n\r\n\r\n # ## Draw a polygon\r\n # @param `ps` an array of Points\r\n # @param `closePath` a boolean value to specify if the path should be closed (joining last point with first point)\r\n # @return this Form\r\n polygon: (ps, closePath) ->\r\n Form.polygon( @cc, ps, closePath, @filled, @stroked)\r\n return @\r\n\r\n\r\n # ## Draw a curve\r\n # @param `ps` an array of Points\r\n # @demo form.curve\r\n # @return this Form\r\n curve: (ps) ->\r\n Form.curve( @cc, ps )\r\n return @\r\n\r\n\r\n # ## Draw text\r\n # @param `p` a Point to specify anchor position\r\n # @param `txt` a string of text\r\n # @param `maxWidth` maximum width per line\r\n # @param `xoff, yoff` x and y positional offset values\r\n text: (p, txt, maxWidth=1000, xoff, yoff) ->\r\n pos = new Vector(p)\r\n if xoff then pos.add(xoff, 0)\r\n if yoff then pos.add(0, yoff)\r\n @cc.fillText(txt, pos.x, pos.y, maxWidth)\r\n return @\r\n\r\n\r\n # Not implemented, see SVGForm\r\n scope: () -> return @cc\r\n\r\n # Not implemented, see SVGForm\r\n enterScope: () -> return @cc\r\n\r\n\r\n# namespace\r\nthis.Form = Form\n# ### A point is the smallest thing in a space. It defines a static position, an indivisible abstraction, and a creative beginning. Think of a point not as a dot, but as a potentiality, visible only to the mind's squinted eyes.\r\nclass Point\r\n\r\n # ## Create a new point using optional parameters which can be a list of numeric values, or an array, or an object with x,y,z properties. If no parameter is specified, this will return a Point at (0,0,0) position.\r\n # @param `args(x,y,z)` optional comma separated values to specify x, y, and z position\r\n # @param `args([x,y,z])` optional array with 1 to 3 values to specify x, y, and z position\r\n # @param `args(pt)` an optional object with `{x, y, z}` properties.\r\n # @eg `new Point()` `new Point(1,2,3)` `new Point([2,4])` `new Point({x:3, y:6, z:9})`\r\n # @return a new Point object\r\n constructor: (args) ->\r\n\r\n # parse arguments and copy to this.x,y,z\r\n @copy( Point.get(arguments) )\r\n\r\n\r\n # ## A static function `Point.get()` which converts arrays or objects to an object with `{x, y, z}` properties.\r\n # @param `args` Similar to Point constructor, this accepts optional parameters which can be comma-separated values, or an array, or any object.\r\n # @eg `Point.get([2,4])` `Point.get({x:3, y:6, z:9})`\r\n # @return an Object with {x, y, z} properties\r\n @get : ( args ) ->\r\n\r\n if args.length > 0\r\n\r\n if typeof args[0] is 'object'\r\n\r\n # if it's Array or arguments (object with length property). Note that \"arguments\" is not considered as an Array by javascript.\r\n if args[0] instanceof Array or args[0].length > 0\r\n\r\n return {\r\n x: args[0][0] || 0\r\n y: args[0][1] || 0\r\n z: args[0][2] || 0\r\n }\r\n\r\n # Point object\r\n else\r\n return {\r\n x: args[0].x || 0\r\n y: args[0].y || 0\r\n z: args[0].z || 0\r\n }\r\n\r\n # multiple args for x, y, z\r\n else\r\n\r\n return {\r\n x: args[0] || 0\r\n y: args[1] || 0\r\n z: args[2] || 0\r\n }\r\n\r\n else\r\n # no argument return empty point\r\n return { x: 0, y: 0, z: 0 }\r\n\r\n\r\n # ## Given another point in relation to this point, this returns which side or quadrant the other point is at.\r\n # @param `pt` a Point object\r\n # @param `epsilon` an optional value to specify the minimum distance threshold. Default is Const.epsilon.\r\n # @eg `p.quadrant( another_p )` `p.quadrant( another_p, 2 )`\r\n # @demo point.quadrant\r\n # @return a constant value such as Const.identical, Const.bottom, Const.top_right\r\n quadrant: (pt, epsilon=Const.epsilon) ->\r\n\r\n if pt.near(@) then return Const.identical\r\n\r\n if (Math.abs(pt.x-@x) < epsilon)\r\n return if pt.y < @y then Const.top else Const.bottom\r\n\r\n if (Math.abs(pt.y-@y) < epsilon)\r\n return if pt.x < @x then Const.left else Const.right\r\n\r\n if (pt.y < @y && pt.x > @x)\r\n return Const.top_right\r\n else if (pt.y < @y && pt.x < @x)\r\n return Const.top_left\r\n else if (pt.y > @y && pt.x < @x)\r\n return Const.bottom_left\r\n else\r\n return Const.bottom_right\r\n\r\n\r\n # ## Set position of this point\r\n # @param `args` comma-separated values, as an array, or as a Point object.\r\n # @eg Eg, `p.set( x, y )` or `p.set( {x, y, z} )` or `p.set( [x, y, z] )`\r\n # @return this Point\r\n set: (args) ->\r\n p = Point.get(arguments)\r\n\r\n # ## property for x position\r\n @x = p.x\r\n\r\n # ## property for y position\r\n @y = p.y\r\n\r\n # ## propoerty for z position\r\n @z = p.z\r\n return @\r\n\r\n\r\n # ## Copy another point object to this point. Slightly faster than `set()`\r\n # @param `p` a Point object to copy\r\n # @return this Point\r\n copy: (p) ->\r\n @x = p.x\r\n @y = p.y\r\n @z = p.z\r\n return @\r\n\r\n\r\n # ## Clone this point\r\n # @return a new Point that is identical to this point\r\n clone: () -> return new Point( @ )\r\n\r\n\r\n # ## Describe this point as a text string\r\n # @return \"Point x, y, z\" text\r\n toString: () -> \"Point #{ @x }, #{ @y }, #{ @z }\"\r\n\r\n # ## Put this vector into an array\r\n # @return an array with a single point object\r\n toArray: () -> [@]\r\n\r\n\r\n\r\n # ## When a point has 3 dimensions `(x,y,z)`, this function converts it to a new point `(x,y)` of a specific 2D plane (such as `yz`)\r\n # @param `axis` an axis id such as `Const.yz`.\r\n # @param `reverse` optional boolean value. If `true`, the mapping will be flipped. Default is false.\r\n # @eg `p.get2D( Const.xy )` `p.get2D(Const.yz, true)`\r\n # @return a new 2D Point\r\n get2D: (axis, reverse=false) ->\r\n\r\n if axis == Const.xy then return new this.__proto__.constructor( @ )\r\n if axis == Const.xz then return new this.__proto__.constructor( @x, @z, @y ) # same flip in reverse\r\n if axis == Const.yz\r\n if reverse\r\n return new this.__proto__.constructor( @z, @x, @y )\r\n else\r\n return new this.__proto__.constructor( @y, @z, @x )\r\n\r\n return new this.__proto__.constructor( @ )\r\n\r\n\r\n\r\n # ## Evaluate the minimum x,y,z of this point and another point, and get a minimum Point\r\n # @param `args` comma-separated values, as an array, or as a Point object.\r\n # @eg `p.min(1,2)` `p.min( another_p )`\r\n # @return this Point\r\n min: (args) ->\r\n _p = Point.get(arguments)\r\n @x = Math.min(@x, _p.x)\r\n @y = Math.min(@y, _p.y)\r\n @z = Math.min(@z, _p.z)\r\n return @\r\n\r\n\r\n # ## Similar to `min()` but returns a new instance\r\n $min: (args) ->\r\n _p = Point.get(arguments)\r\n return new this.__proto__.constructor( Math.min(@x, _p.x), Math.min(@y, _p.y), Math.min(@z, _p.z) )\r\n\r\n\r\n # ## Evaluate the minimum x,y,z of this point and another point, and get a maximum Point\r\n # @param `args` comma-separated values, as an array, or as a Point object.\r\n # @eg `p.max(1,2)` `p.max( another_p )`\r\n # @demo point.max\r\n # @return this Point\r\n max: (args) ->\r\n _p = Point.get(arguments)\r\n @x = Math.max(@x, _p.x)\r\n @y = Math.max(@y, _p.y)\r\n @z = Math.max(@z, _p.z)\r\n return @\r\n\r\n\r\n # ## Similar to `max()` but returns a new instance\r\n $max: (args) ->\r\n _p = Point.get(arguments)\r\n return new this.__proto__.constructor( Math.max(@x, _p.x), Math.max(@y, _p.y), Math.max(@z, _p.z) )\r\n\r\n\r\n # ## Check if this point is at exactly the same position as the other point\r\n # @param `args` comma-separated values, as an array, or as a Point object.\r\n # @eg `p.equal(1,2)` `p.equal( another_p )`\r\n # @return boolean, true if they are equal\r\n equal: (args) ->\r\n _p = Point.get(arguments)\r\n return (_p.x == @x) and (_p.y == @y) and (_p.z == @z)\r\n\r\n\r\n # ## Check if this point is at exactly the same position as the other point\r\n # @param `pt` a Point to check against\r\n # @param `epsilon` an optional threshold value indicating the minimum distance that's near enough\r\n # @eg `p.near(another_p)` `p.near( another_p, 2 )` `p.near( Point.get(1,2,3) )`\r\n # @return boolean, true if they are near\r\n near: ( pt, epsilon=Const.epsilon) ->\r\n _p = Point.get(arguments)\r\n return (Math.abs(_p.x-@x) < epsilon) and (Math.abs(_p.y-@y) < epsilon) and (Math.abs(_p.z-@z) < epsilon)\r\n\r\n\r\n # ## Snap this point's position to the nearest integer by its floor\r\n # @return this Point\r\n floor: () ->\r\n @x = Math.floor( @x )\r\n @y = Math.floor( @y )\r\n @z = Math.floor( @z )\r\n return @\r\n\r\n\r\n # ## Snap this point's position to the nearest integer by its ceiling\r\n # @return this Point\r\n ceil: () ->\r\n @x = Math.ceil( @x )\r\n @y = Math.ceil( @y )\r\n @z = Math.ceil( @z )\r\n return @\r\n\r\n\r\n# namespace\r\nthis.Point = Point\r\n\n# ### A vector points to a point. If a point represents a position on a conceptual plane, then a vector is the thought toward it. As a thought, it has direction and reach. A vector expresses the same concept in verb as a point does in noun.\r\nclass Vector extends Point\r\n\r\n # ## Create a new Vector. A Vector extends a Point and includes functions for arithmetics.\r\n # @param `args` Similar to Point constructor, use comma-separated values, an array, or a Point object as parameters.\r\n # @eg `new Vector()` `new Vector(1,2,3)` `new Vector([2,4])` `new Vector({x:3, y:6, z:9})`\r\n # @return a new Vector object\r\n constructor: () ->\r\n super\r\n\r\n # private function to get arguments based on argument types\r\n _getArgs: (args) -> return if typeof args[0] is 'number' and args.length > 1 then args else args[0]\r\n\r\n # ## Add another vector to this vector.\r\n # @param `args` comma-separated values, or as an array, or a Point object.\r\n # @eg `vec.add(1,2)` `vec.add([2,4])` `vec.add({x:3, y:6, z:9})`\r\n # @demo vector.add\r\n # @return this Vector\r\n add: (args) ->\r\n # add scalar\r\n if typeof arguments[0] is 'number' and arguments.length is 1\r\n @x += arguments[0]\r\n @y += arguments[0]\r\n @z += arguments[0]\r\n # add point\r\n else\r\n _p = Point.get(arguments)\r\n @x += _p.x\r\n @y += _p.y\r\n @z += _p.z\r\n\r\n return @\r\n\r\n\r\n # ## Same as `add()` but returns a new Vector. The values of this vector are not changed.\r\n $add: (args) ->\r\n a = @_getArgs( arguments )\r\n new Vector( @ ).add( a )\r\n\r\n\r\n # ## Subtract another vector from this vector.\r\n # @param `args` 0-3 comma-separated values, or as an array, or a Point object.\r\n # @eg `vec.subtract(1,2)` `vec.subtract([2,4])` `vec.subtract({x:3, y:6, z:9})`\r\n # @return this Vector\r\n subtract: (args) ->\r\n # subtract scalar\r\n if typeof arguments[0] is 'number' and arguments.length is 1\r\n @x -= arguments[0]\r\n @y -= arguments[0]\r\n @z -= arguments[0]\r\n # subtract point\r\n else\r\n _p = Point.get(arguments)\r\n @x -= _p.x\r\n @y -= _p.y\r\n @z -= _p.z\r\n\r\n return @\r\n\r\n # ## Same as `subtract()` but returns a new Vector. The values of this vector are not changed.\r\n $subtract: (args) ->\r\n a = @_getArgs( arguments )\r\n return new Vector( @ ).subtract( a )\r\n\r\n\r\n # ## Multiple this vector with a scalar or vector. If there's only one numberic value in the parameter, this vector will be multiplied by that scalar value. Otherwise, this vector's x,y,z values will be multiplied by the corresponding x,y,z in the parameters. Note that this is different to .dot and .cross products.\r\n # @param `args` 0-3 comma-separated values, or as an array, or a Point object.\r\n # @eg `vec.multiply(4)` `vec.multiply(1,2,3)` `vec.multiply([2,4])` `vec.multiply({x:3, y:6, z:9})`\r\n # @return this Vector\r\n multiply: (args) ->\r\n # multiply scalar\r\n if arguments.length is 1 and (typeof arguments[0] is 'number' or (typeof arguments[0] is 'object' and arguments[0].length == 1) )\r\n @x *= arguments[0]\r\n @y *= arguments[0]\r\n @z *= arguments[0]\r\n # multiply point\r\n else\r\n _p = Point.get(arguments)\r\n @x *= _p.x\r\n @y *= _p.y\r\n @z *= _p.z\r\n\r\n return @\r\n\r\n # ## Same as `multiply()` but returns a new Vector. The values of this vector is not changed.\r\n $multiply: (args) ->\r\n a = @_getArgs( arguments )\r\n return new Vector( @ ).multiply( a )\r\n\r\n\r\n # ## Similar as `multiply()` but easier to read semantically. `vec.divide(2,4,5)` is the same as `vec.multiply(0.5, 0.25, 0.2)`\r\n # @eg `vec.divide(10)` `vec.divide(2,4,5)`\r\n # @return this Vector\r\n divide: (args) ->\r\n # divide scalar\r\n if arguments.length is 1 and (typeof arguments[0] is 'number' or (typeof arguments[0] is 'object' and arguments[0].length == 1) )\r\n @x /= arguments[0]\r\n @y /= arguments[0]\r\n @z /= arguments[0]\r\n # divide point\r\n else\r\n _p = Point.get(arguments)\r\n @x /= _p.x\r\n @y /= _p.y\r\n @z /= _p.z\r\n\r\n return @\r\n\r\n # ## Same as `divide()` but returns a new Vector. The values of this vector is not changed.\r\n $divide: (args) ->\r\n a = @_getArgs( arguments )\r\n return new Vector( @ ).divide( a )\r\n\r\n\r\n # ## Apply a function to all points in the `toArray()` list. This is usually applied to `Pair`, `PointSet` and other objects to call a function to all its points.\r\n # @param `name` a function of this class\r\n # @param `args...` optional, comma-separated arguments to pass to the function\r\n # @eg `pair.op(\"add\", 1,2,3)` `pointset.op(\"multiply\", 2)`\r\n op: ( name, args... ) ->\r\n pts = @toArray()\r\n for p in pts\r\n p[name]( args... )\r\n return @\r\n\r\n\r\n # ## Similar to `op()` but apply the function to a new instance.\r\n $op: ( name, args... ) ->\r\n instance = @clone()\r\n pts = instance.toArray()\r\n for p in pts\r\n p[name]( args... )\r\n return instance\r\n\r\n\r\n\r\n # ## Get the angle of this vector on a plane, or get the angle from this vector to another point. If no parameter specified, this will return the angle on xy plane.\r\n # @param `axis` single optional argument to specify axis id (eg, `Const.yz`) to specify a plane\r\n # @param `pt` single optional argument to specify a Point object, to calculate the angle from this Point to another Point instead\r\n # @param `axis, pt` 2 arguments in this sequence, as optional axis id and Point object, to get the angle to a Point on a specific plane\r\n # @eg `vec.angle()` `vec.angle(Const.yz)` `vec.angle(another_pt)` `vec.angle(Const.xz, another_pt)`\r\n # @return a radian value\r\n angle: (args) ->\r\n\r\n # no argument angle from origin\r\n if arguments.length is 0\r\n return Math.atan2( @y, @x )\r\n\r\n # if first argument is axis\r\n if typeof arguments[0] is 'string'\r\n axis = arguments[0]\r\n p = if arguments.length > 1 then @$subtract( arguments[1] ).multiply(-1) else undefined\r\n\r\n # first argument is object or none\r\n else\r\n p = @$subtract( arguments[0]).multiply(-1)\r\n axis = false\r\n\r\n # if has point and no axis, find xy to another point\r\n if p and !axis\r\n return Math.atan2( p.y, p.x )\r\n\r\n # has axis parameter\r\n else if axis is Const.xy\r\n return if p then Math.atan2( p.y, p.x ) else (Math.atan2( @y, @x ))\r\n\r\n else if axis is Const.yz\r\n return if p then Math.atan2( p.z, p.y ) else (Math.atan2( @z, @y ))\r\n\r\n else if axis is Const.xz\r\n return if p then Math.atan2( p.z, p.x ) else (Math.atan2( @z, @x ))\r\n\r\n\r\n # ## Get the change in radian between this and another vector (from origin position)\r\n # @param `vec` another Vector to compare against\r\n # @param axis optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.angleBetween( another_pt )` `vec.angleBetween( another_pt, Const.yz )`\r\n angleBetween: (vec, axis=Const.xy) ->\r\n Util.boundRadian( @angle( axis ), true ) - Util.boundRadian( vec.angle( axis ), true )\r\n\r\n\r\n # ## Get the mangnitude (ie, distance from origin) of this vector, or get the distance from this vector to another point. Default is to get the magnitude on xyz plane.\r\n # @param `axis` single argument as optional axis id (eg, `Const.yz`) to specify a plane\r\n # @param `pt` single argument as optional Point object to calculate the distance from this Point to another Point instead\r\n # @param `sqrt` single argument as optional boolean value to get distance-squared value if set to `false`. Default is true.\r\n # @param `axis, pt, sqrt` 3 optional parameters can be used in this sequence to specify a plane, a Point, and whether to get squared value.\r\n # @eg `vec.magnitude()` `vec.magnitude(false)` `vec.magnitude(Const.yz)` `vec.magnitude(another_pt)` `vec.magnitude(Const.xz, another_pt, false)`.\r\n # @return magnitude value\r\n magnitude: (args) ->\r\n\r\n m = {x:@x*@x, y:@y*@y, z:@z*@z }\r\n\r\n # if last argument is false, then don't use Math.sqrt\r\n useSq = (arguments.length >= 1 and !arguments[ arguments.length-1 ])\r\n _sq = if useSq then ( (x) -> x ) else Math.sqrt\r\n\r\n # no argument angle from origin\r\n if arguments.length is 0\r\n return _sq( m.x + m.y + m.z )\r\n\r\n # if first argument is axis\r\n if typeof arguments[0] is 'string'\r\n axis = arguments[0]\r\n if arguments.length > 1 and arguments[1]\r\n p = @$subtract( arguments[1] )\r\n else\r\n p = undefined\r\n\r\n # first argument is object or none\r\n else\r\n p = @$subtract( arguments[0] )\r\n axis = false\r\n\r\n mag = if p then {x:p.x*p.x, y:p.y*p.y, z:p.z*p.z} else m\r\n\r\n # if has point and no axis, find xyz to another point\r\n if p and !axis\r\n return _sq( mag.x + mag.y + mag.z )\r\n\r\n # has axis parameter\r\n else if axis is Const.xy\r\n return _sq( mag.x + mag.y )\r\n\r\n else if axis is Const.yz\r\n return _sq( mag.y + mag.z )\r\n\r\n else if axis is Const.xz\r\n return _sq( mag.x + mag.z )\r\n\r\n\r\n # ## Get the distance between this and another point. An alias of magnitude.\r\n # @param `pt` another point\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @return distance\r\n distance: (pt, axis=Const.xy) -> @magnitude( axis, pt )\r\n\r\n # ## Normalize this vector to a unit vector, which has magnitude of 1.\r\n # @demo vector.normalize\r\n # @return this vector\r\n normalize: () ->\r\n @set( @$normalize() )\r\n return @\r\n\r\n\r\n # ## Get a normalized unit vector which has magnitude of 1. The original vector is not changed.\r\n # @return a new unit vector\r\n $normalize: () ->\r\n m = @magnitude()\r\n\r\n if m is 0\r\n return new Vector()\r\n else\r\n return new Vector( @x/m, @y/m, @z/m )\r\n\r\n # ## Set this vector's values to its absolute value (always positive).\r\n # @return this vector\r\n abs: () ->\r\n @x = Math.abs(@x)\r\n @y = Math.abs(@y)\r\n @z = Math.abs(@z)\r\n return @\r\n\r\n\r\n # ## Calculate the [dot product](http://en.wikipedia.org/wiki/Dot_product) of this and another vector.\r\n # @param `p` a Point to calculate the dot product\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.dot( another_vec )` `vec.dot( another_vec, Const.xz )`\r\n # @return the dot product which is a scalar (numeric) value\r\n dot: ( p, axis=Const.xyz ) ->\r\n if axis == Const.xyz\r\n return @x*p.x + @y*p.y + @z*p.z\r\n else if axis == Const.xy\r\n return @x*p.x + @y*p.y\r\n else if axis == Const.yz\r\n return @y*p.y + @z*p.z\r\n else if axis == Const.xz\r\n return @x*p.x + @z*p.z\r\n else\r\n return @x*p.x + @y*p.y + @z*p.z\r\n\r\n # ## Calculate [vector projection](http://en.wikipedia.org/wiki/Vector_projection). A vector projection has the same direction as this vector but a different length. So if you draw a line from the projection vector to the vector specified in the parameter, it will be perpendicular to this vector.\r\n # @param `vec` a Vector to calculate the projection\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.projection( another_vec)` `vec.projection( another_vec, Const.xz )`\r\n # @demo vector.projection\r\n # @return the vector projection\r\n projection: ( vec, axis=Const.xyz ) ->\r\n m = vec.magnitude()\r\n a = @$normalize()\r\n b = new Vector( vec.x/m, vec.y/m, vec.z/m )\r\n dot = a.dot( b, axis )\r\n return a.$multiply( m * dot )\r\n\r\n # ## Calculate the [cross product](http://en.wikipedia.org/wiki/Cross_product) of this and another vector.\r\n # @param `p` a Point to calculate the cross product\r\n # @eg `vec.cross( another_vec )`\r\n # @return the cross product which is a vector\r\n cross: ( p ) ->\r\n new Vector( (@y*p.z - @z*p.y), (@z*p.x - @x*p.z), (@x*p.y - @y*p.x) )\r\n\r\n\r\n # ## Get the middle vector between this and another vector\r\n # @param `vec` a Vector to calculate the bisect\r\n # @eg `vec.bisect( another_vec )`\r\n # @return a vector in the middle\r\n bisect: ( vec, isNormalized=false ) ->\r\n if isNormalized\r\n return @$add(vec).divide(2)\r\n else\r\n return @$normalize().add( vec.$normalize() ).divide(2)\r\n\r\n\r\n # ## Get 2 vectors that are perpendicular to this vector\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.perpendicular()` `vec.perpendicular(Const.yz)`\r\n # @return an array of two vectors\r\n perpendicular: ( axis=Const.xy ) ->\r\n switch axis\r\n when Const.xy then return [new Vector( -@y, @x, @z ), new Vector( @y, -@x, @z )]\r\n when Const.yz then return [new Vector( @x, -@z, @y ), new Vector( @x, @z, -@y )]\r\n when Const.xz then return [new Vector( -@z, @y, @x ), new Vector( @z, -@y, @x )]\r\n else return [new Vector( -@y, @x, @z ), new Vector( @y, -@x, @z )]\r\n\r\n\r\n # ## Check if another vector is perpendicular to this vector\r\n # @param `p` a Point to check against\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.isPerpendicular( another_vec )` `vec.isPerpendicular( another_vec, Const.yz )`\r\n # @return a boolean (true or false)\r\n isPerpendicular: ( p, axis=Const.xyz ) -> @dot(p, axis) == 0\r\n\r\n\r\n # ## Get surface normal vector. A [normal](http://en.wikipedia.org/wiki/Normal_%28geometry%29) is a vector perpendicular to a plane or object.\r\n # @param `p` a Point to calculate the surface normal\r\n # @eg `vec.surfaceNormal( another_vec )`\r\n # @return the normal vector\r\n surfaceNormal: ( p ) ->\r\n return @cross( p ).normalize(true)\r\n\r\n\r\n # ## move origin to a new position. In subclasses of `Vector`, such as `Pair` or `PointSet`, this will move all the points.\r\n # @param `args` new position as 1-3 comma-separated values, or as an array, or a Point object.\r\n moveTo: ( args ) ->\r\n target = Point.get(arguments)\r\n d = @$subtract( target )\r\n pts = @toArray()\r\n for p in pts\r\n p.subtract( d )\r\n\r\n return @\r\n\r\n # ## move origin by a certain amount. In subclasses of `Vector`, such as `Pair` or `PointSet`, this will move all the points.\r\n # @param `args` move amount as 1-3 comma-separated values, or as an array, or a Point object.\r\n moveBy: ( args ) ->\r\n inc = Point.get(arguments)\r\n pts = @toArray()\r\n for p in pts\r\n p.add( inc )\r\n\r\n return @\r\n\r\n\r\n # ## Rotate this vector around an anchor point on a 2D plane. In subclasses of `Vector`, such as `Pair` or `PointSet`, this will rotate all the points.\r\n # @param `radian` a radian value specifying the angle. (where 1 degree = PI / 180 radian)\r\n # @param `anchor` a Point object specifying the anchor position\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.rotate2D( Math.PI/2, anchor_pt )` `vec.rotate2D( 30*Const.deg_to_rad, another_pt, Const.xz )`\r\n # @demo vector.rotate2D\r\n # @return this vector\r\n rotate2D: (radian, anchor, axis=Const.xy) ->\r\n if !anchor then anchor = new Point(0,0,0)\r\n mx = Matrix.rotateAnchor2D( radian, anchor, axis )\r\n\r\n pts = @toArray()\r\n for p in pts\r\n Matrix.transform2D( p, mx, axis )\r\n\r\n return @\r\n\r\n\r\n # ## Reflect this vector along a path. In subclasses of `Vector`, such as `Pair` or `PointSet`, this will reflect all the points.\r\n # @param `line` a Line object to specify the path\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.reflect2D( line )` `vec.reflect2D( line, Const.xz )`\r\n # @return this vector\r\n reflect2D: (line, axis=Const.xy) ->\r\n mx = Matrix.reflectAnchor2D( line, axis )\r\n pts = @toArray()\r\n for p in pts\r\n Matrix.transform2D( p, mx, axis )\r\n\r\n return @\r\n\r\n\r\n # ## Rescale this vector from an anchor point. In subclasses of `Vector`, such as `Pair` or `PointSet`, this will scale all the points together.\r\n # @param `sx` x scale value, where 1 = no change\r\n # @param `sy` y scale value, where 1 = no change\r\n # @param `anchor` a Point object specifying the anchor position to scale from\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.scale2D( 0.7, 1.2, anchor_pt )` `vec.scale2D( 1, 3, anchor_pt, Const.xz )`\r\n # @demo vector.scale2D\r\n # @return this vector\r\n scale2D: (sx, sy, anchor, axis=Const.xy) ->\r\n if !anchor then anchor = new Point(0,0,0)\r\n mx = Matrix.scaleAnchor2D( sx, sy, anchor, axis )\r\n pts = @toArray()\r\n for p in pts\r\n Matrix.transform2D( p, mx, axis )\r\n\r\n return @\r\n\r\n\r\n # ## Shear this vector from an anchor point. In subclasses of `Vector`, such as `Pair` or `PointSet`, this will shear all the points together.\r\n # @param `sx` x scale value, where 1 = no change\r\n # @param `sy` y scale value, where 1 = no change\r\n # @param `anchor` a Point object specifying the anchor position to scale from\r\n # @param `axis` optional axis id (eg `Const.xy`) to specify a plane\r\n # @eg `vec.scale2D( 0.7, 1.2, anchor_pt )` `vec.scale2D( 1, 3, anchor_pt, Const.xz )`\r\n # @return this vector\r\n shear2D: (sx, sy, anchor, axis=Const.xy) ->\r\n if !anchor then anchor = new Point(0,0,0)\r\n mx = Matrix.shearAnchor2D( sx, sy, anchor, axis )\r\n pts = @toArray()\r\n for p in pts\r\n Matrix.transform2D( p, mx, axis )\r\n\r\n return @\r\n\r\n # ## Clone this vector\r\n # @return a new vector identical to this vector\r\n clone: () -> return new Vector(@)\r\n\r\n\r\n # ## Describe this point as a text string\r\n # @return \"Vector x, y, z\" text\r\n toString: () -> \"Vector #{ @x }, #{ @y }, #{ @z }\"\r\n\r\n\r\n\r\n\r\n# namespace\r\nthis.Vector = Vector\r\n\n# ### Color is a sensation of electromagnetic radiation, but your mind interprets it with such obstinate attitude that your favorite color may be, god forbids, pink. Or perhaps color is more like music, whose harmony and rhythm evoke emotions, and can be organized in different sequences to create meaningful narratives.\r\n\r\nclass Color extends Vector\r\n\r\n # ## Create a new Color. Color lets you define a color in a specific mode. [This article](https://software.intel.com/en-us/node/503873) from Intel has a good overview of different color models.\r\n # @param `args` Set the three values of a color as comma-separated values, as an array, or as an object with `{x, y, z}` properties. Optionally set `alpha` in a 4th parameter, and color mode string in 5th parameter.\r\n # @eg `new Color()` `new Color(255,100,20)` `new Color([2,4])` `new Color({x:3, y:6, z:9})` `new Color(360,1,1,0.5)`, `new Color(100,50,-50,1,'lab')`\r\n # @return a new Color object\r\n constructor: ( args ) ->\r\n super\r\n\r\n _args = if ( Array.isArray(arguments[0]) and arguments[0][3] != undefined ) then arguments[0] else arguments\r\n\r\n # ## alpha value from 0 to 1, where 0 is fully transparent, and 1 is fully opaque\r\n @alpha = if _args.length >=4 then Math.min( 1, Math.max( _args[3], 0) ) else 1\r\n\r\n # ## color mode id such as \"lab\" or \"rgb\"\r\n @mode = 'rgb'\r\n if arguments.length >=5 then @mode = arguments[4]\r\n if typeof arguments[1] == \"string\" then @mode = arguments[1]\r\n\r\n\r\n # ## A property to adject XYZ for Standard Observer 2deg, Daylight/sRGB illuminant D65\r\n @XYZ = {\r\n D65: {x: 95.047, y: 100, z: 108.883}\r\n }\r\n\r\n ## # A static function `Color.parseHex` to parse a hex string and a Color or rgb array\r\n # @param `hex` hexadecial string with or without \"#\" in the beginning. It can be \"FF9900\", \"F90\", or \"FF9900CC\" with alpha.\r\n # @param `asColor` Optional boolean value where the return value will be a `Color` object if set to `true`. Defaults to `false` which returns an array.\r\n # @eg `Color.parseHex(\"#FF9900\")` `Color.parseHex(\"F90\")` `Color.parseHex(\"FF9900CC\")` `Color.parseHex(\"FF9900\", true)`\r\n # @return a Color object, or an array [r, g, b]\r\n @parseHex : (hex, asColor=false) ->\r\n if hex.indexOf('#') == 0 then hex = hex.substr(1) # remove '#' if needed\r\n if hex.length == 3 then hex = \"\"+hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2]\r\n if hex.length == 8\r\n @alpha = hex.substr(6) & 0xFF / 255\r\n hex = hex.substring(0,6)\r\n\r\n hexValue = parseInt( hex, 16 )\r\n rgb = [ hexValue >> 16, hexValue >> 8 & 0xFF, hexValue & 0xFF]\r\n return if asColor then new Color( rgb[0], rgb[1], rgb[2] ) else rgb\r\n\r\n\r\n # ## set a color mode and convert current color to new color mode\r\n # @param `m` a string to specify color mode: 'hsl', 'hsb', 'rgb', 'lab', 'lch', 'xyz'\r\n # @eg `color.setMode('lab')`\r\n # @return this Color object with new color mode\r\n setMode : ( m ) ->\r\n m = m.toLowerCase()\r\n\r\n if m != @mode\r\n switch @mode\r\n when 'hsl' then @copy( Point.get( Color.HSLtoRGB(@x, @y, @z) ) )\r\n when 'hsb' then @copy( Point.get( Color.HSBtoRGB(@x, @y, @z) ) )\r\n when 'lab' then @copy( Point.get( Color.LABtoRGB(@x, @y, @z) ) )\r\n when 'lch' then @copy( Point.get( Color.LCHtoRGB(@x, @y, @z) ) )\r\n when 'xyz' then @copy( Point.get( Color.XYZtoRGB(@x, @y, @z) ) )\r\n\r\n\r\n switch m\r\n when 'hsl' then @copy( Point.get( Color.RGBtoHSL(@x, @y, @z) ) )\r\n when 'hsb' then @copy( Point.get( Color.RGBtoHSB(@x, @y, @z) ) )\r\n when 'lab' then @copy( Point.get( Color.RGBtoLAB(@x, @y, @z) ) )\r\n when 'lch' then @copy( Point.get( Color.RGBtoLCH(@x, @y, @z) ) )\r\n when 'xyz' then @copy( Point.get( Color.RGBtoXYZ(@x, @y, @z) ) )\r\n\r\n# if m != @mode\r\n# if m is 'rgb' # to RGB\r\n# if @mode is 'hsl' then @copy( Point.get( Color.HSLtoRGB(@x, @y, @z) ) )\r\n# if @mode is 'hsb' then @copy( Point.get( Color.HSBtoRGB(@x, @y, @z) ) )\r\n#\r\n# else if m is 'hsb' # to HSB\r\n# if @mode is 'rgb' then @copy( Point.get( Color.RGBtoHSB(@x, @y, @z) ) )\r\n# # # TODO: if @mode is 'hsl' then\r\n#\r\n# else if m is 'hsl' # to HSL\r\n# if @mode is 'rgb' then @copy( Point.get( Color.RGBtoHSL(@x, @y, @z) ) )\r\n# # # TODO: if @mode is 'hsb' then\r\n#\r\n# else if m is 'xyz'\r\n# if @mode is 'rgb' then @copy( Point.get( Color.RGBtoXYZ(@x, @y, @z) ) )\r\n# # # TODO: if @mode is 'hsb' then\r\n\r\n @mode = m\r\n return @\r\n\r\n\r\n # ## Get rgb value as hex string such as '#123456'\r\n hex: () ->\r\n if @mode is 'rgb' then @floor() # make sure to get rgb as integer\r\n cs = @values( (@mode != 'rgb') ) # convert to rgb if needed\r\n\r\n # pad zero\r\n _hexstring = (n) ->\r\n n = n.toString(16)\r\n if n.length < 2\r\n return '0'+n\r\n else\r\n return n\r\n\r\n ct = (_hexstring( n ) for n in cs)\r\n return '#' + ct[0] + ct[1] + ct[2]\r\n\r\n\r\n # ## Get rgb string such as 'rgb(12,34,56)'\r\n rgb: () ->\r\n if @mode is 'rgb' then @floor() # make sure to get rgb as integer\r\n cs = @values( (@mode != 'rgb') ) # convert to rgb if needed\r\n \"rgb(#{ cs[0] }, #{ cs[1] }, #{ cs[2] })\"\r\n\r\n\r\n # ## Get rgba string such as 'rgba(12,34,56, 0.2)'\r\n rgba: () ->\r\n if @mode is 'rgb' then @floor() # make sure to get rgb as integer\r\n cs = @values( (@mode != 'rgb') ) # convert to rgb if needed\r\n \"rgba(#{ cs[0] }, #{ cs[1] }, #{ cs[2] }, #{ @alpha })\"\r\n\r\n\r\n # ## Get color values (based on current color mode) as an array\r\n # @param `toRGB` Optional boolean value to convert to rgb value if set to `true`. Default is false.\r\n # @return an array of colro values\r\n values: ( toRGB=false ) ->\r\n cs = [@x, @y, @z]\r\n if toRGB and @mode != 'rgb' # convert to rgb first\r\n switch @mode\r\n when 'hsl' then cs = Color.HSLtoRGB(@x, @y, @z)\r\n when 'hsb' then cs = Color.HSBtoRGB(@x, @y, @z)\r\n when 'lab' then cs = Color.LABtoRGB(@x, @y, @z)\r\n when 'lch' then cs = Color.LCHtoRGB(@x, @y, @z)\r\n when 'xyz' then cs = Color.XYZtoRGB(@x, @y, @z)\r\n\r\n return (Math.floor( v ) for v in cs)\r\n\r\n\r\n # ## override clone\r\n clone: () ->\r\n c = new Color(@x, @y, @z, @alpha)\r\n c.mode = @mode\r\n return c\r\n\r\n\r\n # ## Describe this color as a text string\r\n # @return \"Color(mode) x, y, z, alpha\" text\r\n toString: () -> \"Color (#{@mode} mode): #{ @x }, #{ @y }, #{ @z } #{ @alpha }\"\r\n\r\n\r\n # color conversion code ported to coffeescript\r\n # http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript\r\n\r\n # ## A static function `Color.RGBtoHSL` to convert RGB to HSL\r\n # @param `r, g, b` red, green, blue values from 0 to 255\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @eg `Color.RGBtoHSL(255,70,0)` `Color.RGBtoHSL(1,0.3,0, true)`\r\n # @return an array of [h, s, l] where h is from 0 to 360, s is from 0 to 1, and l is from 0 to 1.\r\n @RGBtoHSL : (r, g, b, normalizedInput, normalizedOutput) ->\r\n if not normalizedInput\r\n r /= 255\r\n g /= 255\r\n b /= 255\r\n\r\n max = Math.max(r, g, b)\r\n min = Math.min(r, g, b)\r\n h = (max + min) / 2\r\n s = h\r\n l = h\r\n\r\n if max == min\r\n h = 0\r\n s = 0 # achromatic\r\n else\r\n d = max - min\r\n s = if l > 0.5 then d / (2 - max - min) else d / (max + min)\r\n\r\n switch max\r\n when r then h = (g - b) / d + (if g < b then 6 else 0)\r\n when g then h = (b - r) / d + 2\r\n when b then h = (r - g) / d + 4\r\n else h = 0\r\n\r\n return if normalizedOutput then [h/60, s, l] else [ h*60, s, l]\r\n\r\n\r\n # ## A static function `Color.HSLtoRGB` to convert HSL to RGB\r\n # @param `h, s, l` hue, saturation, and lightness. hue value from 0 to 360, saturation and lightness values from 0 to 1\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @eg `Color.HSLtoRGB(360,0.7,0.9)` `Color.HSLtoRGB(1,0.3,0, true)`\r\n # @demo color.HSLtoRGB\r\n # @return an array of [r, g, b] where each value is from 0 to 255\r\n @HSLtoRGB : ( h, s, l, normalizedInput, normalizedOutput) ->\r\n\r\n if s == 0\r\n return if normalizedOutput then [1,1,1] else [255,255,255]\r\n else\r\n\r\n if not normalizedInput\r\n h /= 360 # normalize hue\r\n\r\n q = if l <= 0.5 then l * (1 + s) else l + s - (l * s)\r\n p = 2 * l - q;\r\n\r\n hue2rgb = ( p, q, t ) ->\r\n\r\n if t < 0\r\n t += 1\r\n else if t > 1\r\n t -= 1\r\n\r\n if t * 6 < 1\r\n return p + (q - p) * t * 6\r\n else if t * 2 < 1\r\n return q\r\n else if t * 3 < 2\r\n return p + (q - p) * ((2 / 3) - t) * 6\r\n else\r\n return p\r\n\r\n r = hue2rgb( p, q, ( h + 1/3 ) )\r\n g = hue2rgb( p, q, h )\r\n b = hue2rgb( p, q, ( h - 1/3 ) )\r\n\r\n return if normalizedOutput then [ r, g, b ] else [r*255, g*255, b*255]\r\n\r\n\r\n # ## A static function `Color.RGBtoHSB` to convert RGB to HSB\r\n # @param `r, g, b` red, green, blue values from 0 to 255\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @eg `Color.RGBtoHSB(255,70,0)` `Color.RGBtoHSB(1,0.3,0, true)`\r\n # @return an array of [h, s, b] where h is from 0 to 360, s is from 0 to 1, and b is from 0 to 1.\r\n @RGBtoHSB : (r, g, b, normalizedInput, normalizedOutput) ->\r\n\r\n if not normalizedInput\r\n r /= 255\r\n g /= 255\r\n b /= 255\r\n\r\n max = Math.max(r, g, b)\r\n min = Math.min(r, g, b)\r\n\r\n d = max - min\r\n s = if max is 0 then 0 else d / max\r\n v = max\r\n\r\n if max is min\r\n h = 0\r\n else\r\n switch max\r\n when r then h = (g - b) / d + ( if g < b then 6 else 0 )\r\n when g then h = (b - r) / d + 2\r\n when b then h = (r - g) / d + 4\r\n else h = 0\r\n\r\n return if normalizedOutput then [h / 60, s, v] else [h * 60, s, v]\r\n\r\n\r\n # ## A static function `Color.HSBtoRGB` to convert HSB to RGB\r\n # @param `h, s, b` hue, saturation, and brightness. hue value from 0 to 360, saturation and brightness values from 0 to 1\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @eg `Color.HSBtoRGB(360,0.7,0.9)` `Color.HSBtoRGB(1,0.3,0, true)`\r\n # @demo color.HSBtoRGB\r\n # @return an array of [r, g, b] where each value is from 0 to 255\r\n @HSBtoRGB : (h, s, v, normalizedInput, normalizedOutput) ->\r\n\r\n if not normalizedInput\r\n h /= 360\r\n\r\n i = Math.floor(h * 6)\r\n f = h * 6 - i\r\n p = v * (1 - s)\r\n q = v * (1 - f * s)\r\n t = v * (1 - (1 - f) * s)\r\n\r\n switch i % 6\r\n when 0 then rgb = [v, t, p]\r\n when 1 then rgb = [q, v, p]\r\n when 2 then rgb = [p, v, t]\r\n when 3 then rgb = [p, q, v]\r\n when 4 then rgb = [t, p, v]\r\n when 5 then rgb = [v, p, q]\r\n else rgb = [0,0,0]\r\n\r\n return if normalizedOutput then rgb else [ rgb[0]*255, rgb[1]*255, rgb[2]*255 ]\r\n\r\n\r\n # ## Static function `Color.RGBtoLAB` transforms RGB to LAB\r\n # @param `r, g, b` red, green, and blue values from 0 to 255\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @return an array of [L, a, b] where lightness (L) is from 0 to 100, a and b component values are from -128 to 127. red/green colors are represented in a, and yellow/blue colors are represented in b.\r\n @RGBtoLAB : (r, g, b, normalizedInput, normalizedOutput) ->\r\n if normalizedInput\r\n r *= 255\r\n g *= 255\r\n b *= 255\r\n\r\n xyz = Color.RGBtoXYZ(r,g,b)\r\n return Color.XYZtoLAB( xyz[0], xyz[1], xyz[2] )\r\n\r\n\r\n # ## Static function `Color.LABtoRGB` transforms LAB to RGB\r\n # @param `L, a, b` lightness (L) is from 0 to 100, a and b component values are from -128 to 127. red/green colors are represented in a, and yellow/blue colors are represented in b.\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @demo color.LABtoRGB\r\n # @return an array of [r, g, b] where each value is from 0 to 255\r\n @LABtoRGB : (L, a, b, normalizedInput, normalizedOutput) ->\r\n if normalizedInput\r\n L *= 100\r\n a = (a-0.5) * 127\r\n b = (b-0.5) * 127\r\n\r\n xyz = Color.LABtoXYZ( L, a, b)\r\n rgb = Color.XYZtoRGB( xyz[0], xyz[1], xyz[2] )\r\n return if normalizedOutput then [ rgb[0]/255, rgb[1]/255, rgb[2]/255 ] else rgb\r\n\r\n # ## Static function `Color.RGBtoLCH` transforms RGB to LCH (Cylindrical Lab)\r\n # @param `r, g, b` red, green, and blue values from 0 to 255\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @return an array of [L, c, h] where lightness (l) and chroma (c) is from 0 to 100, and hue (h) is from 0 to 360\r\n @RGBtoLCH : (r, g, b, normalizedInput, normalizedOutput) ->\r\n if normalizedInput\r\n r *= 255\r\n g *= 255\r\n b *= 255\r\n\r\n lab = Color.RGBtoLAB(r,g,b)\r\n lch = Color.LABtoLCH( lab[0], lab[1], lab[2] )\r\n return if normalizedOutput then [ lch[0]/100, lch[1]/100, lch[2]/360 ] else lch\r\n\r\n\r\n # ## Static function `Color.LCHtoRGB` transforms LCH to RGB\r\n # @param `L, c, h` lightness (l) and chroma (c) is from 0 to 100, and hue (h) is from 0 to 360\r\n # @return an array of [r, g, b] where each value is from 0 to 255\r\n @LCHtoRGB : (L, c, h, normalizedInput, normalizedOutput) ->\r\n if normalizedInput\r\n L *= 100\r\n c *= 100\r\n h *= 360\r\n\r\n lab = Color.LCHtoLAB( L, c, h )\r\n xyz = Color.LABtoXYZ( lab[0], lab[1], lab[2])\r\n rgb = Color.XYZtoRGB( xyz[0], xyz[1], xyz[2] )\r\n return if normalizedOutput then [ rgb[0]/255, rgb[1]/255, rgb[2]/255 ] else rgb\r\n\r\n\r\n # ## Static function `Color.XYZtoRGB` to convert XYZ to RGB. This is usually used when converting between LAB and RGB.\r\n # @param `x, y, z` x, y, z values from 0 to 100\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @return an array of [r, g, b] where each value is from 0 to 255\r\n @XYZtoRGB : (x, y, z, normalizedInput, normalizedOutput) ->\r\n\r\n if not normalizedInput\r\n x = x / 100\r\n y = y / 100\r\n z = z / 100\r\n\r\n rgb = [\r\n x * 3.2404542 + y * -1.5371385 + z * -0.4985314\r\n x * -0.9692660 + y * 1.8760108 + z * 0.0415560\r\n x * 0.0556434 + y * -0.2040259 + z * 1.0572252\r\n ]\r\n\r\n # convert xyz to rgb. Note that not all colors are visible in rgb, so here we bound rgb between 0 to 1\r\n for c, i in rgb\r\n if c < 0\r\n rgb[i] = 0\r\n else\r\n rgb[i] = Math.min( 1, if ( c > 0.0031308 ) then 1.055 * ( Math.pow( c, 1/2.4 ) ) - 0.055 else 12.92 * c )\r\n\r\n# r = if ( r > 0.0031308 ) then 1.055 * ( Math.pow( r, 1/2.4 ) ) - 0.055 else (if r < 0 then 0 else 12.92 * r)\r\n# g = if ( g > 0.0031308 ) then 1.055 * ( Math.pow( g, 1/2.4 ) ) - 0.055 else (if g < 0 then 0 else 12.92 * g)\r\n# b = if ( b > 0.0031308 ) then 1.055 * ( Math.pow( b, 1/2.4 ) ) - 0.055 else (if b < 0 then 0 else 12.92 * b)\r\n\r\n return if normalizedOutput then rgb else [ Math.round(rgb[0] * 255), Math.round(rgb[1] * 255), Math.round(rgb[2] * 255) ]\r\n\r\n\r\n # ## A static function `Color.RGBtoXYZ` to convert RGB to XYZ. This is usually used when converting between LAB and RGB.\r\n # @param `r, g, b` red, green, blue values from 0 to 255\r\n # @param `normalizedInput, normalizedOutput` Optional boolean values to indicate if input parameters are normalized (0 to 1), and if return value should be normalized\r\n # @return an array of [x, y, z] where each value is from 0 to 100\r\n @RGBtoXYZ : (r, g, b, normalizedInput, normalizedOutput) ->\r\n\r\n if not normalizedInput\r\n r = ( r / 255 )\r\n g = ( g / 255 )\r\n b = ( b / 255 )\r\n\r\n r = if ( r > 0.04045 ) then Math.pow( ( r + 0.055 ) / 1.055, 2.4 ) else r / 12.92\r\n g = if ( g > 0.04045 ) then Math.pow( ( g + 0.055 ) / 1.055, 2.4 ) else g / 12.92\r\n b = if ( b > 0.04045 ) then Math.pow( ( b + 0.055 ) / 1.055, 2.4 ) else b / 12.92\r\n\r\n if not normalizedOutput\r\n r = r * 100\r\n g = g * 100\r\n b = b * 100\r\n\r\n return [\r\n r * 0.4124564 + g * 0.3575761 + b * 0.1804375\r\n r * 0.2126729 + g * 0.7151522 + b * 0.0721750\r\n r * 0.0193339 + g * 0.1191920 + b * 0.9503041\r\n ]\r\n\r\n\r\n # ## Static function `Color.XYZtoLAB` to convert XYZ to LAB.\r\n # @param `x, y, z` x, y, z values from 0 to 100\r\n # @return an array of [l, a, b] where lightness (L) is from 0 to 100, a and b values are from -128 to 127\r\n @XYZtoLAB : (x, y, z) ->\r\n\r\n # adjusted\r\n x = x / Color.XYZ.D65.x\r\n y = y / Color.XYZ.D65.y\r\n z = z / Color.XYZ.D65.z\r\n\r\n calc = (n) ->\r\n return if ( n > 0.008856 ) then Math.pow(n, 1/3) else (7.787 * n) + 16/116\r\n\r\n cy = calc( y )\r\n\r\n return [\r\n ( 116 * cy ) - 16\r\n 500 * ( calc(x) - cy )\r\n 200 * ( cy - calc(z) )\r\n ]\r\n\r\n # ## Static function `Color.LABtoXYZ` to convert LAB to XYZ.\r\n # @param `L, a, b` lightness (L) is from 0 to 100, a and b component values are from -128 to 127\r\n # @return an array of [x, y, z] where each value is from 0 to 100\r\n @LABtoXYZ : (L, a, b) ->\r\n y = ( L + 16 ) / 116\r\n x = a / 500 + y\r\n z = y - b / 200\r\n\r\n calc = (n) ->\r\n nnn = Math.pow(n,3)\r\n return if ( nnn > 0.008856 ) then nnn else ( n - 16 / 116 ) / 7.787\r\n\r\n # adjusted\r\n xyz = [\r\n Math.min( Color.XYZ.D65.x, Color.XYZ.D65.x * calc(x) )\r\n Math.min( Color.XYZ.D65.y, Color.XYZ.D65.y * calc(y) )\r\n Math.min( Color.XYZ.D65.y, Color.XYZ.D65.z * calc(z) )\r\n ]\r\n\r\n return xyz\r\n\r\n # ## Static function `Color.XYZtoLUV` to convert XYZ to LUV.\r\n # @param `x, y, z` x, y, z values from 0 to 100\r\n # @return an array of [l, u, v] where lightness is from 0 to 100, u is from -134 to 220, and v is from -140 o 122\r\n @XYZtoLUV : (x, y, z) ->\r\n u = ( 4 * x ) / ( x + ( 15 * y ) + ( 3 * z ) )\r\n v = ( 9 * y ) / ( x + ( 15 * y ) + ( 3 * z ) )\r\n\r\n y = y / 100\r\n y = if ( y > 0.008856 ) then Math.pow( y, 1/3 ) else ( 7.787 * y + 16 / 116 )\r\n\r\n refU = ( 4 * Color.XYZ.D65.x ) / ( Color.XYZ.D65.x + ( 15 * Color.XYZ.D65.y ) + ( 3 * Color.XYZ.D65.z ) )\r\n refV = ( 9 * Color.XYZ.D65.y ) / ( Color.XYZ.D65.x + ( 15 * Color.XYZ.D65.y ) + ( 3 * Color.XYZ.D65.z ) )\r\n\r\n L = ( 116 * y ) - 16\r\n return [\r\n L\r\n 13 * L * ( u - refU )\r\n 13 * L * ( v - refV )\r\n ]\r\n\r\n # ## Static function `Color.LUVtoXYZ` to convert LUV to XYZ.\r\n # @param `L, u, v` lightness (L) is from 0 to 100, u is from -134 to 220, and v is from -140 o 122\r\n # @return an array of [x, y, z] where each value is from 0 to 100\r\n @LUVtoXYZ : (L, u, v) ->\r\n y = ( L + 16 ) / 116\r\n cubeY = y*y*y\r\n y = if ( cubeY > 0.008856 ) then cubeY else ( y - 16 / 116 ) / 7.787\r\n\r\n refU = ( 4 * Color.XYZ.D65.x ) / ( Color.XYZ.D65.x + ( 15 * Color.XYZ.D65.y ) + ( 3 * Color.XYZ.D65.z ) )\r\n refV = ( 9 * Color.XYZ.D65.y ) / ( Color.XYZ.D65.x + ( 15 * Color.XYZ.D65.y ) + ( 3 * Color.XYZ.D65.z ) )\r\n\r\n u = u / ( 13 * L ) + refU\r\n v = v / ( 13 * L ) + refV\r\n\r\n y = y*100\r\n x = -1 * (9 * y * u) / ( (u - 4) * v - u * v )\r\n return [ x, y, ( 9 * y - (15 * v * y) - (v * x) ) / (3 * v ) ]\r\n\r\n\r\n # ## Static function `Color.LABtoLCH` transforms LAB to Cylindrical LCH\r\n # @param `L, a, b` lightness (L) is from 0 to 100, a and b component values are from -128 to 127\r\n # @return an array of [l, c, h] where lightness (l) and chroma (c) is from 0 to 100, and hue (h) is from 0 to 360\r\n @LABtoLCH : (L, a, b) ->\r\n h = Math.atan2( b, a ) # Quadrant by signs\r\n h = if ( h > 0 ) then (180 * h / Math.PI) else 360 - ( 180 * Math.abs( h ) / Math.PI )\r\n return [L, Math.sqrt( a*a + b*b ), h]\r\n\r\n\r\n # ## Static function `Color.LCHtoLAB` transforms Cylindrical LCH to LAB\r\n # @param `L, c, h` lightness (L) and chroma (c) is from 0 to 100, and hue (h) is from 0 to 360\r\n # @return an array of [l, a, b] where lightness (L) is from 0 to 100, a and b values are from -128 to 127\r\n @LCHtoLAB : (L, c, h) ->\r\n radH = Math.PI * h / 180\r\n return [\r\n L\r\n Math.cos( radH ) * c\r\n Math.sin( radH ) * c\r\n ]\r\n\r\n # ## Static function `Color.LUVtoLCH` to convert LUV to LCH.\r\n # @param `L, u, v` lightness (L) is from 0 to 100, u is from -134 to 220, and v is from -140 o 122\r\n # @return an array of [l, c, h] where lightness (l) and chroma (c) is from 0 to 100, and hue (h) is from 0 to 360\r\n @LUVtoLCH : (L, u, v) -> LABtoLCH( L, u, v )\r\n\r\n # ## Static function `Color.LCHtoLUV` transforms Cylindrical LCH to LUV\r\n # @param `L, c, h` lightness (L) and chroma (c) is from 0 to 100, and hue (h) is from 0 to 360\r\n # @return an array of [l, u, v] where lightness is from 0 to 100, u is from -134 to 220, and v is from -140 o 122\r\n @LCHtoLUV : (L, c, h) -> LCHtoLAB( L, c, h )\r\n\r\n\r\n# namespace\r\nthis.Color = Color\n# ### Imagine this shape: find a point in space, and draw a curve around it so that the distance between the point you picked and any points on that curve is the same. So by remembering how a circle can be constructed, and by considering PI not as a number but as a ratio, we can start to recognize all the expressive potentials of a circle.\r\n\r\nclass Circle extends Vector\r\n\r\n # ## Create a new Circle. A Circle is a Vector which defines its center position, with a `radius` property to define its radius.\r\n # @param `args` Similar to Point constructor, use comma-separated values, an array, or a Point object as parameters to specify the center of circle. Optionally include a 4th parameter to set the radius directly, or use `setRadius()` afterwards.\r\n # @eg `new Circle()` `new Circle(1,2,3)` `new Circle(1,2,3,100)`\r\n # @return a new Circle object\r\n constructor: () ->\r\n super\r\n\r\n # ## the radius property\r\n @radius = if arguments[3]? then arguments[3] else 0 # radius as 4th argument\r\n\r\n # ## set radius of the circle\r\n # @param `r` radius value\r\n # @return this Circle\r\n setRadius: ( r ) ->\r\n @radius = r\r\n return @\r\n\r\n\r\n # ## Check if a point is on this Circle on xy axis.\r\n # @param `args` comma-separated values, or an array, or a Point object\r\n # @eg `circle.intersectPoint(1,2,3)` `circle.intersectPoint(pt)`\r\n # @demo circle.intersectPoint\r\n # @return a boolean value to indicate if there is an intersection\r\n intersectPoint: (args) ->\r\n item = new Vector( Point.get(arguments) )\r\n d = item.$subtract( @ )\r\n return (d.x * d.x + d.y * d.y < @radius * @radius )\r\n\r\n\r\n # ## Check intersections between this Circle and an infinite Line on xy axis. Based on [this algorithm](http://stackoverflow.com/questions/13053061/circle-line-intersection-points).\r\n # @param `path` a Pair or Line object to specify an infinite line\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @demo circle.intersectPath\r\n # @returns an Array of intersection points (zero, one, or two points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectPath: ( path, get_pts=true ) ->\r\n if not path instanceof Pair then return false\r\n\r\n d = path.direction()\r\n f = @.$subtract( path )\r\n\r\n a = d.dot(d, Const.xy)\r\n b = f.dot(d, Const.xy)\r\n c = f.dot(f, Const.xy) - ( @radius * @radius )\r\n p = b / a\r\n q = c / a\r\n disc = p * p - q # discriminant\r\n\r\n if disc < 0\r\n return (if get_pts then [] else false)\r\n else\r\n if !get_pts then return true\r\n\r\n discSqrt = Math.sqrt( disc )\r\n t1 = -p + discSqrt\r\n t2 = -p - discSqrt\r\n\r\n p1 = new Point( path.x - d.x * t1, path.y - d.y * t1 )\r\n p2 = new Point( path.x - d.x * t2, path.y - d.y * t2 )\r\n\r\n return if disc == 0 then [p1] else [p1, p2]\r\n\r\n\r\n# a = d.x * d.x + d.y * d.y\r\n# b = d.x * f.x + d.y * f.y\r\n# c = ( f.x * f.x + f.y * f.y ) - ( @radius * @radius )\r\n# p = b / a\r\n# q = c / a\r\n# disc = p * p - q\r\n#\r\n# if disc < 0\r\n# return []\r\n# else\r\n# discSqrt = Math.sqrt( disc )\r\n# t1 = -p + discSqrt\r\n# t2 = -p - discSqrt\r\n#\r\n# p1 = new Point( ray.x - d.x * t1, ray.y - d.y * t1 )\r\n# p2 = new Point( ray.x - d.x * t2, ray.y - d.y * t2 )\r\n#\r\n# return if disc == 0 then [p1] else [p1, p2]\r\n\r\n\r\n # ## Check intersections between this Circle and a Line segment on xy axis.\r\n # @param `line` a Pair or Line object to specify a line segment\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero, one, or two points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectLine: ( line, get_pts=true ) ->\r\n\r\n # check ray\r\n pts = @intersectPath( line )\r\n if pts and pts.length > 0\r\n\r\n # check intersected point is within line bounding box\r\n pi = []\r\n bounds = line.bounds()\r\n for p in pts\r\n if Rectangle.contain( p, bounds, bounds.p1 )\r\n if !get_pts then return true\r\n pi.push( p )\r\n\r\n return (if get_pts then pi else (pi.length>0) )\r\n else\r\n return (if get_pts then [] else false)\r\n\r\n\r\n # ## Check if this cirlce intersects with a set of lines ( useful for polygon or polyline such as `rectangle.sides()` ) on xy axis.\r\n # @param `lines` an array of Line\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @eg `circle.intersectLines( rect.sides() )` `circle.intersectLines( pointset.sides(), true )`\r\n # @returns an Array of intersection points, or a boolean value. (Based on `get_pts` parameter)\r\n intersectLines: (lines, get_pts=true) ->\r\n return Line.intersectLines( @, lines, get_pts )\r\n\r\n\r\n # ## Check if this circle intersects with another circle\r\n # @param `circle` another Circle\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @demo circle.intersectCircle\r\n # @returns an Array of intersection points (zero or two points) or a boolean value, based on `get_pts` parameter.\r\n intersectCircle: (circle, get_pts=true) ->\r\n dv = circle.$subtract( @ )\r\n dr2 = dv.magnitude(false)\r\n dr = Math.sqrt( dr2 )\r\n\r\n ca_r2 = @radius * @radius\r\n cb_r2 = circle.radius * circle.radius\r\n\r\n if dr > @radius + circle.radius # not intersected\r\n return (if get_pts then [] else false)\r\n\r\n else if dr < Math.abs( @radius - circle.radius ) # completely enclosing the other, no intersecting points\r\n return (if get_pts then [ new Vector(this), new Vector(circle) ] else true)\r\n\r\n else # has two intersection points\r\n if !get_pts then return true\r\n\r\n a = (ca_r2 - cb_r2 + dr2) / (2*dr)\r\n h = Math.sqrt( ca_r2 - a*a )\r\n p = dv.$multiply(a/dr).add(@)\r\n\r\n return [\r\n new Vector( (p.x + h*dv.y/dr), (p.y - h*dv.x/dr) )\r\n new Vector( (p.x - h*dv.y/dr), (p.y + h*dv.x/dr) )\r\n ]\r\n\r\n\r\n # ## Check if this cirlce intersect with another element on xy axis\r\n # @param `item` any object that is based on Point. (Vector, Line, Rectangle, Circle, etc)\r\n # @eg `circle.hasIntersect( another_circle )` `circle.hasIntersect(line)` `circle.hasIntersect(rect)`\r\n # @returns an Array of intersection points or a boolean value. (Based on `get_pts` parameter)\r\n hasIntersect: (item, get_pts=false) ->\r\n\r\n # circle intersection check\r\n if item instanceof Circle\r\n return @intersectCircle( item, get_pts )\r\n\r\n # polygon intersection check (TODO any better algorithm?)\r\n else if item instanceof Rectangle or item instanceof PointSet or item instanceof Triangle\r\n return @intersectLines(item.sides(), get_pts)\r\n\r\n # line intersection check\r\n else if item instanceof Pair\r\n ins = @intersectLine(item)\r\n return if !get_pts then (ins.length > 0) else ins\r\n\r\n # point intersection check\r\n else if item instanceof Point\r\n d = item.$subtract( @ )\r\n return (d.x * d.x + d.y * d.y < @radius * @radius)\r\n\r\n else\r\n return if get_pts then [] else false\r\n\r\n\r\n\r\n # ## Describe this point as a text string\r\n # @return \"Vector x, y, z\" text\r\n toString: () -> \"Circle of #{@radius} radius at center #{ @x }, #{ @y }, #{ @z }\"\r\n\r\n# namespace\r\nthis.Circle = Circle\n# ### If a point represents a static concept in space, then a particle resembles an energized thought. It dashes, brakes, and swirls about. By emulating how forces integrate and energies exchange, we may examine dynamic systems and continuous movements from a new perspective.\r\nclass Particle extends Circle\r\n\r\n # derivative of momentum is force (F=dp/dt)\r\n # derivative of position is velocity (v=dx/dt)\r\n # derivative of velocity is acceleration (a=dv/dt)\r\n # Force = mass * acceleration (F=ma)\r\n # Momentum = mass * velocity (p=mv)\r\n\r\n # ## Create a new Particle. Like a Circle, specify its center position with a `radius` property to define its radius.\r\n # @param `args` Similar to Point constructor, use comma-separated values, an array, or a Point object as parameters to specify the center of circle. Optionally include a 4th parameter to set the radius directly, or use `setRadius()` afterwards.\r\n # @eg `new Particle()` `new Particle(1,2,3)` `new Particle(1,2,3,100)`\r\n # @return a new Circle object\r\n constructor: () ->\r\n super\r\n\r\n # ## A property to store this particle's id\r\n @id = 0\r\n\r\n # ## A property to track this particle's states. An object with properties `.age` and `.maxAge` and a boolean proeprty `.active`\r\n @life = {age: 0, maxAge: 0, active: true, complete: false}\r\n\r\n # ## A property to track this particle's momentum as a Vector\r\n @momentum = new Vector()\r\n\r\n # ## A property to track this particle's velocity as a Vector\r\n @velocity = new Vector()\r\n\r\n # ## A property to specify this particle's mass value. Default is 2.\r\n @mass = 2\r\n\r\n # ## A property to specify this particle's friction. Defaulti is 0.\r\n @friction = 0\r\n\r\n # A property to specify how many frames per milliseconds, for timeStep integration. Default is 20 ms (1000/48 (48 fps) = ~20ms).\r\n @frame_ms = 20\r\n\r\n\r\n # ## Play the particle for one time-step.\r\n # @param `time` current time in milliseconds\r\n # @param `timeDiff` time difference between last and current step, ie, the time of a frame.\r\n # @demo particle.play\r\n play: ( time, timeDiff ) ->\r\n t = 0\r\n while timeDiff > 0\r\n dt = Math.min( timeDiff, @frame_ms )\r\n @integrate(t/1000, dt/1000 ); # unit is seconds\r\n timeDiff -= dt\r\n t += dt\r\n @life.age++\r\n\r\n\r\n\r\n # ## Integrate function using Runge-Kutta-4. Override this function to specify other integrator, such as Euler or Verlet.\r\n # @param `t` current time in *seconds*\r\n # @param `dt` time difference between last and current step, in *seconds*\r\n integrate: (t, dt) ->\r\n @integrateRK4(t, dt)\r\n\r\n\r\n # ## Calculate all forces acting on this particle. This is called by integrate function. Override this function to implement specific force calculations.\r\n # @param `state` a object with `position` and `momentum` Vectors\r\n # @param `t` curent time in seconds\r\n # @eg `p.forces( {position: new Vector(), momentum: new Vector()}, t+dt )`\r\n # @return an object with `force` property\r\n forces: (state, t) ->\r\n return {force: new Vector()}\r\n\r\n # ## Apply an impulse to this particle's `momentum` and `velocity` properties\r\n # @param `force_dt` a force Vector\r\n impulse: ( force_dt ) ->\r\n @momentum.add( force_dt )\r\n @velocity = @momentum.$divide( @mass )\r\n\r\n\r\n # For RK4 integration: update position, momentum and velocity. calculate force.\r\n _evaluate : (t, dt=0, derivative=false) ->\r\n\r\n # integrate at time dt\r\n if dt != 0 and derivative\r\n\r\n state = {\r\n position: @$add( derivative.velocity.$multiply( dt ) )\r\n momentum: @momentum.$add( derivative.force.$multiply( dt ) )\r\n }\r\n\r\n else\r\n state = { position: new Vector(@), momentum: new Vector(@momentum) }\r\n\r\n # recalculate velocity\r\n state.velocity = state.momentum.$divide( @mass )\r\n\r\n # calculate force\r\n f = @forces( state, t+dt )\r\n\r\n return { velocity: state.velocity, force: f.force }\r\n\r\n\r\n # ## Runge-Kutta-4 integration\r\n # @param `t` current time in *seconds*\r\n # @param `dt` time difference between last and current step, in *seconds*\r\n integrateRK4: (t, dt) ->\r\n\r\n # rk4 calculations (adapted based on the algorithm on gafferongames.com)\r\n _map = (m1, m2, m3, m4) ->\r\n v = new Vector(\r\n (m1.x + 2*(m2.x+m3.x) + m4.x) / 6\r\n (m1.y + 2*(m2.y+m3.y) + m4.y) / 6\r\n (m1.z + 2*(m2.z+m3.z) + m4.z) / 6\r\n )\r\n\r\n return v\r\n\r\n a = @_evaluate(t, 0)\r\n b = @_evaluate(t, dt*0.5, a)\r\n c = @_evaluate(t, dt*0.5, b)\r\n d = @_evaluate(t, dt, c)\r\n\r\n @add( _map( a.velocity, b.velocity, c.velocity, d.velocity ) )\r\n @momentum.add( _map( a.force, b.force, c.force, d.force ) )\r\n\r\n\r\n # ## Simple Euler integration using momentum\r\n # @param `t` current time in *seconds*\r\n # @param `dt` time difference between last and current step, in *seconds*\r\n integrateEuler: (t, dt) ->\r\n\r\n f = @forces( { position: new Vector(@), momentum: new Vector(@momentum) }, t+dt )\r\n @add( @velocity )\r\n @momentum.add( f.force )\r\n @velocity = @momentum.$divide( @mass )\r\n\r\n\r\n # ## check Collision with a line segment (wall), and calculate the resulting velocity and momentum\r\n # @param `wall` a Line object to check collision against\r\n # @param `precise` a boolean value to specify a precise collision calculation. If `true`, then the particle position will be recalculated to match the exact collision position with the line. Default is true.\r\n # @demo particle.collideLine2d\r\n # @return a boolean value to indicate if collision occurs\r\n collideLine2d: ( wall, precise=true ) ->\r\n\r\n # this can be optimized by calculating the normalized velocity and wall vectors (used in various Line functions)\r\n\r\n curr_pos = new Vector(@)\r\n curr_dist = Math.abs( wall.getDistanceFromPoint( curr_pos ) )\r\n collided = Math.abs(curr_dist) < @radius\r\n\r\n # if precision is on, find the next position and check if the next position completely crossed the wall (when speed is very fast)\r\n if precise\r\n next_pos = @$add( @velocity )\r\n next_dist = Math.abs( wall.getDistanceFromPoint( next_pos ) )\r\n crossed = wall.intersectLine( new Line( curr_pos ).to( next_pos ) )\r\n\r\n if crossed\r\n next_pos = crossed.$add( @velocity.$normalize().$multiply(-@radius/2) )\r\n next_dist = Math.abs( wall.getDistanceFromPoint( next_pos ) )\r\n collided = true\r\n\r\n if collided\r\n\r\n pt_on_wall = wall.getPerpendicularFromPoint( curr_pos ) # normal point on wall\r\n wall_path = wall.$subtract( wall.p1 )\r\n\r\n collideEndPt = false\r\n\r\n # intersecting with wall segment\r\n if !wall.withinBounds( pt_on_wall, Const.xy )\r\n\r\n # check if colliding with end pt\r\n if @intersectPoint( wall )\r\n collideEndPt = true\r\n end_path = @$subtract( wall )\r\n\r\n if @intersectPoint( wall.p1 )\r\n collideEndPt = true\r\n end_path = @$subtract( wall.p1 )\r\n\r\n if collideEndPt\r\n wall_path = new Vector( -end_path.y, end_path.x ) # treating it like colliding with zero-radius point\r\n\r\n else\r\n return false\r\n\r\n # find project and resulting velocity\r\n dot = wall_path.dot( @velocity )\r\n proj = wall_path.$multiply( (dot / wall_path.dot( wall_path )) )\r\n tangent = proj.$subtract( @velocity )\r\n\r\n @velocity = proj.$add(tangent)\r\n @momentum = @velocity.$multiply( @mass )\r\n\r\n\r\n # Recalculate last position before collision if precision needed\r\n if precise and !collideEndPt\r\n\r\n # normal on wall to curr_pos\r\n perpend = new Line( pt_on_wall ).to( curr_pos )\r\n\r\n # line segment of two points on wall\r\n prev_pt_on_wall = wall.getPerpendicularFromPoint( next_pos )\r\n path = new Line( pt_on_wall ).to( prev_pt_on_wall )\r\n pvec = path.direction()\r\n\r\n # interpolate the point where the collision occurs\r\n r = (@radius-curr_dist) / (next_dist-curr_dist)\r\n pt = pvec.$multiply( r ).$add( path )\r\n pt2 = pt.$add( perpend.direction().$normalize().$multiply( @radius ) )\r\n\r\n # set new position\r\n @set( pt2.$add( @velocity.$normalize() ) )\r\n\r\n return collided\r\n\r\n\r\n # ## Check if a particle hits the boundaries within a box, and calculate the resulting velocity and momentum. Precise collision positioning are not implemented.\r\n # @param `bound` a Rectangle object to specify a bounding box`\r\n # @return a boolean value to indicate if collision occurs\r\n collideWithinBounds: ( bound ) ->\r\n\r\n if @x - @radius < bound.x or @x + @radius > bound.p1.x\r\n\r\n if @x - @radius < bound.x # fast but not totally accurate. Would be better to check the trajectory like in collideLine2D.\r\n @x = bound.x + @radius;\r\n else if @x + @radius > bound.p1.x\r\n @x = bound.p1.x - @radius;\r\n\r\n @velocity.x *= -1\r\n @momentum = @velocity.$multiply( @mass )\r\n return true\r\n\r\n else if @y - @radius < bound.y or @y + @radius > bound.p1.y\r\n if @y - @radius < bound.y\r\n @y = bound.y + @radius;\r\n else if @y + @radius > bound.p1.y\r\n @y = bound.p1.y - @radius;\r\n\r\n @velocity.y *= -1\r\n @momentum = @velocity.$multiply( @mass )\r\n return true\r\n\r\n return false\r\n\r\n\r\n # ## Check 2D collision with another particle, and calculate the resulting velocity and momentum. Precise collision positioning are not implemented.\r\n # @param `pb` another Particle\r\n # @return an array of 2 Vectors, representing this and the other particle's resulting velocity. Or `false` if collision doesn't occur.\r\n collideParticle2d: ( pb ) ->\r\n\r\n if @hasIntersect( pb )\r\n return Particle.collideParticle2d( @, pb, true )\r\n\r\n else\r\n return false\r\n\r\n\r\n # ## Static function to calculate velocity and momentum after 2D collision, without precise coliision positioning. Remember to check intersection/collision before calling this.\r\n # @param `pa, pb` two Particles\r\n # @param `update` a boolean value to update the velocity and momentum of the two particle directly if set to `true`. Default is true.\r\n # @return an array of 2 Vectors, representing this and the other particle's resulting velocity.\r\n @collideParticle2d: (pa, pb, update=true, checkOverlap=true) ->\r\n\r\n # normal and tangent vector of 2 particles on contact\r\n normal = pa.$subtract(pb).normalize()\r\n tangent = new Vector( -normal.y, normal.x )\r\n\r\n # dot products\r\n dot1n = normal.dot( pa.velocity )\r\n dot1t = tangent.dot( pa.velocity )\r\n dot2n = normal.dot( pb.velocity )\r\n dot2t = tangent.dot( pb.velocity )\r\n\r\n # final velocity (one dimension)\r\n d1 = ( dot1n * (pa.mass - pb.mass) + 2 * pb.mass * dot2n ) / (pa.mass + pb.mass)\r\n d2 = ( dot2n * (pb.mass - pa.mass) + 2 * pa.mass * dot1n ) / (pa.mass + pb.mass)\r\n\r\n # final veloctiy (vector)\r\n v1n = normal.$multiply( d1 )\r\n v1t = tangent.$multiply( dot1t )\r\n v2n = normal.$multiply( d2 )\r\n v2t = tangent.$multiply( dot2t )\r\n\r\n pav = v1n.$add( v1t )\r\n pbv = v2n.$add( v2t )\r\n\r\n # check if two particles are overlapping, if so, push them apart\r\n if checkOverlap\r\n mag = pa.magnitude( pb );\r\n if mag < pa.radius + pb.radius\r\n dir= pa.$subtract( pb ).normalize()\r\n magDiff = Math.abs(mag - pa.radius - pb.radius) / 1.98;\r\n pa.add( dir.multiply( magDiff ) );\r\n pb.add( dir.multiply( -magDiff ) );\r\n\r\n if update\r\n pa.velocity = pav\r\n pb.velocity = pbv\r\n\r\n pa.momentum = pa.velocity.$multiply( pa.mass )\r\n pb.momentum = pb.velocity.$multiply( pb.mass )\r\n\r\n return [pav, pbv]\r\n\r\n\r\n # ## Static function to calculate gravitational forces between 2 particles. This can be used as an implementation of `forces()` function\r\n # @param `state` a object with `position` and `momentum` Vectors\r\n # @param `t` curent time in seconds\r\n # @param `pa, pb` two Particles\r\n # @param `g` optional gravitational constant. Defaults to 0.0067.\r\n # @return an object with `force` property\r\n @force_gravitation: (state, t, pa, pb, g=0.0067) ->\r\n meterToPixel = 30\r\n\r\n d = pb.$subtract( state.position )\r\n mag = d.magnitude() / meterToPixel\r\n force = if mag == 0 then 0 else t * g * pa.mass * pb.mass / (mag*mag)\r\n d.normalize().multiply( force )\r\n\r\n return {force: d}\r\n\r\n\r\n # ## Static function of Runge-Kutta-4 integrator (adopted from gafferongames.com)\r\n # @param `c, d` the derivative of c is d. If c is position, then d is velocity.\r\n # @param `func` acceleration function(c, d, dt, t)\r\n # @param `dt` change in time\r\n # @param `t` current time\r\n # @return an object with `{c, d}` properties where the derivative of c is d.\r\n @RK4: (c, d, func, dt, t) ->\r\n\r\n c1 = c\r\n d1= d\r\n a1 = func(c1, d1, 0, t)\r\n\r\n c2 = c + 0.5*d1*dt\r\n d2 = d + 0.5*a1*dt\r\n a2 = func(c2, d2, dt/2, t)\r\n\r\n c3 = c + 0.5*d2*dt\r\n d3 = d + 0.5*a2*dt\r\n a3 = func(c3, d3, dt/2, t)\r\n\r\n c4 = c + d3*dt\r\n d4 = d + a3*dt\r\n\r\n dc = (c1 + 2*(c2+c3) + c4) / 6\r\n dd = (d1 + 2*(d2+d3) + d4) / 6\r\n\r\n return { c: c + dc*dt, d: d + dd*dt }\r\n\r\n# namespace\r\nthis.Particle = Particle\n# ### A particle system keeps track of particles, and regulate them with rules specific to a system. It can also hold constant values from gravitational to cosmic, and specify whether a god may play dice here.\r\nclass ParticleSystem\r\n\r\n # ## Create a ParticleSystem to track a set of particles\r\n constructor : () ->\r\n\r\n # ## a property to store particles in this system as an Array\r\n @count = 0\r\n @particles = []\r\n\r\n # ## a property to track time in milliseconds\r\n @time = 0\r\n\r\n # @animateID = -1\r\n\r\n\r\n # ## add a particle to the system\r\n # @param `particle` a Particle\r\n # @return this system\r\n add : ( particle ) ->\r\n particle.id = @count++\r\n @particles.push( particle )\r\n return @\r\n\r\n\r\n # ## remove a particle which has a `particle.life` property. This marks the `particle.life.complete` as `true` for removal in next cycle.\r\n # @param `particle` a Particle\r\n # @return this system\r\n remove: (particle) ->\r\n if particle and particle.life then particle.life.complete = true\r\n return @\r\n\r\n\r\n # ## animate callback function which is called by` Space.play()`. Override this callback function to specify other animation loops\r\n # @param `time, frame, ctx` parameters for current time, fps, and rendering context, which will be passed by `Space` in callback\r\n animate : ( time, frame, ctx ) ->\r\n @time++\r\n\r\n _remove = []; # to be removed\r\n\r\n for p, i in @particles\r\n\r\n # if life is complete, mark for removal\r\n if p.life.complete\r\n _remove.push( i )\r\n\r\n # if active, animate it\r\n else if p.life.active\r\n p.animate( time, frame, ctx )\r\n\r\n # remove completed particles\r\n if _remove.length > 0\r\n for index in _remove\r\n @particles.splice(index, 1)\r\n\r\n\r\n\r\n# namespace\r\nthis.ParticleSystem = ParticleSystem\r\n\r\n\n# ### A pair of vectors is not merely two vectors, for relationships bring forth meanings. Two vectors can be compared, joined, and interpreted in relation to each other. Together they may connect a line, mark an area, track a change.\r\nclass Pair extends Vector\r\n\r\n # ## Create a new Pair. A Pair is a Vector which defines its anchor point, and connected to another Vector through the `to()` function.\r\n # @param `args` Similar to Point constructor, use comma-separated values, an array, or an object as parameters to specify the first point. As a shortcut to `to()`, you can also pass 4 or 6 values to set both anchor and `p1` points directly as a 2d or 3d vector.\r\n # @eg `new Pair()` `new Pair(1,2,3)` `new Pair([2,4])` `new Pair({x:3, y:6, z:9}).to(1,2,3)`, `new Pair(10,10, 20,20)`\r\n # @return a new Pair object\r\n constructor: () ->\r\n super\r\n\r\n # ## A vector object which is other point in this pair.\r\n @p1 = new Vector( @x, @y, @z )\r\n\r\n if arguments.length == 4\r\n @z = 0\r\n @p1.set( arguments[2], arguments[3] )\r\n else if arguments.length == 6\r\n @p1.set( arguments[3], arguments[4], arguments[5] )\r\n\r\n\r\n # ## connect the other point\r\n # @param `args` comma-separated values, or an array, or an object\r\n # @eg `pair.to(1,2,3)` `new Pair(1,2).to(3,4)`\r\n # @return this Pair\r\n to: () ->\r\n @p1 = new Vector( Point.get(arguments) )\r\n return @\r\n\r\n\r\n # ## Get a point from the set of points based on its index position\r\n # @param `index` index position\r\n # @return a point in the pair\r\n getAt: (index) ->\r\n if (index==1 or index==\"p1\") then return @p1;\r\n return @;\r\n\r\n\r\n # ## Same as `getAt()` but return as a new Vector\r\n $getAt: (index) -> return new Vector( @getAt(index) );\r\n\r\n\r\n # ## Update p1's new position by recalculating it as a relative position to the anchor point\r\n # @return this Pair\r\n relative: () ->\r\n @p1.add( @ )\r\n return @\r\n\r\n # ## Return a new vector of p1's new position, by recalculating it as a relative position to the anchor point\r\n # @return a new Vector\r\n $relative: () -> @$add( @p1 )\r\n\r\n\r\n # ## Get a new pair that's the bounding box of this pair. This is the same as calculating its top-left (min) and bottom-right (max) points.\r\n # @return a new Pair\r\n bounds: () ->\r\n return new Pair( @$min(@p1) ).to( @$max(@p1) )\r\n\r\n # ## Check if a point is within the bounds of this pair\r\n # @param `pt` a Point object to check.\r\n # @param `axis` optional axis id such as Const.xy.\r\n # @eg `pair.withinBounds( point )`, `pair.withinBounds( point, Const.yz )`\r\n # @demo pair.withinBounds\r\n # @return a boolean value where `true` means the point is within bounds.\r\n withinBounds: ( pt, axis ) ->\r\n if axis\r\n a = @get2D( axis )\r\n b = @p1.get2D( axis )\r\n\r\n # simplify checking for horizontal and vertical lines, and avoid rounding errors\r\n if a.x == b.x\r\n return pt.y >= Math.min(a.y, b.y) and pt.y <= Math.max(a.y, b.y)\r\n else if a.y == b.y\r\n return pt.x >= Math.min(a.x, b.x) and pt.x <= Math.max(a.x, b.x)\r\n\r\n # bounding box check\r\n else\r\n return ( pt.x >= Math.min(a.x, b.x) and pt.y >= Math.min(a.y, b.y) and pt.x <= Math.max(a.x, b.x) and pt.y <= Math.max(a.y, b.y) )\r\n else\r\n return ( pt.x >= Math.min( @x, @p1.x) and pt.y >= Math.min(@y, @p1.y) and pt.z >= Math.min(@z, @p1.z) and pt.x <= Math.max(@x, @p1.x) and pt.y <= Math.max(@y, @p1.y) and pt.z <= Math.max(@z, @p1.z) )\r\n\r\n # ## Interpolate to find a point which lies somewhere on a straight path between the two points of this pair\r\n # @param `t` a value between 0 to 1.\r\n # @param `relative` an optional boolean value. If `true`, then `this.p1` will be treated as relative to the achor point. Default is `false`.\r\n # @eg `pair.interpolate(0.4)` `pair.interpolate(0.1, true)`\r\n # @demo pair.interpolate\r\n # @return the interpolated point as Vector\r\n interpolate: ( t, relative=false ) ->\r\n p2 = if relative then @$relative() else @p1\r\n\r\n return new Vector(\r\n (1-t) * @x + t * p2.x\r\n (1-t) * @y + t * p2.y\r\n (1-t) * @z + t * p2.z\r\n )\r\n\r\n # ## A convenient method to get the midpoint of this pair of points. Same as @interpolate( 0.5 )\r\n # @return the middle point as Vector\r\n midpoint: () -> @interpolate( 0.5 )\r\n\r\n # ## Get a vector which points to the same direction as this pair, but starts at origin (0,0)\r\n # @param `reverse` optional parameter to reverse the direction if set to `true`. Default is `false`.\r\n # @eg `pair.direction()`, `pair.direction(false)`, `pair.direction().normalize()`\r\n # @return the directional vector\r\n direction: ( reverse ) ->\r\n return if reverse then @.$subtract( @p1 ) else @p1.$subtract( @ )\r\n\r\n\r\n # ## Set or get width and height of this pair\r\n # @param `args` Optional parameter to set the size of this Pair. Can be comma-separated values, or as an array, or a Point object.\r\n # @eg `pair.size()`, `pair.size(100, 50)`\r\n # @return When setting a new size, returns self. When getting size, returns a Vector whose x is the width and y is the height.\r\n size: () ->\r\n if arguments.length > 0\r\n @p1 = @.$add( Point.get(arguments) )\r\n return @\r\n else\r\n return @p1.$subtract( @ ).abs()\r\n\r\n # ## Find distance of this pair from anchor to p1\r\n # @param: `sqrt` optional boolean value to get distance-squared value if set to `false`. Default is true.\r\n # @return distance value\r\n length: ( sqrt = true ) ->\r\n dz = @z - @p1.z\r\n dy = @y - @p1.y;\r\n dx = @x - @p1.x;\r\n d = dx*dx + dy*dy + dz*dz\r\n return if sqrt then Math.sqrt( d ) else d\r\n\r\n\r\n # ## Check if a point lies on the left or right side of this pair's *ray*, and if the 3 points are collinear\r\n # @param `point` a Point object to check against this pair.\r\n # @demo pair.collinear\r\n # @return a value where 0 means collinear, poitive value means the point lies on left, and negative value means it's on right\r\n collinear: (point) ->\r\n return (@p1.x - @x) * (point.y - @y) - (point.x - @x) * (@p1.y - @y)\r\n\r\n # ## Recalculate the origin and vec so that origin is at top-left and vec is at bottom-right\r\n # @return this Pair\r\n resetBounds: () ->\r\n temp = @$min( @p1 )\r\n @p1.set( @$max( @p1 ) )\r\n @set( temp )\r\n return @\r\n\r\n # ## override equal() from parent class\r\n equal: (epsilon=false) ->\r\n if arguments[0] instanceof Pair\r\n return super( arguments[0] ) and @p1.equal( arguments[0].p1 )\r\n else\r\n super\r\n\r\n # ## Override clone() from parent class\r\n clone: () ->\r\n p = new Pair( @ )\r\n p.to( @p1.clone() )\r\n return p\r\n\r\n # ## Override floor() from parent class\r\n floor: () ->\r\n super\r\n @p1.floor()\r\n\r\n # ## Describe this Pair as a text string\r\n # @return \"Pair of vectors from ... to ...\" text\r\n toString: () -> \"Pair of vectors from (#{ @x }, #{ @y }, #{ @z }) to (#{ @p1.x }, #{ @p1.y }, #{ @p1.z })\"\r\n\r\n # ## Override toArray() include `p1` in the array.\r\n toArray: () -> [@, @p1]\r\n\r\n\r\n# namespace\r\nthis.Pair = Pair\n# ### There is a shortest path that connects a pair of points. Trace that unique path, with pencil or thread or mind, and you will make a straight line. A line embodies the simplest movement or change. It is a point set in motion, moving to meet another point and leaving a trail behind.\r\nclass Line extends Pair\r\n\r\n # ## Create a new Line. A Line is a Pair defined by two vectors. It can be treated as an infinite line, or as a line segment with two end points.\r\n # @param `args` Similar to Pair constructor, use comma-separated values, an array, or an object as parameters to specify the first point. As a shortcut to `to()`, you can also pass 4 or 6 values to set both anchor and `p1` points directly as a 2d or 3d vector.\r\n # @eg `new Line()` `new Line(1,2,3)` `new Line([2,4])` `new Line({x:3, y:6, z:9}).to(1,2,3)`\r\n # @return a new Pair object\r\n constructor: () ->\r\n super\r\n\r\n\r\n # ## a static function `Line.slope` to find the slope between two points\r\n # @param `a` a Point\r\n # @param `b` another Point\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @eg `Line.slope(pt1, pt2)`, `Line.slope(pt1, pt2, Const.yz)`\r\n # @return slope value, or false if it divides by 0 (a vertical line)\r\n @slope: ( a, b, axis=Const.xy ) ->\r\n p1 = a.get2D( axis )\r\n p2 = b.get2D( axis )\r\n return if (p2.x - p1.x is 0) then false else (p2.y - p1.y) / (p2.x - p1.x)\r\n\r\n\r\n # ## a static function `Line.intercept` to get x and y intercept\r\n # @param `a` a Point\r\n # @param `b` another Point\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @eg `Line.intercept(pt1, pt2)`, `Line.intercept(pt1, pt2, Const.yz)`\r\n # return: an Object with {xi, yi, slope} properties, or false if it divides by 0 (a vertical line)\r\n @intercept: ( a, b, axis=Const.xy ) ->\r\n p1 = a.get2D( axis )\r\n p2 = b.get2D( axis )\r\n if p2.x - p1.x is 0\r\n return false\r\n else\r\n # y = mx + c\r\n m = ((p2.y - p1.y) / (p2.x - p1.x)) # slope\r\n c = p1.y - m * p1.x\r\n return { slope: m, yi: c, xi: if m==0 then false else -c/m } #[ -c/m, c, m ]\r\n\r\n\r\n # ## a static function `Line.isPerpendicularLine` to check if two lines are perpendicular to each other\r\n # @param `line1` a Line\r\n # @param `line2` another Line\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @eg `Line.isPerpendicularLine(ln1, ln2)`, `Line.isPerpendicularLine(ln1, ln2, Const.yz)`\r\n # return a boolean value where `true` means the two lines are perpendicular\r\n @isPerpendicularLine: (line1, line2, axis=Const.xy) ->\r\n s1 = Line.slope( line1, line1.p1, axis )\r\n s2 = Line.slope( line2, line2.p1, axis )\r\n if s1 is false\r\n return (s2 is 0)\r\n else if s2 is false\r\n return (s1 is 0)\r\n else\r\n return (s1*s2 is -1)\r\n\r\n\r\n # ## Get slope of this line\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @return slope value, or false if it divides by 0 (a vertical line)\r\n slope: ( axis=Const.xy ) -> Line.slope( @, @p1, axis )\r\n\r\n\r\n # ## Get intercepts and slop of this line\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # return: an Object with {xi, yi, slope} properties, or false if it divides by 0 (a vertical line)\r\n intercept: ( axis=Const.xy ) -> Line.intercept( @, @p1, axis )\r\n\r\n\r\n # ## Given an interpolated point on this line, return another line of specific length that is perpendicular to this line.\r\n # @param `t` a value between 0 to 1 to interpolate a point on this line\r\n # @param `len` an optional value to specify a length for the new line. Defaults to 10.\r\n # @param `reverse` a boolean value to reverse the direction of the new line if set to `true`\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @eg `ln.getPerpendicular(0.5)`, `ln.getPerpendicular(0.2, 100, true, Const.yz)`\r\n # @demo line.getPerpendicular\r\n # @return a new Line that's perpendicular to this line\r\n getPerpendicular: ( t, len=10, reverse=false, axis=Const.xy ) ->\r\n pn = @direction().normalize().perpendicular( axis ) # get normal vector\r\n pp = if reverse then pn[1] else pn[0] # from which side of the dividing line\r\n line = new Line( @interpolate( t ) ) # the start-point in the new line\r\n line.to( pp.multiply(len).add( line ) ) # connect the end point\r\n return line\r\n\r\n # ## Find the shortest distance from a point to this line (as infinite line, not line segment)\r\n # @param `pt` a Point\r\n # return the distance, which can be positive or negative value depending on the point's position.\r\n getDistanceFromPoint: ( pt ) ->\r\n path = @$subtract( @p1 )\r\n normal = new Vector( -path.y, path.x ).normalize()\r\n return @$subtract( pt ).dot( normal )\r\n\r\n\r\n # ## Find the perpendicular vector from this line to the point. You can connect the resulting vector with the point's position to draw a perpendicular line\r\n # @param `pt` a Point\r\n # @param `fromProjection` a boolean value defaults to true. If true, the resulting vector is based on this line's position. Otherwise the vector starts from origin (0,0).\r\n # @demo line.getPerpendicularFromPoint\r\n # @return a perpendicular Vector\r\n getPerpendicularFromPoint: ( pt, fromProjection=true ) ->\r\n proj = @p1.$subtract(@).projection( pt.$subtract(@) )\r\n return if !fromProjection then proj else proj.add(@)\r\n\r\n\r\n # ## Get intersection point of this line and another line (as infinite lines, not line segements)\r\n # @param `line` another Line\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @return an intersection point as Vector, or `false` if no intersection, or `null` if two lines are identical\r\n intersectPath: ( line, axis=Const.xy ) ->\r\n\r\n a = @intercept( axis )\r\n b = line.intercept( axis )\r\n\r\n p = @get2D( axis )\r\n ln = line.get2D( axis )\r\n\r\n if a == false\r\n if b == false then return false # no solution\r\n # one of them is vertical line, while the other is not, so they will intersect\r\n y1 = -b.slope * (ln.x - p.x) + ln.y # -slope * p.x + p.y\r\n return if axis == Const.xy then new Vector( p.x, y1 ) else new Vector( p.x, y1 ).get2D( axis, true )\r\n\r\n else\r\n # diff slope, or b slope is vertical line\r\n if b == false\r\n y1 = -a.slope * (p.x - ln.x) + p.y # -slope * p.x + p.y\r\n return new Vector( ln.x, y1 )\r\n\r\n else if b.slope != a.slope\r\n px = (a.slope * p.x - b.slope * ln.x + ln.y - p.y) / (a.slope - b.slope)\r\n py = a.slope * ( px - p.x ) + p.y\r\n if axis == Const.xy\r\n return new Vector( px, py )\r\n else\r\n return new Vector( px, py ).get2D( axis, true ) # flip back to intended axis\r\n\r\n else\r\n if a.yi == b.yi # exactly along the same path\r\n return null\r\n else\r\n return false\r\n\r\n\r\n # ## Get intersection point of this line segement and another line segement (not infintie lines)\r\n # @param `line` another Line\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @demo line.intersectLine\r\n # @return an intersection point as Vector, or `false` if no intersection, or `null` if two lines are identical\r\n intersectLine: (line, axis=Const.xy) ->\r\n # get point from intersectPath()\r\n pt = @intersectPath( line, axis )\r\n\r\n # check line segment intersection\r\n if pt and @withinBounds( pt, axis ) and line.withinBounds( pt, axis )\r\n return pt\r\n else\r\n return if pt == null then null else false\r\n\r\n\r\n # ## A static function `Line.intersectLines` if an element intersects with a list of lines ( useful for polygon or polyline such as `rectangle.sides()` ) on xy axis.\r\n # @param `lines` an array of Line\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @eg `Line.intersectLines( rect, triangle.sides() )` `Line.intersectLines( line, pointset.sides(), true )`\r\n # @returns an Array of intersection points, or a boolean value. (Based on `get_pts` parameter)\r\n @intersectLines: (elem, lines, get_pts=true) ->\r\n if !elem.intersectLine\r\n throw \"No intersectLine function found in \"+ elem.toString()\r\n\r\n pts = []\r\n # check each line\r\n for i, ln of lines\r\n ins = elem.intersectLine(ln, get_pts)\r\n\r\n # store intersection points\r\n if ins\r\n if !get_pts then return true\r\n if ins.length > 0\r\n for p in ins\r\n pts.push( p )\r\n\r\n return if get_pts then pts else false\r\n\r\n\r\n # ## Get intersection point of between two \"grid\" lines. Grid lines are parallel to an axis, such as a horizontal or vertical line on xy plane.\r\n # @param `line` another Line which is parallen to an axis\r\n # @param `path_only` a boolean value to specify whether to check for whole path (`true`) or line segment (`false`). Defaults to `false`.\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @return an intersection point as Vector, or `false` if no intersection\r\n intersectGridLine: (line, path_only=false, axis=Const.xy ) ->\r\n a1 = @get2D( axis )\r\n a2 = @p1.get2D( axis )\r\n\r\n b1 = line.get2D( axis )\r\n b2 = line.p1.get2D( axis )\r\n\r\n if a2.x - a1.x == 0\r\n if b2.y - b1.y == 0 and Util.within( a1.x, b1.x, b2.x )\r\n if path_only or Util.within( b1.y, a1.y, a2.y )\r\n return new Vector( a1.x, b1.y )\r\n\r\n else if a2.y - a1.y == 0\r\n if b2.x - b1.x == 0 and Util.within( a1.y, b1.y, b2.y )\r\n if path_only or Util.within( b1.x, a1.x, a2.x )\r\n return new Vector( b1.x, a1.y )\r\n\r\n else\r\n return false\r\n\r\n\r\n # ## Get a list of evenly distributed points on this line\r\n # @param `num` the number of points to get\r\n # @return an Array of Points\r\n subpoints: (num) -> (@interpolate t/num for t in [0..num] )\r\n\r\n\r\n # ## override clone\r\n clone: (deep) ->\r\n return new Line(@).to(@p1)\r\n\r\n\r\n# namespace\r\nthis.Line = Line\r\n\r\n\r\n\r\n# Old code -- Use Matrix transform functions instead\r\n\r\n# Rotate this line from a hinged point along the line\r\n# param: t is between 0 to 1, radian is the rotation\r\n# see also Matrix.rotateAnchor2D\r\n# rotate: (t, radian, axis=Const.xy) ->\r\n# # get anchor point\r\n# anchor = @interpolate( t )\r\n# # get init angle\r\n# ang = anchor.angle( axis, @ ) + radian\r\n#\r\n# # find rotated line's points\r\n# pa = new Vector( Math.cos( ang ), Math.sin( ang ) )\r\n#\r\n# if axis is Const.yz\r\n# pb = new Vector( 0, -pa.y, -pa.z )\r\n# else if axis is Const.xz\r\n# pb = new Vector( -pa.x, 0, -pa.z )\r\n# else\r\n# pb = new Vector( -pa.x, -pa.y, 0 )\r\n#\r\n# pa.multiply( anchor.$subtract( @ ).magnitude() )\r\n# pa.add( anchor )\r\n#\r\n# pb.multiply( @p1.$subtract( anchor ).magnitude() )\r\n# pb.add( anchor )\r\n#\r\n# # set the points to new position\r\n# @set( pa )\r\n# @p1.set( pb )\r\n#\r\n# return @\r\n\r\n\r\n# Reflect a point to the other side of this line\r\n# see also Vector.reflect2D and Matrix.reflectAnchor2D\r\n# reflect: (point, axis=Const.xy) ->\r\n# ln = @intercept( axis )\r\n# p = point.get2D( axis )\r\n# d = ( p.x + (p.y-ln.yi) * ln.slope ) / (1+ ln.slope*ln.slope)\r\n# ref = {\r\n# x: 2*d - p.x,\r\n# y: 2*d*ln.slope - p.y + 2*ln.yi\r\n# }\r\n#\r\n# if axis == Const.xz\r\n# return new Vector( ref.x, point.y, ref.y )\r\n# else if axis == Const.yz\r\n# return new Vector( point.x, ref.x, ref.y )\r\n# else\r\n# return new Vector( ref.x, ref.y, point.z )\n# ### Imagine making a viewfinder with your hands: touch one hand's thumb with the other hand's index finger, and stretch them wide open. Your fingers are the two vectors that define a rectangle, and the rectangle partitions a space and redefines what's inside and outside.\r\nclass Rectangle extends Pair\r\n\r\n # ## Create a new Rectangle. A Rectangle is a Pair whose rectangular bounding box are defined by two Vectors. Use `toPointSet()` to convert it to a PointSet with 4 points if you need to rotate or shear it.\r\n # @param `args` Similar to Pair constructor, use comma-separated values, an array, or an object as parameters to specify the first point. As a shortcut to `to()`, you can also pass 4 or 6 values to set both anchor and `p1` points directly as a 2d or 3d vector.\r\n # @eg `new Rectangle()` `new Rectangle(1,2,3)` `new Rectangle([2,4])` `new Rectangle({x:3, y:6, z:9}).to(1,2,3)`\r\n # @return a new Rectangle object\r\n constructor: () ->\r\n super\r\n\r\n # ## the center point of rectangle as Vector object\r\n @center = new Vector()\r\n\r\n\r\n # ## A static method `Rectangle.contain` to check if a point is within a bound\r\n # @param `pt` the Point to check\r\n # @param `ptl` a Point to specify top-left position of the rectangular bounds\r\n # @param `pbr` a Point to specify bottom-right position of the rectangular bounds\r\n # @return a boolean value indicating if the point is contained within the rectangular bounds\r\n @contain: (pt, ptl, pbr) ->\r\n return (pt.x >= ptl.x && pt.x <= pbr.x && pt.y >= ptl.y && pt.y <= pbr.y && pt.z >= ptl.z && pt.z <= pbr.z)\r\n\r\n\r\n # ## Describe this rectangle as a text string\r\n # @return \"Rectangle x1, y1, z1, x2, y2, z2, width height\" text\r\n toString : ->\r\n s = @size()\r\n \"Rectangle x1 #{@x}, y1 #{@y}, z1 #{@z}, x2 #{@p1.x}, y2 #{@p1.y}, z2 #{@p1.z}, width #{s.x}, height #{s.y}\"\r\n\r\n\r\n # ## Convert this Rectangle from a pair of points to a `PointSet` which has 4 points. Note that if you want to rotate or shear this rectangle, convert this rectangle to a `PointSet` first.\r\n # @return a PointSet with 4 points. (top-right, bottom-right, bottom-left, top-left)\r\n toPointSet: () ->\r\n c = @corners()\r\n return new PointSet( @ ).to( [c.topRight, c.bottomRight, c.bottomLeft, c.topLeft ] )\r\n\r\n\r\n # ## Similar to `Pair`, this function connects the anchor with another point to define the rectangular bounds. This also calls Pair's `resetBounds()` to make sure anchor point is at top-left and `p1` is at bottom-right\r\n # @param `args` comma-separated values, or an array, or an object\r\n # @eg `rect.to(1,2,3)` `new Rect(pt).to([3,4])`\r\n # @return this Rectangle\r\n to: ( args ) ->\r\n @p1 = new Vector( Point.get(arguments) )\r\n @resetBounds()\r\n @center = @midpoint() # get center point also\r\n return @\r\n\r\n\r\n # ## Set center to new location and move this rectangle, or reset the center point based on current size and position.\r\n # @param `args` comma-separated values, or an array, or an object to specify the new position\r\n # @eg `rect.setCenter()`, `rect.setCenter(100,50)`, `rect.setCenter( pt )`\r\n # @return this Rectangle\r\n setCenter: ( args ) ->\r\n if arguments.length == 0\r\n @center = @midpoint();\r\n return;\r\n\r\n halfsize = @size().$divide(2)\r\n @center.set( Point.get(arguments) )\r\n @set( @center.$subtract( halfsize ) )\r\n @p1.set( @center.$add( halfsize ) )\r\n return @\r\n\r\n\r\n # ## resize to a specific size from top left\r\n # @param `args` comma-separated values, or an array, or an object to specify the new size\r\n # @eg `rect.resizeTo(10,10)` `rect.resizeTo( size_vec )`\r\n # @return this Rectangle\r\n resizeTo: () ->\r\n @p1 = new Vector( Point.get(arguments) )\r\n @relative()\r\n @center = @midpoint() # get center point also\r\n return @\r\n\r\n\r\n # ## resize to a specific size from center point\r\n # @param `args` comma-separated values, or an array, or an object to specify the new size.\r\n # @eg `rect.resizeCenterTo(10,10)` `rect.resizeCenterTo( size_vec )`\r\n # @demo rectangle.resizeCenterTo\r\n # @return this Rectangle\r\n resizeCenterTo: () ->\r\n size = new Vector( Point.get(arguments)).divide( 2 ) # get half size\r\n @set( @center.$subtract(size) )\r\n @p1.set( @center.$add(size) )\r\n return @\r\n\r\n\r\n # ## resize this rectangle so that it will enclose another rectangle. Namely, the resulting rectangle is a *union* of the two initial rectangles.\r\n # @param `rect` another Rectangle or Pair object\r\n # @demo rectangle.enclose\r\n # @return this Rectangle which has the new size\r\n enclose: ( rect ) ->\r\n @set( @$min( rect ) )\r\n @p1.set( @p1.$max( rect.p1 ) )\r\n @center = @midpoint() # get center point also\r\n return @\r\n\r\n\r\n # ## Same as `enclose()` but returns a new Rectangle\r\n # @param `rect` another Rectangle or Pair object\r\n # @return a new Rectangle which has the new size\r\n $enclose: ( rect ) -> return @clone().enclose( rect )\r\n\r\n # ## Check if this rectangle encloses (or is enclosed by) another rect. Use with `isLarger()` to check which rectangle is being enclosed.\r\n # @param `rect` another rectangle\r\n # @return a boolean value to indicate if one rectangle is enclosed by another\r\n isEnclosed: ( rect ) ->\r\n d = @$subtract( rect ).multiply( @p1.$subtract( rect.p1 ) )\r\n d2 = @size().subtract( rect.size() )\r\n return d.x <= 0 and d.y <= 0 and d.z <= 0 and (d2.x * d2.y >= 0)\r\n\r\n\r\n # ## Check if this rectangle is larger than another rectangle\r\n # @param `rect` another rectangle\r\n # @return a boolean value to indicate if this rectangle is larger\r\n isLarger: ( rect ) ->\r\n s1 = @size()\r\n s2 = rect.size()\r\n return s1.x * s1.y > s2.x * s2.y\r\n\r\n\r\n # ## Check if a Point is on this Rectangle\r\n # @param `args` comma-separated values, or an array, or a Point object\r\n # @eg `rect.intersectPoint(1,2,3)` `rect.intersectPoint(pt)`\r\n # @return a boolean value to indicate if there is an intersection\r\n intersectPoint: () ->\r\n pt = Point.get(arguments)\r\n return (pt.x >= @x && pt.x <= @p1.x && pt.y >= @y && pt.y <= @p1.y && pt.z >= @z && pt.z <= @p1.z)\r\n\r\n\r\n # ## Check intersections between this Rectangle and an infinite Line on xy axis.\r\n # @param `path` a Pair or Line object to specify an infinite line\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @demo rectangle.intersectPath\r\n # @returns an Array of intersection points (zero or two points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectPath: ( line, get_pts=true ) ->\r\n sides = @sides()\r\n pts = []\r\n for s in sides\r\n p = s.intersectPath( line )\r\n if p and @intersectPoint( p )\r\n if get_pts\r\n pts.push( p )\r\n else\r\n return true\r\n\r\n return if get_pts then pts else false\r\n\r\n\r\n # ## Check intersections between this Rectangle and a Line segment on xy axis.\r\n # @param `line` a Line to check\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero, one, or two points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectLine: (line, get_pts=true) ->\r\n\r\n # check if fully enclosed\r\n ip1 = @intersectPoint( line )\r\n ip2 = @intersectPoint( line.p1 )\r\n if ip1 and ip2 then return if get_pts then [] else true\r\n\r\n # bounding box check\r\n if !(ip1 or ip2)\r\n lbound = line.bounds()\r\n if !@intersectRectangle( lbound, false )\r\n return if get_pts then [] else false\r\n\r\n # check sides\r\n sides = @sides()\r\n pts = []\r\n for s in sides\r\n p = line.intersectLine( s )\r\n if p\r\n if get_pts\r\n pts.push( p )\r\n else\r\n return true\r\n\r\n return if get_pts then pts else false\r\n\r\n\r\n # ## Check if this Rectangle intersects with a list of Lines ( useful for polygon or polyline such as `rectangle.sides()` ) on xy axis.\r\n # @param `lines` an array of Line\r\n # @param `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points, or a boolean value. (Based on `get_pts` parameter)\r\n intersectLines: (lines, get_pts=true) ->\r\n return Line.intersectLines( @, lines, get_pts )\r\n\r\n\r\n # ## Check if this Rectangle intersects with another Rectangle\r\n # @param `rect` a Rectangle to check\r\n # @get_pts `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero or two or four points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectRectangle: ( rect, get_pts=true ) ->\r\n\r\n # rectangle intersection check, check for whether it's completely contain\r\n xi = ( @p1.x >= rect.x ) && ( @x <= rect.p1.x )\r\n yi = ( @p1.y >= rect.y ) && ( @y <= rect.p1.y )\r\n zi = ( @p1.z >= rect.z ) && ( @z <= rect.p1.z )\r\n intersected = (xi && yi && zi)\r\n\r\n if !get_pts then return intersected\r\n if @isEnclosed( rect ) then return (if get_pts then [] else true )\r\n\r\n if !intersected then return []\r\n\r\n # pa = new Vector(@max( rect ))\r\n # pb = new Vector(@p1.min( rect.p1 ))\r\n\r\n sidesA = @sides()\r\n sidesB = rect.sides()\r\n\r\n pts = []\r\n for sa in sidesA\r\n for sb in sidesB\r\n\r\n p = sa.intersectGridLine( sb )\r\n if p then pts.push(p)\r\n\r\n return pts\r\n\r\n\r\n\r\n # ## Check if this Rectangle intersect with another element\r\n # @param `item` any object that is based on Point. (Vector, Line, Rectangle, Circle, etc)\r\n # @eg `rect.hasIntersect( another_circle )` `rect.hasIntersect(line)` `rect.hasIntersect(rect)`\r\n # @returns an Array of intersection points or a boolean value. (Based on `get_pts` parameter)\r\n hasIntersect: ( item, get_pts=false ) ->\r\n\r\n # circle intersection check\r\n if item instanceof Circle\r\n return item.intersectLines( @sides(), get_pts )\r\n\r\n # rectangle bounding box check\r\n else if item instanceof Rectangle\r\n return @intersectRectangle( item, get_pts )\r\n\r\n # polygon intersection check\r\n else if item instanceof PointSet or item instanceof Triangle\r\n return @intersectLines(item.sides(), get_pts)\r\n\r\n # line intersection check\r\n else if item instanceof Pair\r\n return @intersectLine( item, get_pts )\r\n\r\n # point intersection check\r\n else if item instanceof Point\r\n return Rectangle.contain( item, @, @p1 )\r\n\r\n else\r\n return if get_pts then [] else false\r\n\r\n\r\n # ## Get the corners of this rectangle as 4 Vectors\r\n # @return an Object with 4 `Vector` objects as {topLeft, topRight, bottomLeft, bottomRight}\r\n corners: () -> {\r\n topLeft: new Vector( Math.min( @x, @p1.x ), Math.min( @y, @p1.y), Math.max( @z, @p1.z) )\r\n topRight: new Vector( Math.max( @x, @p1.x ), Math.min( @y, @p1.y), Math.min( @z, @p1.z) )\r\n bottomLeft: new Vector( Math.min( @x, @p1.x ), Math.max( @y, @p1.y), Math.max( @z, @p1.z) )\r\n bottomRight: new Vector( Math.max( @x, @p1.x ), Math.max( @y, @p1.y), Math.min( @z, @p1.z) )\r\n }\r\n\r\n\r\n # ## Get the sides of this rectangle as 4 lines\r\n # @return an Array of 4 `Line` objects [top, right, bottom, left]\r\n sides: () ->\r\n c = @corners()\r\n return [\r\n new Line( c.topLeft ).to( c.topRight )\r\n new Line( c.topRight ).to( c.bottomRight )\r\n new Line( c.bottomRight ).to( c.bottomLeft )\r\n new Line( c.bottomLeft ).to( c.topLeft )\r\n ]\r\n\r\n # ## Get 4 rectangles from this rectangle by subdividing the quadrants\r\n # @return an Object with 4 `Rectangle` objects as {topLeft, topRight, bottomLeft, bottomRight}\r\n quadrants: () ->\r\n c = @corners()\r\n return {\r\n topLeft: new this.__proto__.constructor( c.topLeft ).to( @center )\r\n topRight: new this.__proto__.constructor( c.topRight ).to( @center )\r\n bottomLeft: new this.__proto__.constructor( c.bottomLeft ).to( @center )\r\n bottomRight: new this.__proto__.constructor( c.bottomRight ).to( @center )\r\n }\r\n\r\n\r\n # override clone\r\n clone: () ->\r\n p = new Rectangle(@).to(@p1)\r\n p.to( @p1.clone() )\r\n return p\r\n\r\n\r\n# namespace\r\nthis.Rectangle = Rectangle\n# ### A grid divides a space into cells, puts things into groups. Like scattering a handful of peas on the chessboard, we can simplify the description of a state by clarifying its context. A grid thus help us interpret spaces and restate forms.\r\nclass Grid extends Rectangle\r\n\r\n # ## Create a new Grid. Like a Rectangle, a Grid's area are defined by two Vectors.\r\n # @param `args` Similar to Pair constructor, use comma-separated values, an array, or an object as parameters to specify the first point. As a shortcut to `to()`, you can also pass 4 or 6 values to set both anchor and `p1` points directly as a 2d or 3d vector.\r\n # @eg `new Grid()` `new Grid(1,2,3)` `new Grid([2,4])` `new Grid({x:3, y:6, z:9}).to(1,2,3)`\r\n # @return a new Grid object\r\n constructor: () ->\r\n super\r\n\r\n # ## grid cell settings as an object with `.type` property which defines the grid type such as \"fix-fix\", and `.size` property which stores the cell size as a Vector object.\r\n @cell = {\r\n type : 'fix-fix'\r\n size: new Vector()\r\n }\r\n\r\n # ## property to specify number of rows in the grid\r\n @rows = 0\r\n\r\n # ## property to specify number of columns in the grid\r\n @columns = 0\r\n\r\n # ## property to store layout and cell states\r\n @layout = []\r\n\r\n # callback from cell generation\r\n @cellCallback = null\r\n\r\n\r\n # ## Describe this grid as a text string\r\n # @return \"Grid width, height, columns, rows, cell\" text\r\n toString: ->\r\n s = @size()\r\n \"Grid width #{s.x}, height #{s.y}, columns #{@columns}, rows #{@rows}, \" +\r\n \"cell (#{@cell.size.x}, #{@cell.size.y}), type #{@cell.type}\"\r\n\r\n\r\n # ## Initiate a grid\r\n # @param `x` a value to specify cell width (if `xtype` parameter is \"fix\" or \"flex\") or column count (if `xtype` parameter is \"stretch\")\r\n # @param `y` a value to specify cell height (if `ytype` parameter is \"fix\" or \"flex\") or row count (if `ytype` parameter is \"stretch\")\r\n # @param `xtype, ytype` a string to specify how columns and rows should be calculated. Use \"fix\" to specify exact cell width or height in pixels, \"flex\" to specify ideal cell width or height in pixels (which allows for flexible rounding to rows or columns), \"stretch\" to specify number of rows or columns only\r\n # @eg `grid.create(100,50)` `grid.create( 10,10, \"stretch\",\"stretch\")` `grid.create( 20,20, \"flex\",\"fix\")`\r\n # @return this grid\r\n init : ( x, y, xtype='fix', ytype='fix' ) ->\r\n\r\n size = @size()\r\n\r\n @cell.type = xtype + '-' + ytype\r\n @rows = y\r\n @columns = x\r\n\r\n # calculate x and columns\r\n # stretch: always fit number of columns\r\n if xtype is 'stretch'\r\n @cell.size.x = size.x / x\r\n @columns = x\r\n # flex: fit as many as possible\r\n else if xtype is 'flex'\r\n @columns = Math.round( size.x / x )\r\n @cell.size.x =size.x / @columns\r\n # fix: cell width is fixed\r\n else # fix\r\n @cell.size.x = x\r\n @columns = Math.floor( size.x / @cell.size.x )\r\n\r\n # calculate y and rows\r\n # stretch: always fit number of rows\r\n if ytype is 'stretch'\r\n @cell.size.y = size.y / y\r\n @rows = y\r\n # flex: fit as many as possible\r\n else if ytype is 'flex'\r\n @rows = Math.round( size.y / y )\r\n @cell.size.y = size.y / @rows\r\n # fix: cell height is fixed\r\n else # fix\r\n @cell.size.y = y\r\n @rows = Math.floor( size.y / @cell.size.y )\r\n\r\n # init layout arrays\r\n if (@layout.length < 1) then @resetLayout()\r\n\r\n return @\r\n\r\n\r\n # ## Define a callback function for cell creation. This will loop through each cell in the grid and call the callback function.\r\n # @param `callback` a callback function with these parameters `( cell_size, cell_position, cell_row, cell_column, cell_type )`\r\n # @demo grid.generate\r\n # @return this grid\r\n generate : ( callback ) ->\r\n if (typeof callback == \"function\")\r\n @cellCallback = callback\r\n return @\r\n\r\n\r\n # ## Generate the grid by looping through each cell\r\n create : () ->\r\n if !@cellCallback then return @\r\n\r\n for c in [0...@columns]\r\n for r in [0...@rows]\r\n cell = @cell.size.clone()\r\n pos = @$add( cell.$multiply( c, r ) ) # cellsize * row-column + grid-position\r\n isOccupied = if (@layout.length > 0 and @layout[0].length > 0) then @layout[r][c]==1 else false;\r\n @cellCallback( cell, pos, r, c, @cell.type, isOccupied )\r\n\r\n return @\r\n\r\n\r\n # ## Get the cell's size as a Vector\r\n # @return a cloned `cell.size` property as Vector\r\n getCellSize: () -> return @cell.size.clone()\r\n\r\n # ## Give a column and a row, get a rectangle which indicates the cell position and size\r\n # @param `c, r` column and row index, respectively\r\n # @param `allowOutofBound` a boolean value to set if the returned rectangle can be outside of the grid\r\n # @eg `grid.cellToRectangle(2, 3)`, `grid.cellToRectangle(2, 5, true)`\r\n # @return a Rectangle\r\n cellToRectangle : (c, r, allowOutofBound=false) ->\r\n # cellsize * row-column + grid-position\r\n if allowOutofBound or (c >= 0 and c < @columns and r >= 0 and r < @rows)\r\n rect = new Rectangle( @$add( @cell.size.$multiply( c, r ) ) ).resizeTo( @cell.size )\r\n return rect\r\n else\r\n return false\r\n\r\n\r\n # ## Give a x,y position, get the corresponding cell on the grid.\r\n # @param `args` 0-3 comma-separated values, or as an array, or a Point object.\r\n # @eg `grid.positionToCell( 100, 50 )`, `grid.positionToCell( [100, 50] )`, `grid.positionToCell( pt )`,\r\n # @return a Vector object whose `x` is the column index and `y` is the row index\r\n positionToCell : (args) ->\r\n pos = new Vector( @_getArgs( arguments ) )\r\n cellpos = pos.$subtract( @ ).$divide( @cell.size ).floor()\r\n cellpos.max( 0, 0 ).min( @columns-1, @rows-1 );\r\n return cellpos\r\n\r\n\r\n # ## Reset the layout and its cell states\r\n # @param `callback` a function with these parameters ( this_grid, cell_row, cell_column ). This will get called after each cell's reset.\r\n # @return this grid\r\n resetLayout : ( callback ) ->\r\n @layout = []\r\n for r in [0...@rows]\r\n @layout[r] = []\r\n for c in [0...@columns]\r\n @layout[r][c] = 0\r\n if callback then callback( @, r, c )\r\n\r\n return @\r\n\r\n\r\n # ## Mark a certain area in the grid layout as occupied\r\n # @param `x, y` column and row index\r\n # @param `w` column width\r\n # @param `h` row size\r\n # @param `occupy` a boolean value to set if this cell should be occupied. Defaults to `true`\r\n # @eg `grid.occupy(0,0, 5,3)`\r\n # @demo grid.occupy\r\n # @return this grid\r\n occupy : ( x, y, w, h, occupy=true ) ->\r\n if (@rows <= 0 or @columns <=0) then return @\r\n if (@layout.length < 1) then @resetLayout()\r\n for c in [0...w]\r\n for r in [0...h]\r\n @layout[ Math.min( @layout.length-1, y+r) ][ x+c] = (if (occupy) then 1 else 0)\r\n\r\n return @\r\n\r\n\r\n # ## Check a certain area in the grid is unoccupied\r\n # @param `x, y` column and row index\r\n # @param `w` column width\r\n # @param `h` row size\r\n # @eg `grid.canFit(0,0, 5,3)`\r\n # @return a boolean value where `true` means the area is unoccupied\r\n canFit : ( x, y, w, h ) ->\r\n\r\n # each cell in specific rows and columns\r\n for currRow in [y...Math.min(@rows, y+h)]\r\n for currCol in [x...Math.min(@columns, x+w)]\r\n cell = @layout[currRow][currCol]\r\n # if cell is filled\r\n if cell? and cell > 0\r\n return false\r\n\r\n return true\r\n\r\n\r\n # ## Fit this area as much as possible within the grid's free ceels\r\n # @param `cols` number of columns\r\n # @param `rows` number of rows\r\n # @return an object with properties `row` and `column` to specify the top left position, `columnSize` and `rowSize` to specify the resulting size in grid units, and `bound` which is the actual area as a Rectangle object.\r\n fit : ( cols, rows ) ->\r\n\r\n # find column size, bound by maximum columns in the grid\r\n # maxColumns = @layout[0].length\r\n colSize = Math.min( cols, @columns )\r\n\r\n # go through each grid cell\r\n # each row\r\n for currRow in [0...@rows]\r\n colCount = colSize # counter to find available columns\r\n freeCol = 0 # start position of first free column\r\n\r\n # each column\r\n for currCol in [0...@columns]\r\n cell = @layout[currRow][currCol]\r\n\r\n # if cell is filled\r\n if cell? and cell > 0\r\n freeCol++ # this column is not free\r\n colCount = colSize # reset colCount if it's counting\r\n\r\n # if cell is not filled\r\n else\r\n # see if the next one fits\r\n colCount--\r\n\r\n # can fit all\r\n if colCount <= 0\r\n\r\n # mark this area as occupied\r\n @occupy( freeCol, currRow, colSize, rows )\r\n\r\n # calculate the bounding box\r\n b = new Rectangle( @$add( @cell.size.$multiply( freeCol, currRow ) ) ) # top left\r\n b.resizeTo( @cell.size.$multiply( colSize, rows ) ) # size\r\n\r\n return {\r\n row: currRow\r\n column: freeCol\r\n columnSize: colSize\r\n rowSize: rows\r\n bound: b\r\n }\r\n\r\n # cannot fit\r\n return false\r\n\r\n\r\n # ## Given a cell's position, get an array of the neighboring cells that surround it\r\n # @param `c` column index\r\n # @param `r` row index\r\n # @eg `grid.neighbors( 3, 2 )`, `(grid.neighbors(3, 2))[Const.top_right]`\r\n # @return an array of neighbors starting from top-left going clockwise. The array values can be Vectors whose `x` is column index and `y` is row index, or `false` if the neighbor cell is out of bounds. You may access the cells semantically by using Const.top_right etc.\r\n neighbors: (c, r) ->\r\n temp = [ [c-1, r-1], [c, r-1], [c+1, r-1], [c+1, r], [c+1, r+1], [c, r+1], [c-1, r+1], [c-1, r] ];\r\n ns = []\r\n for n in temp\r\n if n[0] >= 0 and n[0] < @columns and n[1] >= 0 and n[1] < @rows\r\n ns.push( new Vector( n[0], n[1], @layout[ n[1] ][ n[0] ] ) )\r\n else\r\n ns.push( false )\r\n return ns;\r\n\r\n\r\n\r\n# namespace\r\nthis.Grid = Grid\n# ### Like stargazing, like connecting the dots, like pareidolia, a set of points in space always flickers in our imagination and illuminates potential forms. Perhaps, creativity is the process in which one seeks hidden relationships in these disparate points or ideas, and conjures meanings or polygons.\r\nclass PointSet extends Vector\r\n\r\n # ## Create a new PointSet. A PointSet is a set of points which can repsent a polygon or a polyline or a time series.\r\n # @param `args` Similar to Point constructor, use comma-separated values, an array, or an object as parameters to specify the anchor point. Use `to()` to add points to the set.\r\n # @eg `new PointSet()` `new PointSet(1,2,3)` `new PointSet([2,4])` `new PointSet({x:3, y:6, z:9}).to(1,2,3)` `new PointSet(1,2,3).to([p1, p2, p3, p4, p5])`\r\n # @return a new PointSet object\r\n constructor: () ->\r\n super\r\n\r\n # ## The points in this set as an array\r\n @points = []\r\n\r\n\r\n # ## Describe this rectangle as a text string\r\n # @return \"PointSet [p1... p2... p3...]\" text\r\n toString:() ->\r\n str = \"PointSet [ \"\r\n for p in @points\r\n str += \"#{p.x},#{p.y},#{p.z}, \"\r\n return str+\" ]\"\r\n\r\n\r\n # ## Get a copy of the `points` property as an array\r\n toArray:() -> @points.slice()\r\n\r\n\r\n # ## Add a point or an array of points to this PointSet\r\n # @param `args` either an Array of Points, or a single point defined by comma-separated values, an array, or an object.\r\n # @eg `pset.to( 1,2,3 )` `pset.to([1,2,3]` `pset.to({x:3, y:6, z:9})` `pset.to([p1, p2, p3, p4...])`\r\n # @return this PointSet\r\n to: ( args ) ->\r\n\r\n if arguments.length > 0\r\n # if it's an array of objects.\r\n if Array.isArray( arguments[0] ) and arguments[0].length > 0 and typeof arguments[0][0] is 'object'\r\n for p in arguments[0]\r\n @points.push( new Vector(p) )\r\n\r\n else\r\n @points.push( new Vector( Point.get(arguments ) ) )\r\n\r\n return @\r\n\r\n\r\n # ## Get a point from the set of points based on its index position\r\n # @param `index` index position\r\n # @return a point in the set\r\n getAt: ( index ) ->\r\n return @points[ Math.min( @points.length-1, Math.max(0, index) ) ];\r\n\r\n\r\n # ## Same as `getAt()` but returns a new Vector\r\n $getAt: ( index ) -> return new Vector( @getAt( index ) );\r\n\r\n\r\n # ## Set a point at a specific index position\r\n # @param `index` index position\r\n # @param `p` new point\r\n # @return this set\r\n setAt: ( index, p ) ->\r\n @points[ index ] = p;\r\n return this;\r\n\r\n\r\n # ## Get the number of points in the set\r\n count: () -> return this.points.length;\r\n\r\n # ## Add a point whose position is calculated relative to this PointSet's anchor point\r\n # @param `args` 0-3 comma-separated values, or as an array, or a Point object.\r\n # @eg `pset.connectFromAnchor(1,2)` `pset.connectFromAnchor([2,4])` `pset.connectFromAnchor({x:3, y:6, z:9})`\r\n # @return this PointSet\r\n connectFromAnchor: ( args ) ->\r\n\r\n if arguments.length > 0\r\n if Array.isArray( arguments[0] ) and arguments[0].length > 0 # if it's Array.\r\n for p in arguments[0]\r\n @points.push( @$add(p) )\r\n\r\n else\r\n @points.push( @$add( Point.get(arguments ) ) )\r\n\r\n return @\r\n\r\n\r\n # ## Remove a point or a series of points from this Points set\r\n # @param `index` an index which can be positive or negative integer. If index is negative, the points are removed from the end. For example, `-2` will remove the last 2 points.\r\n # @eg `pset.disconnect(3)`, `pset.disconnect(-2)`\r\n # @return this PointSet\r\n disconnect: (index=-1) ->\r\n if index < 0\r\n @points = @points.slice( 0, @points.length+index )\r\n else\r\n @points = @points.slice( index+1 )\r\n\r\n return @\r\n\r\n\r\n # ## Remove all the points\r\n # @return this PointSet\r\n clear: () ->\r\n @points = []\r\n return @\r\n\r\n\r\n # ## Get an array of Lines that represents this PointSet's sides\r\n # @param `close_path` a boolean value to include the side from last point to first point when set to `true`\r\n # @demo pointset.sides\r\n # @return an array of Lines\r\n sides: ( close_path=true ) ->\r\n lastP = null\r\n sides = []\r\n for p in @points\r\n if lastP then sides.push( new Line(lastP).to(p) )\r\n lastP = p\r\n\r\n if @points.length > 1 and close_path\r\n sides.push( new Line( lastP ).to( @points[0] ) )\r\n\r\n return sides\r\n\r\n # ## Get the angles of each vertice connected by 2 sides\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @return an array of objects `{p0, p1, p2, angle}`\r\n angles: ( axis=Const.xy ) ->\r\n angles = []\r\n for i in [1...@points.length-1] by 1\r\n v1 = @points[i-1].$subtract( @points[i] )\r\n v2 = @points[i+1].$subtract( @points[i] )\r\n angles.push( { p0: @points[i-1], p1: @points[i], p2: @points[i+1], angle: v1.angleBetween( v2 ) } )\r\n\r\n return angles\r\n\r\n\r\n # ## Get the bounding box for this point set.\r\n # @return a Rectangle which is the bounding box of the PointSet\r\n bounds: () ->\r\n Util.boundingBox( @points )\r\n\r\n\r\n # ## Get this PointSet's centroid, which is the averge positions of its points.\r\n # @return the centroid point as Vector\r\n centroid: () ->\r\n Util.centroid( @points )\r\n\r\n\r\n # ## Get a convex hull of the point set using Melkman's algorithm\r\n # @param `sort` a boolean value to sort the `points` by x position first if set to true\r\n # @demo pointset.convexHull\r\n # @return an array of Vectors to define the convex hull\r\n convexHull: ( sort=true ) ->\r\n\r\n if @points.length < 3 then return []\r\n\r\n # sort points array first or not\r\n if sort\r\n pts = @points.slice()\r\n pts.sort( (a, b) -> return a.x - b.x )\r\n else\r\n pts = @points\r\n\r\n # if pt is on left of ray ab. Similar to Pari.collinear()\r\n left = (a, b, pt) ->\r\n (b.x - a.x) * (pt.y - a.y) - (pt.x - a.x) * (b.y - a.y) > 0\r\n\r\n # double end queue\r\n dq = []\r\n\r\n # first 3 points\r\n if left( pts[0], pts[1], pts[2])\r\n dq.push( pts[0] )\r\n dq.push( pts[1] )\r\n else\r\n dq.push( pts[1] )\r\n dq.push( pts[0] )\r\n\r\n dq.unshift( pts[2] )\r\n dq.push( pts[2] )\r\n\r\n # remaining points\r\n i = 3\r\n while i < pts.length\r\n pt = pts[i]\r\n\r\n if left( pt, dq[0], dq[1] ) and left(dq[dq.length-2], dq[dq.length-1], pt)\r\n i++\r\n continue\r\n\r\n while !left(dq[dq.length-2], dq[dq.length-1], pt)\r\n dq.pop()\r\n dq.push( pt )\r\n\r\n while !left( dq[0], dq[1], pt)\r\n dq.shift()\r\n dq.unshift( pt )\r\n\r\n i++\r\n\r\n # returns the hull's points\r\n return dq\r\n\r\n\r\n # overrides clone\r\n clone: () ->\r\n new PointSet(@).to( Util.clonePoints( @points ) )\r\n\r\n\r\n# namespace\r\nthis.PointSet = PointSet\n# ### A straight line or a moving particle, swayed by external forces or internal constraints, gradually deviates from its ideal path and becomes a curve. A river meanders and a strain of hair curls. A curve expresses the effects of forces and constraints.\r\nclass Curve extends PointSet\r\n\r\n # ## Create a new Curve. A Curve uses a set of anchor and/or control points to interpolate a curve.\r\n # @param `args` Similar to PointSet constructor, use comma-separated values, an array, or an object as parameters to specify the anchor point. Use `to()` to add points to the set.\r\n # @eg `new PointSet()` `new PointSet(1,2,3)` `new PointSet([2,4])` `new PointSet({x:3, y:6, z:9}).to(1,2,3)` `new PointSet(1,2,3).to([p1, p2, p3, p4, p5])`\r\n # @return a new Curve object\r\n constructor: () ->\r\n super\r\n\r\n # ## a boolean value to specify if this Curve is 2D or 3D. Default is `false` (2D).\r\n @is3D = false\r\n\r\n\r\n # A private function to pre-calculate the interpolation steps\r\n _getSteps: (steps) ->\r\n ts = []\r\n for s in [0..steps] by 1\r\n t = s/steps\r\n ts.push( [t, t*t, t*t*t] )\r\n return ts\r\n\r\n\r\n # ## Given an index for the starting position in `points` array, get the control and/or end points of a curve segment\r\n # @param `index` start index in `points` array. Default is 0.\r\n # @param `copyStart` an optional boolean value to indicate if the start index should be used twice. Default is false.\r\n # @return an object with 4 points `{p0, p1, p2, p3}`\r\n controlPoints: ( index=0, copyStart=false ) ->\r\n\r\n _index = (i) =>\r\n idx = if i < @points.length-1 then i else @points.length-1\r\n return idx\r\n\r\n # Get points based on index\r\n p0 = @points[index] # control pt 1\r\n if !p0.x? then return false\r\n\r\n index = if copyStart then index else index+1\r\n\r\n p1 = @points[ _index(index++) ] # t = 0\r\n p2 = @points[ _index(index++) ] # t = 1\r\n p3 = @points[ _index(index++) ] # control pt 2\r\n\r\n return {\r\n p0: p0\r\n p1: p1\r\n p2: p2\r\n p3: p3\r\n }\r\n\r\n\r\n # ## Create a Catmull-Rom curve. Catmull-Rom is a kind of Cardinal curve with smooth-looking curve.\r\n # @param `step` the number of line segments. Defaults to 10 steps.\r\n # @return an array of Points\r\n catmullRom: ( steps=10 ) ->\r\n\r\n if @points.length < 2 then return []\r\n\r\n ps = []\r\n ts = @_getSteps( steps )\r\n\r\n # use first point twice\r\n c = @controlPoints( 0, true )\r\n for i in [0..steps] by 1\r\n ps.push( @catmullRomPoint( ts[i], c ) )\r\n\r\n # go through all the points\r\n k = 0\r\n while k < @points.length-2\r\n c = @controlPoints( k )\r\n if c\r\n for i in [0..steps] by 1\r\n ps.push( @catmullRomPoint( ts[i], c ) )\r\n k++\r\n\r\n return ps\r\n\r\n\r\n # ## Interpolate to get a point on Catmull-Rom curve\r\n # @param `step` the point to interpolate, as an array of `[t, t*t, t*t*t]` where `t` is between 0 to 1\r\n # @param `ctrls` the control points which can be provided by `controlPoints()` function\r\n # @return a Point on the curve\r\n catmullRomPoint: ( step, ctrls ) ->\r\n # Basis Matrix (http://mrl.nyu.edu/~perlin/courses/fall2002/hw/12.html)\r\n # {-0.5, 1.5, -1.5, 0.5}\r\n # { 1 , -2.5, 2 ,-0.5},\r\n # {-0.5, 0 , 0.5, 0 },\r\n # { 0 , 1 , 0 , 0 }\r\n\r\n t = step[0]\r\n t2 = step[1]\r\n t3 = step[2]\r\n\r\n h1 = ( -0.5*t3 + t2 - 0.5*t )\r\n h2 = ( 1.5*t3 - 2.5*t2 + 1 )\r\n h3 = ( -1.5*t3 + 2*t2 + 0.5*t )\r\n h4 = ( 0.5*t3 - 0.5*t2 )\r\n\r\n x = ( h1*ctrls.p0.x + h2* ctrls.p1.x + h3*ctrls.p2.x + h4*ctrls.p3.x )\r\n y = ( h1*ctrls.p0.y + h2* ctrls.p1.y + h3*ctrls.p2.y + h4*ctrls.p3.y )\r\n z = if !@is3D then 0 else ( h1*ctrls.p0.z + h2* ctrls.p1.z + h3*ctrls.p2.z + h4*ctrls.p3.z )\r\n\r\n return new Point(x,y,z)\r\n\r\n\r\n # ## Create a Cardinal spline curve\r\n # @param `step` the number of line segments. Defaults to 10 steps.\r\n # @param `tension` optional value between 0 to 1 to specify a \"tension\". Default to 0.5 which is the tension for Catmull-Rom curve\r\n # @demo curve.cardinal\r\n # @return an array of Points\r\n cardinal: ( steps=10, tension=0.5 ) ->\r\n\r\n if @points.length < 2 then return []\r\n\r\n ps = []\r\n ts = @_getSteps( steps )\r\n\r\n # use first point twice\r\n c = @controlPoints( 0, true )\r\n for i in [0..steps] by 1\r\n ps.push( @cardinalPoint( ts[i], c, tension ) )\r\n\r\n # go through all the points\r\n k = 0\r\n while k < @points.length-2\r\n c = @controlPoints( k )\r\n if c\r\n for i in [0..steps] by 1\r\n ps.push( @cardinalPoint( ts[i], c, tension ) )\r\n k++\r\n\r\n return ps\r\n\r\n\r\n # ## Interpolate to get a point on Cardinal curve\r\n # @param `step` the point to interpolate, as an array of `[t, t*t, t*t*t]` where `t` is between 0 to 1\r\n # @param `ctrls` the control points which can be provided by `controlPoints()` function\r\n # @param `tension` optional value between 0 to 1 to specify a \"tension\". Default to 0.5 which is the tension for Catmull-Rom curve\r\n # @return a Point on the curve\r\n cardinalPoint: ( step, ctrls, tension=0.5 ) ->\r\n\r\n # Basis Matrix (http://algorithmist.wordpress.com/2009/10/06/cardinal-splines-part-4/)\r\n # [ -s 2-s s-2 s ]\r\n # [ 2s s-3 3-2s -s ]\r\n # [ -s 0 s 0 ]\r\n # [ 0 1 0 0 ]\r\n\r\n t = step[0]\r\n t2 = step[1]\r\n t3 = step[2]\r\n\r\n h1 = tension * ( -1*t3 + 2*t2 - t )\r\n h2 = tension * ( -1*t3 + t2 )\r\n h2a = (2*t3 - 3*t2 + 1)\r\n h3 = tension * ( t3 - 2*t2 + t )\r\n h3a = (-2*t3 + 3*t2)\r\n h4 = tension * ( t3 - t2 )\r\n\r\n x = ctrls.p0.x*h1 + ctrls.p1.x*h2 + h2a*ctrls.p1.x + ctrls.p2.x*h3 + h3a*ctrls.p2.x + ctrls.p3.x*h4\r\n y = ctrls.p0.y*h1 + ctrls.p1.y*h2 + h2a*ctrls.p1.y + ctrls.p2.y*h3 + h3a*ctrls.p2.y + ctrls.p3.y*h4\r\n z = if !@is3D then 0 else ctrls.p0.z*h1 + ctrls.p1.z*h2 + h2a*ctrls.p1.z + ctrls.p2.z*h3 + h3a*ctrls.p2.z + ctrls.p3.z*h4\r\n\r\n return new Point(x,y,z)\r\n\r\n\r\n # ## Create a Bezier curve. In a cubic bezier curve, the first and 4th points are end points, and 2nd and 3rd points are control points.\r\n # @param `step` the number of line segments. Defaults to 10 steps\r\n # @demo curve.bezier\r\n # @return an array of Points\r\n bezier: ( steps=10 ) ->\r\n\r\n if @points.length < 4 then return []\r\n\r\n ps = []\r\n ts = @_getSteps( steps )\r\n\r\n # go through all the points\r\n k = 0\r\n while k <= @points.length-3\r\n c = @controlPoints( k )\r\n if c\r\n for i in [0..steps] by 1\r\n ps.push( @bezierPoint( ts[i], c ) )\r\n # go to the next set of point, but assume current end pt is next start pt\r\n k+=3\r\n\r\n return ps\r\n\r\n\r\n # ## Interpolate to get a point on a cubic Bezier curve\r\n # @param `step` the point to interpolate, as an array of `[t, t*t, t*t*t]` where `t` is between 0 to 1\r\n # @param `ctrls` the control and end points which can be provided by `controlPoints()` function. The first and 4th points are end points, and 2nd and 3rd points are control points.\r\n # @return a Point on the curve\r\n bezierPoint: (step, ctrls) ->\r\n # Bezier basis matrix\r\n # { -1, 3, -3, 1 }\r\n # { 3, -6, 3, 0 }\r\n # { -3, 3, 0, 0 }\r\n # { 1, 0, 0, 0 }\r\n\r\n t = step[0]\r\n t2 = step[1]\r\n t3 = step[2]\r\n\r\n h1 = ( -1*t3 + 3*t2 - 3*t + 1 )\r\n h2 = ( 3*t3 - 6*t2 + 3*t )\r\n h3 = ( -3*t3 + 3*t2 )\r\n h4 = t3\r\n\r\n x = ( h1*ctrls.p0.x + h2* ctrls.p1.x + h3*ctrls.p2.x + h4*ctrls.p3.x )\r\n y = ( h1*ctrls.p0.y + h2* ctrls.p1.y + h3*ctrls.p2.y + h4*ctrls.p3.y )\r\n z = if !@is3D then 0 else ( h1*ctrls.p0.z + h2* ctrls.p1.z + h3*ctrls.p2.z + h4*ctrls.p3.z )\r\n\r\n return new Point(x,y,z)\r\n\r\n\r\n # ## Create a B-Spline cuve\r\n # @param `step` the number of line segments. Defaults to 10 steps.\r\n # @param `tension` optional value between 0 to 1 to specify a \"tension\". Or `false` to have normal tension. Default is false.\r\n # @demo curve.bspline\r\n # @return an array of Points\r\n bspline: ( steps=10, tension=false ) ->\r\n\r\n if @points.length < 2 then return []\r\n\r\n ps = []\r\n ts = @_getSteps( steps )\r\n\r\n # go through all the points\r\n k = 0\r\n while k < @points.length-2\r\n c = @controlPoints( k )\r\n if c\r\n if !tension\r\n for i in [0..steps] by 1\r\n ps.push( @bsplinePoint( ts[i], c ) )\r\n else\r\n for i in [0..steps] by 1\r\n ps.push( @bsplineTensionPoint( ts[i], c, tension ) )\r\n k++\r\n\r\n return ps\r\n\r\n\r\n # ## Interpolate to get a point on B-Spline curve\r\n # @param `step` the point to interpolate, as an array of `[t, t*t, t*t*t]` where `t` is between 0 to 1\r\n # @param `ctrls` the control points which can be provided by `controlPoints()` function\r\n # @return a Point on the curve\r\n bsplinePoint: (step, ctrls) ->\r\n # Basis matrix:\r\n # { -1.0/6.0, 3.0/6.0, -3.0/6.0, 1.0/6.0 },\r\n # { 3.0/6.0, -6.0/6.0, 3.0/6.0, 0.0 },\r\n # { -3.0/6.0, 0.0, 3.0/6.0, 0.0 },\r\n # { 1.0/6.0, 4.0/6.0, 1.0/6.0, 0.0 }\r\n\r\n t = step[0]\r\n t2 = step[1]\r\n t3 = step[2]\r\n\r\n h1 = ( -0.16666666666*t3 + 0.5*t2 - 0.5*t + 0.16666666666 )\r\n h2 = ( 0.5*t3 - t2 + 0.66666666666 )\r\n h3 = ( -0.5*t3 + 0.5*t2 + 0.5*t + 0.16666666666 )\r\n h4 = (0.16666666666*t3)\r\n\r\n x = ( h1*ctrls.p0.x + h2* ctrls.p1.x + h3*ctrls.p2.x + h4*ctrls.p3.x )\r\n y = ( h1*ctrls.p0.y + h2* ctrls.p1.y + h3*ctrls.p2.y + h4*ctrls.p3.y )\r\n z = if !@is3D then 0 else ( h1*ctrls.p0.z + h2* ctrls.p1.z + h3*ctrls.p2.z + h4*ctrls.p3.z )\r\n\r\n return new Point(x,y,z)\r\n\r\n\r\n # ## Interpolate to get a point on B-Spline curve with tension (Duff)\r\n # @param `step` the point to interpolate, as an array of `[t, t*t, t*t*t]` where `t` is between 0 to 1\r\n # @param `ctrls` the control points which can be provided by `controlPoints()` function\r\n # @param `tension` optional value between 0 to 1 to specify a \"tension\". Default to 1 which is the normal tension.\r\n # @return a Point on the curve\r\n bsplineTensionPoint: (step, ctrls, tension=1) ->\r\n # Basis matrix:\r\n # [ -1/6a, 2 - 1.5a, 1.5a - 2, 1/6a ]\r\n # [ 0.5a, 2a-3, 3-2.5a 0 ]\r\n # [ -0.5a, 0, 0.5a, 0 ]\r\n # [ 1/6a, 1 - 1/3a, 1/6a, 0 ]\r\n\r\n t = step[0]\r\n t2 = step[1]\r\n t3 = step[2]\r\n\r\n h1 = tension * ( -0.16666666666*t3 + 0.5*t2 - 0.5*t + 0.16666666666 )\r\n h2 = tension * ( -1.5*t3 + 2*t2 - 0.33333333333 )\r\n h2a = (2*t3 - 3*t2 + 1)\r\n h3 = tension * ( 1.5*t3 - 2.5*t2 + 0.5*t + 0.16666666666 )\r\n h3a = (-2*t3 + 3*t2)\r\n h4 = tension * (0.16666666666*t3)\r\n\r\n x = ( h1*ctrls.p0.x + h2*ctrls.p1.x + h2a*ctrls.p1.x + h3*ctrls.p2.x + h3a*ctrls.p2.x + h4*ctrls.p3.x )\r\n y = ( h1*ctrls.p0.y + h2*ctrls.p1.y + h2a*ctrls.p1.y + h3*ctrls.p2.y + h3a*ctrls.p2.y + h4*ctrls.p3.y )\r\n z = if !@is3D then 0 else ( h1*ctrls.p0.z + h2* ctrls.p1.z + h2a*ctrls.p1.y + h3*ctrls.p2.z + h3a*ctrls.p2.z + h4*ctrls.p3.z )\r\n\r\n return new Point(x,y,z)\r\n\r\n\r\n# namespace\r\nthis.Curve = Curve\n# ### There are so many ways to construct, and to dissect, a triangle. Various center points, circle inner or outer, imaginary lines cutting through its interiors, bisecting angles or sides, and yet it seems perfectly poised with its three sides and 180 degrees internal angles. A triangle encapsulates tension and plasticity.\r\nclass Triangle extends Vector\r\n\r\n # ## Create a new triangle\r\n # @param Set the triangle's anchor point using 0 to 3 values. Can be comma-separated values, as an array, or as an object with `{x, y, z}` properties.\r\n # @eg `new Triangle()` `new Triangle(1,2,3)` `new Triangle([2,4])` `new Triangle({x:3, y:6, z:9})`\r\n # @return a new Triangle object\r\n constructor: () ->\r\n super\r\n\r\n # ## a vertice (corner point) of the triangle as Vector object\r\n @p1 = new Vector( @x-1, @y-1, @z)\r\n\r\n # ## another vertice (corner point) of the triangle as Vector object\r\n @p2 = new Vector( @x+1, @y+1, @z)\r\n\r\n\r\n # ## Connect triangle's anchor point with the other two points\r\n # @param Parameters can be 2 objects or 2 arrays, or 4 or 6 numeric values to specify x, y, and optionally z positions\r\n # @eg `tri.to( p1, p2)` `tri.to([1,2], [3,4]` `tri.to(1,2,3,4)` `tri.to(1,3,5,2,4,6)`\r\n # @return this triangle\r\n to:( args ) ->\r\n\r\n if arguments.length > 0\r\n\r\n # by object or array\r\n if typeof arguments[0] is 'object' and arguments.length == 2\r\n @p1.set( arguments[0] )\r\n @p2.set( arguments[1] )\r\n\r\n # by 4 or 6 numeric values\r\n else\r\n if arguments.length < 6\r\n @p1.set( [arguments[0], arguments[1]] )\r\n @p2.set( [arguments[2], arguments[3]] )\r\n else\r\n @p1.set( [arguments[0], arguments[1], arguments[2]] )\r\n @p2.set( [arguments[3], arguments[4], arguments[5]] )\r\n\r\n return @\r\n\r\n\r\n # ## Convert this triangle's points to an array of Vectors\r\n # @return an array of 3 vectors\r\n toArray: () -> [@, @p1, @p2 ]\r\n\r\n\r\n # ## Get a text string that describes this triangle\r\n toString:() -> \"Triangle (#{@x}, #{@y}, #{@z}), (#{@p1.x}, #{@p1.y}, #{@p1.z}), (#{@p2.x}, #{@p2.y}, #{@p2.z})\"\r\n\r\n\r\n # ## Get a point from the set of points based on its index position\r\n # @param `index` index position as number (0, 1, 2) or as string \"p0\", \"p1\", \"p2\"\r\n # @return a point in the triangle\r\n getAt: (index) ->\r\n if (index==1 or index==\"p1\") then return @p1;\r\n if (index==2 or index==\"p2\") then return @p2;\r\n return @;\r\n\r\n\r\n # ## Same as `getAt()` but return as a new Vector\r\n $getAt: (index) -> return new Vector( @getAt(index) );\r\n\r\n\r\n # ## Convert this Triangle to a `PointSet`\r\n # @return a PointSet with 3 points.\r\n toPointSet: () ->\r\n p0 = new Vector(@)\r\n return new PointSet( p0 ).to( [p0, @p1, @p2 ] )\r\n\r\n\r\n # ## Get an array of Lines that represents this triangle's 3 sides\r\n # @return an array of 3 lines\r\n sides: () ->\r\n return [\r\n new Line(@).to(@p1)\r\n new Line(@p1).to(@p2)\r\n new Line(@p2).to(@)\r\n ]\r\n\r\n\r\n # ## Get the triangle's 3 angles\r\n # @param `axis` optional axis id (eg, `Const.yz`) to specify a plane\r\n # @return an array of 3 angles\r\n angles: ( axis=Const.xy ) ->\r\n angles = [\r\n @p2.$subtract( @ ).angleBetween( @p1.$subtract( @ ), axis )\r\n @$subtract( @p1 ).angleBetween( @p2.$subtract( @p1 ), axis )\r\n ]\r\n angles.push( Math.PI - angles[0] - angles[1] )\r\n return angles\r\n\r\n\r\n # ## Get the medial, which is an inner triangle formed by connecting the midpoints of this triangle's sides\r\n # @return the medial triangle\r\n medial: () ->\r\n sides = @sides()\r\n pts = ( side.midpoint() for side in sides )\r\n return new Triangle( pts[0] ).to( pts[1], pts[2] )\r\n\r\n\r\n # ## Get this triangle's perimeter, which is the length of its 3 sides\r\n # @return an object with 3 properties, where `.value` is the perimeter value, `.sides` is an array of 3 sides, `lengths` is an array of the 3 sides' lengths\r\n perimeter: () ->\r\n sides = @sides()\r\n lens = [\r\n sides[0].length()\r\n sides[1].length()\r\n sides[2].length()\r\n ]\r\n return {\r\n sides: sides\r\n value: lens[0] + lens[1] + lens[2]\r\n lengths: lens\r\n }\r\n\r\n\r\n # ## Get this triangle's area using Heron's formula for calculating polygon area\r\n # @return an object with 2 properties, where `.value` is the area value, and `.perimeter` is an object returned by `perimeter()` function\r\n area: () ->\r\n p = @perimeter()\r\n hp = p.value / 2\r\n return {\r\n value: Math.sqrt( (hp * (hp-p.lengths[0]) * (hp-p.lengths[1]) * (hp-p.lengths[2]) ))\r\n perimeter: p\r\n }\r\n\r\n\r\n # ## Given a point of the triangle, the opposite side is the side which the point doesn't touch\r\n # @param specify a point by its id `\"p0\"` (the anchor point), `\"p1\"`, or `\"p2\"`\r\n # @eg `tri.oppositeSide(\"p1\")`\r\n # @demo triangle.oppositeSide\r\n # @return a Line which represents the opposite side\r\n oppositeSide: ( id ) ->\r\n if id==\"p1\"\r\n return new Line(@).to(@p2)\r\n else if id == \"p2\"\r\n return new Line(@).to(@p1)\r\n else\r\n return new Line(@p1).to(@p2)\r\n\r\n\r\n # ## Given a point of the triangle, the adjacent sides are the two side which the point touches\r\n # @param specify a point by its id `\"p0\"` (the anchor point), `\"p1\"`, or `\"p2\"`\r\n # @eg `tri.adjacentSides(\"p1\")`\r\n # @return an array of 2 Line which represents the adjacent sides\r\n adjacentSides: (id) ->\r\n if id==\"p1\"\r\n return [new Line(@p1).to(@), new Line(@p1).to(@p2)]\r\n else if id == \"p2\"\r\n return [new Line(@p2).to(@), new Line(@p2).to(@p1)]\r\n else\r\n return [new Line(@).to(@p1), new Line(@).to(@p2)]\r\n\r\n\r\n # ## Get a bisector, which is a path that splits a triangle's angle in half.\r\n # @param the first paramter specifies a point by its id `\"p0\"`, `\"p1\"`, or `\"p2\"`. The second parameter determines if the path should be a simple vector from origin (`false`) or a line connected to the triangle's point (`true`). Optionally include a third parameter to set the length of the path.\r\n # @eg `tri.bisector(\"p1\")`, `tri.bisector(\"p0\", true)`, `tri.bisector(\"p2\", false, 10)`\r\n # @return either a Line or a Vector, based on the second parameter\r\n bisector: (id, asLine=false, size=100) ->\r\n ad = @adjacentSides(id)\r\n p = new Vector(ad[0])\r\n ad[0].moveTo(0,0)\r\n ad[1].moveTo(0,0)\r\n bp = ad[0].p1.bisect(ad[1].p1) # bisect vector from origin\r\n\r\n return if asLine then new Line(p).to( bp.multiply(size).add(p) ) else bp\r\n\r\n\r\n # ## Get a triangle's altitude, which is a line from a triangle's point to its opposite side, and perpendicular to its opposite side.\r\n # @param specify a point by its id `\"p0\"` (the anchor point), `\"p1\"`, or `\"p2\"`\r\n # @eg `tri.altitude(\"p1\")` gets a line from p1 to the side formed by p0 and p2\r\n # @return a Line representing an altitude\r\n altitude: ( id ) ->\r\n if id==\"p1\" or id==\"p2\"\r\n return new Line(@[id]).to( @oppositeSide(id).getPerpendicularFromPoint( @[id] ) )\r\n else\r\n return new Line(@).to( @oppositeSide().getPerpendicularFromPoint( @ ) )\r\n\r\n\r\n # ## Get a triangle's centroid, which is the averge positions of its three points.\r\n # @return the centroid point as Vector\r\n centroid : () ->\r\n c0 = @$divide(3)\r\n c1 = @p1.$divide(3)\r\n c2 = @p2.$divide(3)\r\n return new Vector(c0.x+c1.x+c2.x, c0.y+c1.y+c2.y, c0.z+c1.z+c2.z)\r\n\r\n\r\n # ## Get orthocenter, which is the intersection point of a triangle's 3 altitudes (the 3 lines that are perpendicular to its 3 opposite sides).\r\n # @return the orthocenter point as Vector\r\n orthocenter: () ->\r\n a = @altitude()\r\n b = @altitude(\"p1\")\r\n return a.intersectPath( b, Const.xyz )\r\n\r\n\r\n # ## Get incenter, which is the center point of its inner circle, and also the intersection point of its 3 angle bisector lines (each of which cuts one of the 3 angles in half).\r\n # @demo triangle.incenter\r\n # @return the incenter point as Vector\r\n incenter: () ->\r\n a = @bisector(\"p0\", true)\r\n b = @bisector(\"p1\", true)\r\n return a.intersectPath( b, Const.xyz )\r\n\r\n\r\n # ## Get an interior circle, which is the largest circle completed enclosed by this triangle\r\n # @return a Circle\r\n incircle: () ->\r\n center = @incenter()\r\n area = @area()\r\n radius = 2 * area.value / area.perimeter.value\r\n return new Circle(center).setRadius( radius )\r\n\r\n\r\n # ## Get circumcenter, which is the intersection point of its 3 perpendicular bisectors lines ( each of which divides a side in half and is perpendicular to the side)\r\n # @return an object with { `center`: circumcenter point as Vector, `bisector`: an array of bisectors }\r\n circumcenter: () ->\r\n medial = @medial()\r\n\r\n # find perpendicular bisectors\r\n pbs = [\r\n new Line( medial ).to( @.$subtract( medial ).perpendicular()[0].$add(medial) )\r\n new Line( medial.p1 ).to( @p1.$subtract( medial.p1 ).perpendicular()[0].$add(medial.p1) )\r\n new Line( medial.p2 ).to( @p2.$subtract( medial.p2 ).perpendicular()[0].$add(medial.p2) )\r\n ]\r\n\r\n return {\r\n center: pbs[0].intersectPath( pbs[1], Const.xyz )\r\n bisectors: pbs\r\n }\r\n\r\n\r\n # ## Get circumcircle, which is the smaller circle that encloses this triangle completely\r\n # @return a Circle\r\n circumcircle: () ->\r\n center = @circumcenter()\r\n r = @magnitude( center.center )\r\n return new Circle( center.center ).setRadius( r )\r\n\r\n\r\n intersectPoint: (p) ->\r\n sides = @sides()\r\n hp = ( s.collinear(p) > 0 for s in sides ) # check left or right sides of the half plane\r\n return hp[0] == hp[1] and hp[1] == hp[2]\r\n\r\n\r\n # ## Check intersections between this Triangle and an infinite Line on xy axis.\r\n # @param `path` a Pair or Line object to specify an infinite line\r\n # @param `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero or two points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectPath: (path, get_pts=true, axis=Const.xy) ->\r\n sides = @sides()\r\n pts = []\r\n for s in sides\r\n p = s.intersectPath( path )\r\n if p and s.withinBounds( p, axis )\r\n if !get_pts then return true\r\n pts.push( p )\r\n\r\n return if get_pts then pts else false\r\n\r\n\r\n # ## Check intersections between this Triangle and a Line segment on xy axis.\r\n # @param `line` a Line to check\r\n # @param `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero, one, or two points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectLine: (line, get_pts=true, axis=Const.xy) ->\r\n ins = @intersectPath( line, true, axis )\r\n pts = []\r\n for p in ins\r\n if line.withinBounds( p )\r\n if !get_pts then return true\r\n pts.push( p )\r\n\r\n return if get_pts then pts else false\r\n\r\n\r\n # ## Check if this Triangle intersects with a set of Lines on xy axis\r\n # @param `lines` an array of Line\r\n # @param `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points, or a boolean value. (Based on `get_pts` parameter)\r\n intersectLines: (lines, get_pts=true) ->\r\n return Line.intersectLines( @, lines, get_pts )\r\n\r\n\r\n # ## Moller-Trumbore algorithm for 3D ray triangle intersection\r\n intersectPath3D: (path, get_pts) ->\r\n e1 = @p1.$subtract(@)\r\n e2 = @p2.$subtract(@)\r\n dir = path.direction().normalize()\r\n\r\n pvec = dir.cross(e2)\r\n det = e1.dot(pvec)\r\n\r\n # 3D only, in 2D the det is always 0\r\n if (det > -Const.epsilon and det < Const.epsilon ) then return false\r\n\r\n inv_det = 1 / det\r\n\r\n tvec = path.$subtract(@)\r\n u = tvec.dot(pvec) * inv_det\r\n if (u < 0 or u > 1) then return false\r\n\r\n qvec = tvec.cross( e1 )\r\n v = dir.dot(qvec) * inv_det\r\n if (v < 0 or v > 1) then return false\r\n\r\n t = e2.dot( qvec ) * inv_det\r\n if t > Const.epsilon\r\n return if get_pts then [u,v,t] else true\r\n else\r\n return false\r\n\r\n\r\n # ## Check if this Triangle intersects with a Rectangle\r\n # @param `rect` a Rectangle to check\r\n # @param `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero or two or four points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectRectangle: (rect, get_pts=true) ->\r\n return rect.intersectLines( @sides(), get_pts )\r\n\r\n\r\n # ## Check if this Triangle intersects with another Circle\r\n # @param `circle` a Circle to check\r\n # @param `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero or two or four points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectCircle: (circle, get_pts=true) ->\r\n return circle.intersectLines( @sides(), get_pts )\r\n\r\n\r\n # ## Check if this Triangle intersects with another Triangle\r\n # @param `tri` a Triangle to check\r\n # @param `get_pts` a boolean value to specify whether the results should include the intersection points. If `false`, then only the intersection state (true or false) will be returned.\r\n # @returns an Array of intersection points (zero or two or four points), or a boolean value. (Based on `get_pts` parameter)\r\n intersectTriangle: (tri, get_pts=true) ->\r\n return tri.intersectLines( @sides(), get_pts )\r\n\r\n\r\n # overrides clone\r\n clone: () -> new Triangle(@).to( @p1, @p2 )\r\n\r\n\r\n# namespace\r\nthis.Triangle = Triangle\r\n\r\n"]} \ No newline at end of file diff --git a/docs/json/core/CanvasSpace.json b/docs/json/core/CanvasSpace.json index f703100..3a32a7b 100644 --- a/docs/json/core/CanvasSpace.json +++ b/docs/json/core/CanvasSpace.json @@ -8,10 +8,10 @@ "description": "

Create a CanvasSpace which represents a HTML Canvas Space

", "name": "CanvasSpace", "param": [ - "

id an optional string which refers to the \"id\" attribute of a DOM element. It can either refer to an existing <canvas>, or a <div> container in which a new <canvas> will be created. If left empty, a <div id=\"pt_container\"><canvas id=\"pt\" /></div> will be added to DOM. Use css to customize its appearance if needed.

", + "

elem Either a string which refers to the \"id\" attribute of a Canvas element, or the Canvas element itself. It can either refer to an existing <canvas>, or a <div> container in which a new <canvas> will be created. If left empty, a <div id=\"pt_container\"><canvas id=\"pt\" /></div> will be added to DOM. Use css to customize its appearance if needed.

", "

callback an optional callback function(boundingBox, spaceElement) to be called when canvas is appended and ready. A \"ready\" event will also be fired from the <canvas> element when it's appended, which can be traced with spaceInstance.space.addEventListener(\"ready\")

" ], - "pname": "id, callback" + "pname": "elem, callback" }, { "description": "

display(...) is deprecated as of 0.2.0. You can now set the canvas element directly in the constructor, and customize it using setup().

", diff --git a/docs/json/core/Color.json b/docs/json/core/Color.json index fe253b6..3d1d520 100644 --- a/docs/json/core/Color.json +++ b/docs/json/core/Color.json @@ -66,6 +66,11 @@ } ], "props": [ + { + "description": "

alpha value from 0 to 1, where 0 is fully transparent, and 1 is fully opaque

", + "name": "alpha", + "param": [] + }, { "description": "

color mode id such as \"lab\" or \"rgb\"

", "name": "mode", diff --git a/docs/json/core/DOMSpace.json b/docs/json/core/DOMSpace.json index 8c67a8d..861b1dd 100644 --- a/docs/json/core/DOMSpace.json +++ b/docs/json/core/DOMSpace.json @@ -8,11 +8,11 @@ "description": "

Create a DOMSpace which represents a HTML DOM

", "name": "DOMSpace", "param": [ - "

id an id property which refers to the \"id\" attribute of the element in DOM.

", + "

elem Either a string which refers to the \"id\" attribute of a DOM element, or the DOM element itself.

", "

callback an optional callback function(boundingBox, spaceElement) to be called when element is appended and ready. A \"ready\" event will also be fired from the space's element when it's appended, which can be tracked with spaceInstance.space.addEventListener(\"ready\")

", - "

spaceElement a string of space's dom element name, such as \"div\" or \"svg\" or . Default is \"div\"

" + "

spaceElement an optional string of space's dom element name, such as \"div\" or \"svg\" or . Default is \"div\"

" ], - "pname": "id, callback, spaceElement=\"div\"" + "pname": "elem, callback, spaceElement=\"div\"" }, { "description": "

display(...) is deprecated as of 0.2.0. You can now set the DOM element directly in the constructor, and customize it using setup().

", diff --git a/docs/json/core/SVGSpace.json b/docs/json/core/SVGSpace.json index 3e23ec6..9999602 100644 --- a/docs/json/core/SVGSpace.json +++ b/docs/json/core/SVGSpace.json @@ -8,7 +8,7 @@ "description": "

Create a SVGSpace which represents a svg element

", "name": "SVGSpace", "param": [ - "

id an optional string which refers to the \"id\" attribute of a DOM element. It can either refer to an existing <svg>, or a <div> container in which a new <svg> will be created. If left empty, a <div id=\"pt\"><svg id=\"pt_svg\" /></div> will be added to DOM. Use css to customize its appearance if needed.

", + "

id Either a string which refers to the \"id\" attribute of a DOM element, or the DOM element itself. It can either refer to an existing <svg>, or a <div> container in which a new <svg> will be created. If left empty, a <div id=\"pt\"><svg id=\"pt_svg\" /></div> will be added to DOM. Use css to customize its appearance if needed.

", "

callback an optional callback function(boundingBox, spaceElement) to be called when element is appended and ready. A \"ready\" event will also be fired from the space's element when it's appended, which can be tracked with spaceInstance.space.addEventListener(\"ready\")

" ], "pname": "id, callback" diff --git a/docs/json/core/all.json b/docs/json/core/all.json index 2970eba..66cb41b 100644 --- a/docs/json/core/all.json +++ b/docs/json/core/all.json @@ -9,10 +9,10 @@ "description": "

Create a CanvasSpace which represents a HTML Canvas Space

", "name": "CanvasSpace", "param": [ - "

id an optional string which refers to the \"id\" attribute of a DOM element. It can either refer to an existing <canvas>, or a <div> container in which a new <canvas> will be created. If left empty, a <div id=\"pt_container\"><canvas id=\"pt\" /></div> will be added to DOM. Use css to customize its appearance if needed.

", + "

elem Either a string which refers to the \"id\" attribute of a Canvas element, or the Canvas element itself. It can either refer to an existing <canvas>, or a <div> container in which a new <canvas> will be created. If left empty, a <div id=\"pt_container\"><canvas id=\"pt\" /></div> will be added to DOM. Use css to customize its appearance if needed.

", "

callback an optional callback function(boundingBox, spaceElement) to be called when canvas is appended and ready. A \"ready\" event will also be fired from the <canvas> element when it's appended, which can be traced with spaceInstance.space.addEventListener(\"ready\")

" ], - "pname": "id, callback" + "pname": "elem, callback" }, { "description": "

display(...) is deprecated as of 0.2.0. You can now set the canvas element directly in the constructor, and customize it using setup().

", @@ -246,6 +246,11 @@ } ], "props": [ + { + "description": "

alpha value from 0 to 1, where 0 is fully transparent, and 1 is fully opaque

", + "name": "alpha", + "param": [] + }, { "description": "

color mode id such as \"lab\" or \"rgb\"

", "name": "mode", @@ -712,11 +717,11 @@ "description": "

Create a DOMSpace which represents a HTML DOM

", "name": "DOMSpace", "param": [ - "

id an id property which refers to the \"id\" attribute of the element in DOM.

", + "

elem Either a string which refers to the \"id\" attribute of a DOM element, or the DOM element itself.

", "

callback an optional callback function(boundingBox, spaceElement) to be called when element is appended and ready. A \"ready\" event will also be fired from the space's element when it's appended, which can be tracked with spaceInstance.space.addEventListener(\"ready\")

", - "

spaceElement a string of space's dom element name, such as \"div\" or \"svg\" or . Default is \"div\"

" + "

spaceElement an optional string of space's dom element name, such as \"div\" or \"svg\" or . Default is \"div\"

" ], - "pname": "id, callback, spaceElement=\"div\"" + "pname": "elem, callback, spaceElement=\"div\"" }, { "description": "

display(...) is deprecated as of 0.2.0. You can now set the DOM element directly in the constructor, and customize it using setup().

", @@ -2829,7 +2834,7 @@ "description": "

Create a SVGSpace which represents a svg element

", "name": "SVGSpace", "param": [ - "

id an optional string which refers to the \"id\" attribute of a DOM element. It can either refer to an existing <svg>, or a <div> container in which a new <svg> will be created. If left empty, a <div id=\"pt\"><svg id=\"pt_svg\" /></div> will be added to DOM. Use css to customize its appearance if needed.

", + "

id Either a string which refers to the \"id\" attribute of a DOM element, or the DOM element itself. It can either refer to an existing <svg>, or a <div> container in which a new <svg> will be created. If left empty, a <div id=\"pt\"><svg id=\"pt_svg\" /></div> will be added to DOM. Use css to customize its appearance if needed.

", "

callback an optional callback function(boundingBox, spaceElement) to be called when element is appended and ready. A \"ready\" event will also be fired from the space's element when it's appended, which can be tracked with spaceInstance.space.addEventListener(\"ready\")

" ], "pname": "id, callback" diff --git a/src/coffee/core/CanvasSpace.coffee b/src/coffee/core/CanvasSpace.coffee index d5b063b..ab98abd 100644 --- a/src/coffee/core/CanvasSpace.coffee +++ b/src/coffee/core/CanvasSpace.coffee @@ -3,13 +3,14 @@ class CanvasSpace extends Space # ## Create a CanvasSpace which represents a HTML Canvas Space - # @param `id` an optional string which refers to the "id" attribute of a DOM element. It can either refer to an existing ``, or a `
` container in which a new `` will be created. If left empty, a `
` will be added to DOM. Use css to customize its appearance if needed. + # @param `elem` Either a string which refers to the "id" attribute of a Canvas element, or the Canvas element itself. It can either refer to an existing ``, or a `
` container in which a new `` will be created. If left empty, a `
` will be added to DOM. Use css to customize its appearance if needed. # @param `callback` an optional callback `function(boundingBox, spaceElement)` to be called when canvas is appended and ready. A "ready" event will also be fired from the `` element when it's appended, which can be traced with `spaceInstance.space.addEventListener("ready")` - constructor : ( id, callback ) -> - if (!id) then id = 'pt' - super( id ) + constructor : ( elem, callback ) -> + if (!elem) then elem = 'pt' - @id = if (@id[0] == "#") then @id.substr(1) else @id + isElement = elem instanceof Element + + super( if (isElement) then "pt_custom_space" else elem ) # ## A property to store canvas DOM element @space = null @@ -19,8 +20,15 @@ class CanvasSpace extends Space @pixelScale = 1 @_autoResize = true - _selector = document.querySelector("#"+@id) - _existed = true + _selector = null + + if (isElement) + _selector = elem + else + @id = if (@id[0] == "#") then @id.substr(1) else @id + _selector = document.querySelector("#"+@id) + _existed = true + # if selector is not defined, create a canvas if !_selector diff --git a/src/coffee/core/Color.coffee b/src/coffee/core/Color.coffee index feaa54d..055fabf 100644 --- a/src/coffee/core/Color.coffee +++ b/src/coffee/core/Color.coffee @@ -9,8 +9,9 @@ class Color extends Vector constructor: ( args ) -> super - # ## alpha value from 0 to 1, where 0 is fully transparent, and 1 is fully opaque _args = if ( Array.isArray(arguments[0]) and arguments[0][3] != undefined ) then arguments[0] else arguments + + # ## alpha value from 0 to 1, where 0 is fully transparent, and 1 is fully opaque @alpha = if _args.length >=4 then Math.min( 1, Math.max( _args[3], 0) ) else 1 # ## color mode id such as "lab" or "rgb" diff --git a/src/coffee/core/DOMSpace.coffee b/src/coffee/core/DOMSpace.coffee index 682c066..493a65b 100644 --- a/src/coffee/core/DOMSpace.coffee +++ b/src/coffee/core/DOMSpace.coffee @@ -3,14 +3,15 @@ class DOMSpace extends Space # ## Create a DOMSpace which represents a HTML DOM - # @param `id` an id property which refers to the "id" attribute of the element in DOM. + # @param `elem` Either a string which refers to the "id" attribute of a DOM element, or the DOM element itself. # @param `callback` an optional callback `function(boundingBox, spaceElement)` to be called when element is appended and ready. A "ready" event will also be fired from the space's element when it's appended, which can be tracked with `spaceInstance.space.addEventListener("ready")` - # @param `spaceElement` a string of space's dom element name, such as `"div"` or `"svg"` or . Default is `"div"` - constructor: ( id, callback, spaceElement="div" ) -> - if (!id) then id = 'pt' - super( id ) + # @param `spaceElement` an optional string of space's dom element name, such as `"div"` or `"svg"` or . Default is `"div"` + constructor: ( elem, callback, spaceElement="div" ) -> + if (!elem) then elem = 'pt' + + isElement = elem instanceof Element - @id = if (@id[0] == "#") then @id.substr(1) else @id + super( if (isElement) then "pt_custom_space" else elem ) # ## A property to store the DOM element @space = null @@ -19,7 +20,14 @@ class DOMSpace extends Space @css = {}; - _selector = document.querySelector("#"+@id) + _selector = null + + if (isElement) + _selector = elem + else + @id = if (@id[0] == "#") then @id.substr(1) else @id + _selector = document.querySelector("#"+@id) + # if selector is not defined, create the spaceElement element if !_selector diff --git a/src/coffee/core/SVGSpace.coffee b/src/coffee/core/SVGSpace.coffee index 4ff40b1..29a35ea 100644 --- a/src/coffee/core/SVGSpace.coffee +++ b/src/coffee/core/SVGSpace.coffee @@ -2,7 +2,7 @@ class SVGSpace extends DOMSpace # ## Create a SVGSpace which represents a svg element - # @param `id` an optional string which refers to the "id" attribute of a DOM element. It can either refer to an existing ``, or a `
` container in which a new `` will be created. If left empty, a `
` will be added to DOM. Use css to customize its appearance if needed. + # @param `id` Either a string which refers to the "id" attribute of a DOM element, or the DOM element itself. It can either refer to an existing ``, or a `
` container in which a new `` will be created. If left empty, a `
` will be added to DOM. Use css to customize its appearance if needed. # @param `callback` an optional callback `function(boundingBox, spaceElement)` to be called when element is appended and ready. A "ready" event will also be fired from the space's element when it's appended, which can be tracked with `spaceInstance.space.addEventListener("ready")` constructor: ( id, callback ) -> super( id, callback, 'svg')