mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-19 08:55:32 +01:00
Added new BoundaryUnionBoundary subclass of AreaBoundary, which does what it says on the tin. Hi, sirikfoll.
This commit is contained in:
@@ -24,9 +24,6 @@ RectangleBoundary::RectangleBoundary(float southX, float northX, float eastY, fl
|
||||
AreaBoundary(isInverted), _minX(southX), _maxX(northX), _minY(eastY), _maxY(westY) { }
|
||||
bool RectangleBoundary::IsWithinBoundaryArea(Position const* pos) const
|
||||
{
|
||||
if (!pos)
|
||||
return false;
|
||||
|
||||
return !(
|
||||
pos->GetPositionX() < _minX ||
|
||||
pos->GetPositionX() > _maxX ||
|
||||
@@ -43,9 +40,6 @@ CircleBoundary::CircleBoundary(Position const& center, Position const& pointOnCi
|
||||
AreaBoundary(isInverted), _center(center), _radiusSq(_center.GetDoubleExactDist2dSq(pointOnCircle)) { }
|
||||
bool CircleBoundary::IsWithinBoundaryArea(Position const* pos) const
|
||||
{
|
||||
if (!pos)
|
||||
return false;
|
||||
|
||||
double offX = _center.GetDoublePositionX() - pos->GetPositionX();
|
||||
double offY = _center.GetDoublePositionY() - pos->GetPositionY();
|
||||
return offX*offX+offY*offY <= _radiusSq;
|
||||
@@ -57,10 +51,8 @@ EllipseBoundary::EllipseBoundary(Position const& center, double radiusX, double
|
||||
AreaBoundary(isInverted), _center(center), _radiusYSq(radiusY*radiusY), _scaleXSq(_radiusYSq / (radiusX*radiusX)) { }
|
||||
bool EllipseBoundary::IsWithinBoundaryArea(Position const* pos) const
|
||||
{
|
||||
if (!pos)
|
||||
return false;
|
||||
|
||||
double offX = _center.GetDoublePositionX()-pos->GetPositionX(), offY = _center.GetDoublePositionY()-pos->GetPositionY();
|
||||
double offX = _center.GetDoublePositionX() - pos->GetPositionX();
|
||||
double offY = _center.GetDoublePositionY() - pos->GetPositionY();
|
||||
return (offX*offX)*_scaleXSq + (offY*offY) <= _radiusYSq;
|
||||
}
|
||||
|
||||
@@ -70,9 +62,6 @@ TriangleBoundary::TriangleBoundary(Position const& pointA, Position const& point
|
||||
AreaBoundary(isInverted), _a(pointA), _b(pointB), _c(pointC), _abx(_b.GetDoublePositionX()-_a.GetDoublePositionX()), _bcx(_c.GetDoublePositionX()-_b.GetDoublePositionX()), _cax(_a.GetDoublePositionX() - _c.GetDoublePositionX()), _aby(_b.GetDoublePositionY()-_a.GetDoublePositionY()), _bcy(_c.GetDoublePositionY()-_b.GetDoublePositionY()), _cay(_a.GetDoublePositionY() - _c.GetDoublePositionY()) { }
|
||||
bool TriangleBoundary::IsWithinBoundaryArea(Position const* pos) const
|
||||
{
|
||||
if (!pos)
|
||||
return false;
|
||||
|
||||
// half-plane signs
|
||||
bool sign1 = ((-_b.GetDoublePositionX() + pos->GetPositionX()) * _aby - (-_b.GetDoublePositionY() + pos->GetPositionY()) * _abx) < 0;
|
||||
bool sign2 = ((-_c.GetDoublePositionX() + pos->GetPositionX()) * _bcy - (-_c.GetDoublePositionY() + pos->GetPositionY()) * _bcx) < 0;
|
||||
@@ -88,9 +77,6 @@ ParallelogramBoundary::ParallelogramBoundary(Position const& cornerA, Position c
|
||||
AreaBoundary(isInverted), _a(cornerA), _b(cornerB), _d(cornerD), _c(DoublePosition(_d.GetDoublePositionX() + (_b.GetDoublePositionX() - _a.GetDoublePositionX()), _d.GetDoublePositionY() + (_b.GetDoublePositionY() - _a.GetDoublePositionY()))), _abx(_b.GetDoublePositionX() - _a.GetDoublePositionX()), _dax(_a.GetDoublePositionX() - _d.GetDoublePositionX()), _aby(_b.GetDoublePositionY() - _a.GetDoublePositionY()), _day(_a.GetDoublePositionY() - _d.GetDoublePositionY()) { }
|
||||
bool ParallelogramBoundary::IsWithinBoundaryArea(Position const* pos) const
|
||||
{
|
||||
if (!pos)
|
||||
return false;
|
||||
|
||||
// half-plane signs
|
||||
bool sign1 = ((-_b.GetDoublePositionX() + pos->GetPositionX()) * _aby - (-_b.GetDoublePositionY() + pos->GetPositionY()) * _abx) < 0;
|
||||
bool sign2 = ((-_a.GetDoublePositionX() + pos->GetPositionX()) * _day - (-_a.GetDoublePositionY() + pos->GetPositionY()) * _dax) < 0;
|
||||
@@ -107,8 +93,17 @@ ZRangeBoundary::ZRangeBoundary(float minZ, float maxZ, bool isInverted) :
|
||||
AreaBoundary(isInverted), _minZ(minZ), _maxZ(maxZ) { }
|
||||
bool ZRangeBoundary::IsWithinBoundaryArea(Position const* pos) const
|
||||
{
|
||||
if (!pos)
|
||||
return false;
|
||||
|
||||
return !(pos->GetPositionZ() < _minZ || pos->GetPositionZ() > _maxZ);
|
||||
return (_minZ <= pos->GetPositionZ() && pos->GetPositionZ() <= _maxZ);
|
||||
}
|
||||
|
||||
|
||||
// ---== UNION OF 2 BOUNDARIES ==---
|
||||
BoundaryUnionBoundary::BoundaryUnionBoundary(AreaBoundary const* b1, AreaBoundary const* b2, bool isInverted) :
|
||||
AreaBoundary(isInverted), _b1(b1), _b2(b2)
|
||||
{
|
||||
ASSERT(b1 && b2);
|
||||
}
|
||||
bool BoundaryUnionBoundary::IsWithinBoundaryArea(Position const* pos) const
|
||||
{
|
||||
return (_b1->IsWithinBoundary(pos) || _b2->IsWithinBoundary(pos));
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
class TC_GAME_API AreaBoundary
|
||||
{
|
||||
public:
|
||||
bool IsWithinBoundary(Position const* pos) const { return (IsWithinBoundaryArea(pos) != _isInvertedBoundary); }
|
||||
bool IsWithinBoundary(Position const* pos) const { return pos && (IsWithinBoundaryArea(pos) != _isInvertedBoundary); }
|
||||
bool IsWithinBoundary(Position const& pos) const { return IsWithinBoundary(&pos); }
|
||||
|
||||
virtual ~AreaBoundary() { }
|
||||
@@ -151,4 +151,17 @@ class TC_GAME_API ZRangeBoundary : public AreaBoundary
|
||||
float const _minZ, _maxZ;
|
||||
};
|
||||
|
||||
class TC_GAME_API BoundaryUnionBoundary : public AreaBoundary
|
||||
{
|
||||
public:
|
||||
BoundaryUnionBoundary(AreaBoundary const* b1, AreaBoundary const* b2, bool isInverted = false);
|
||||
|
||||
protected:
|
||||
bool IsWithinBoundaryArea(Position const* pos) const override;
|
||||
|
||||
private:
|
||||
AreaBoundary const* const _b1;
|
||||
AreaBoundary const* const _b2;
|
||||
};
|
||||
|
||||
#endif //TRINITY_AREA_BOUNDARY_H
|
||||
|
||||
Reference in New Issue
Block a user