From ab12093685e7e4bfe65308914c8d945cd3917970 Mon Sep 17 00:00:00 2001 From: Julian Harnath Date: Mon, 9 Nov 2015 18:09:22 +0100 Subject: [PATCH] BShape: move bounding box method to shape_data * Makes it easier to get the bounding box from inside app_server --- headers/private/interface/ShapePrivate.h | 30 ++++++++++++++++++++++++ src/kits/interface/Shape.cpp | 27 +-------------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/headers/private/interface/ShapePrivate.h b/headers/private/interface/ShapePrivate.h index 38b1beeb20..9fa63448ae 100644 --- a/headers/private/interface/ShapePrivate.h +++ b/headers/private/interface/ShapePrivate.h @@ -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; + } }; diff --git a/src/kits/interface/Shape.cpp b/src/kits/interface/Shape.cpp index 909f8e442d..2819a87e48 100644 --- a/src/kits/interface/Shape.cpp +++ b/src/kits/interface/Shape.cpp @@ -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(); }