BShape: move bounding box method to shape_data

* Makes it easier to get the bounding box from inside app_server
This commit is contained in:
Julian Harnath 2015-11-09 18:09:22 +01:00
parent 08135223ce
commit ab12093685
2 changed files with 31 additions and 26 deletions

View File

@ -27,6 +27,36 @@ struct shape_data {
BPoint* ptList;
int32 ptCount;
int32 ptSize;
BRect DetermineBoundingBox() const
{
BRect bounds;
if (ptCount == 0)
return bounds;
// TODO: This implementation doesn't take into account curves at all.
bounds.left = ptList[0].x;
bounds.top = ptList[0].y;
bounds.right = ptList[0].x;
bounds.bottom = ptList[0].y;
for (int32 i = 1; i < ptCount; i++) {
if (bounds.left > ptList[i].x)
bounds.left = ptList[i].x;
if (bounds.top > ptList[i].y)
bounds.top = ptList[i].y;
if (bounds.right < ptList[i].x)
bounds.right = ptList[i].x;
if (bounds.bottom < ptList[i].y)
bounds.bottom = ptList[i].y;
}
return bounds;
}
};

View File

@ -306,32 +306,7 @@ BRect
BShape::Bounds() const
{
shape_data* data = (shape_data*)fPrivateData;
BRect bounds;
if (data->ptCount == 0)
return bounds;
// TODO: This implementation doesn't take into account curves at all.
bounds.left = data->ptList[0].x;
bounds.top = data->ptList[0].y;
bounds.right = data->ptList[0].x;
bounds.bottom = data->ptList[0].y;
for (int32 i = 1; i < data->ptCount; i++) {
if (bounds.left > data->ptList[i].x)
bounds.left = data->ptList[i].x;
if (bounds.top > data->ptList[i].y)
bounds.top = data->ptList[i].y;
if (bounds.right < data->ptList[i].x)
bounds.right = data->ptList[i].x;
if (bounds.bottom < data->ptList[i].y)
bounds.bottom = data->ptList[i].y;
}
return bounds;
return data->DetermineBoundingBox();
}