lib/toxi/geom/Polygon2D.js
function( count ){
            var num = this.vertices.length,
                longestID = 0,
                maxD = 0,
                i = 0,
                d,
                m;

            while( num < count ){
                //find longest edge
                longestID = 0;
                maxD = 0;
                for( i=0; i<num; i++ ){
                    d = this.vertices[i].distanceToSquared( this.vertices[ (i+1) % num ] );
                    if( d > maxD ){
                        longestID = i;
                        maxD = d;
                    }
                }
                //insert mid point of longest segment
                m = this.vertices[longestID]
                    .add(this.vertices[(longestID + 1) % num])
                    .scaleSelf(0.5);
                //push this into the array inbetween the 2 points
                this.vertices.splice( longestID+1, 0, m );
                num++;
            }
            return this;
        }
function( count ){
            var num = this.vertices.length,
                longestID = 0,
                maxD = 0,
                i = 0,
                d,
                m;

            while( num < count ){
                //find longest edge
                longestID = 0;
                maxD = 0;
                for( i=0; i<num; i++ ){
                    d = this.vertices[i].distanceToSquared( this.vertices[ (i+1) % num ] );
                    if( d > maxD ){
                        longestID = i;
                        maxD = d;
                    }
                }
                //insert mid point of longest segment
                m = this.vertices[longestID]
                    .add(this.vertices[(longestID + 1) % num])
                    .scaleSelf(0.5);
                //push this into the array inbetween the 2 points
                this.vertices.splice( longestID+1, 0, m );
                num++;
            }
            return this;
        }
function ( count ) { var num = this . vertices . length , longestID = 0 , maxD = 0 , i = 0 , d , m ; while ( num < count ) { //find longest edge longestID = 0 ; maxD = 0 ; for ( i = 0 ; i < num ; i ++ ) { d = this . vertices [ i ] . distanceToSquared ( this . vertices [ ( i + 1 ) % num ] ) ; if ( d > maxD ) { longestID = i ; maxD = d ; } } //insert mid point of longest segment m = this . vertices [ longestID ] . add ( this . vertices [ ( longestID + 1 ) % num ] ) . scaleSelf ( 0.5 ) ; //push this into the array inbetween the 2 points this . vertices . splice ( longestID + 1 , 0 , m ) ; num ++ ; } return this ; }
Repeatedly inserts vertices as mid points of the longest edges until the
new vertex count is reached.
@param {Number} count new vertex count
@return itself
Repeatedly inserts vertices as mid points of the longest edges until the new vertex count is reached .