* @return bounding box rectangle.
*/
public static Rect getBounds(List<ShapeRecord> records, LineStyle ls, AbstractStrokeNode strokeNode)
{
if (records == null || records.size() == 0)
return new Rect();
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;
int x = 0;
int y = 0;
boolean firstMove = true;
Iterator<ShapeRecord> iterator = records.iterator();
while (iterator.hasNext())
{
ShapeRecord r = iterator.next();
if (r == null)
continue;
if (r instanceof StyleChangeRecord)
{
StyleChangeRecord scr = (StyleChangeRecord)r;
x = scr.moveDeltaX;
y = scr.moveDeltaY;
if (firstMove)
{
x1 = x;
y1 = y;
x2 = x;
y2 = y;
firstMove = false;
}
}
else if (r instanceof StraightEdgeRecord)
{
StraightEdgeRecord ser = (StraightEdgeRecord)r;
x = x + ser.deltaX;
y = y + ser.deltaY;
}
else if (r instanceof CurvedEdgeRecord)
{
CurvedEdgeRecord cer = (CurvedEdgeRecord)r;
Rect currRect = new Rect(x1, x2, y1, y2);
if (!curveControlPointInsideCurrentRect(x, y, cer, currRect))
{
Rect curvBounds = computeCurveBounds(x, y, cer);
if (curvBounds.xMin < x1) x1 = curvBounds.xMin;
if (curvBounds.yMin < y1) y1 = curvBounds.yMin;
if (curvBounds.xMax > x2) x2 = curvBounds.xMax;
if (curvBounds.yMax > y2) y2 = curvBounds.yMax;
}
x = x + cer.controlDeltaX + cer.anchorDeltaX;
y = y + cer.controlDeltaY + cer.anchorDeltaY;
}
//update x1, y1 to min values and x2, y2 to max values
if (x < x1) x1 = x;
if (y < y1) y1 = y;
if (x > x2) x2 = x;
if (y > y2) y2 = y;
}
Rect newRect = new Rect(x1, x2, y1, y2);
if (ls == null)
{
return newRect;
}
// Inflate the bounding box from all sides with half of the stroke
// weight - pathBBox.inflate(weight/2, weight/2).
Rect strokeExtents = getStrokeExtents(strokeNode, ls);
newRect.xMin -= strokeExtents.xMax;
newRect.yMin -= strokeExtents.yMax;
newRect.xMax += strokeExtents.xMax;
newRect.yMax += strokeExtents.yMax;