add: Geometry::GetBoundingBox & Geometry::ComputeArea

This commit is contained in:
Haibo 2018-11-20 15:00:01 +08:00 committed by Nomango
parent 92711b411a
commit e435d94e4e
3 changed files with 41 additions and 0 deletions

View File

@ -36,6 +36,20 @@ namespace easy2d
{
}
Rect Geometry::GetBoundingBox()
{
if (!geo_)
return Rect{};
D2D1_RECT_F rect;
// no matter it failed or not
geo_->GetBounds(
ConvertToD2DMatrix(GetTransformMatrix()),
&rect
);
return rect;
}
float Geometry::GetLength()
{
float length = 0.f;
@ -71,6 +85,20 @@ namespace easy2d
return false;
}
float Geometry::ComputeArea()
{
if (!geo_)
return 0.f;
float area = 0.f;
// no matter it failed or not
geo_->ComputeArea(
ConvertToD2DMatrix(GetTransformMatrix()),
&area
);
return area;
}
bool Geometry::ContainsPoint(Point const & point)
{
if (!geo_)

View File

@ -46,6 +46,9 @@ namespace easy2d
virtual ~Geometry();
// 삿혤棍학관鍋분
Rect GetBoundingBox();
// 判断图形是否包含点
bool ContainsPoint(
Point const& point
@ -66,6 +69,9 @@ namespace easy2d
Point* tangent
);
// 셕炬충생
float ComputeArea();
protected:
cpGeometry geo_;
};

View File

@ -67,6 +67,13 @@ namespace easy2d
, size(other.size.width, other.size.height)
{}
Rect(
const D2D1_RECT_F& other
)
: origin(other.left, other.top)
, size(other.right - other.left, other.bottom - other.top)
{}
Rect& operator= (const Rect& other)
{
origin = other.origin;