Simple 2D shape generators
A simple set of geometric shape generators, starting with the simple stuff.
Create a polygon starting and ending at [0, 0] with
n sides of
l. Allows partial application (i.e. if
l is not supplied a
l and generating the poly will be returned).
Like other functions in the shape toolbox, clamping defaults to true.
var poly = ;// generate a squareconsole;// --> [ [ 0, 0 ], [ 0, 100 ], [ 100, 100 ], [ 100, 0 ], [ 0, 0 ] ]// generate a triangleconsole;// --> [ [ 0, 0 ], [ 0, 100 ], [ 86, 50 ], [ 0, 0 ] ]// generate a triangle with no clampingconsole;// --> [ [ 0, 0 ], [ 0, 100 ], [ 86.60254037844388, 50.00000000000002 ], [ 4.263256414560601e-14, -2.1316282072803006e-14 ] ]
For those times you don't want to type poly(4) we do it for you.
var square = ;// generate a squareconsole;// --> [ [ 0, 0 ], [ 0, 100 ], [ 100, 100 ], [ 100, 0 ], [ 0, 0 ] ]// generate an unclamped squareconsole;// --> [ [ 0, 0 ], [ 0, 25.5 ], [ 25.5, 25.5 ], [ 25.500000000000004, 0 ], [ 3.552713678800501e-15, -4.684119303370593e-15 ] ]
Copyright (c) 2013 Damon Oehlman firstname.lastname@example.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.