var utils = require('../../../utils');
/**
* Builds a complex polygon to draw
*
* @private
* @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties
* @param webGLData {object} an object containing all the webGL-specific information to create this shape
*/
var buildComplexPoly = function (graphicsData, webGLData)
{
//TODO - no need to copy this as it gets turned into a FLoat32Array anyways..
var points = graphicsData.points.slice();
if (points.length < 6)
{
return;
}
// get first and last point.. figure out the middle!
var indices = webGLData.indices;
webGLData.points = points;
webGLData.alpha = graphicsData.fillAlpha;
webGLData.color = utils.hex2rgb(graphicsData.fillColor);
// calclate the bounds..
var minX = Infinity;
var maxX = -Infinity;
var minY = Infinity;
var maxY = -Infinity;
var x,y;
// get size..
for (var i = 0; i < points.length; i+=2)
{
x = points[i];
y = points[i+1];
minX = x < minX ? x : minX;
maxX = x > maxX ? x : maxX;
minY = y < minY ? y : minY;
maxY = y > maxY ? y : maxY;
}
// add a quad to the end cos there is no point making another buffer!
points.push(minX, minY,
maxX, minY,
maxX, maxY,
minX, maxY);
// push a quad onto the end..
//TODO - this aint needed!
var length = points.length / 2;
for (i = 0; i < length; i++)
{
indices.push( i );
}
};
module.exports = buildComplexPoly;