Scripts: Remove unneccessary DoublePosition from AreaBoundary
Port From (https://github.com/TrinityCore/TrinityCore/commit/0f5d634e381b2bf6d4062c0ebd31551d98f64a32)
This commit is contained in:
@@ -84,85 +84,83 @@ namespace Game.Maps
|
|||||||
|
|
||||||
public class CircleBoundary : AreaBoundary
|
public class CircleBoundary : AreaBoundary
|
||||||
{
|
{
|
||||||
public CircleBoundary(Position center, double radius, bool isInverted = false) : base(isInverted)
|
public CircleBoundary(Position center, float radius, bool isInverted = false) : base(isInverted)
|
||||||
{
|
{
|
||||||
_center = new DoublePosition(center);
|
_center = new Position(center);
|
||||||
_radiusSq = radius * radius;
|
_radiusSq = radius * radius;
|
||||||
}
|
}
|
||||||
public CircleBoundary(Position center, Position pointOnCircle, bool isInverted = false) : base(isInverted)
|
public CircleBoundary(Position center, Position pointOnCircle, bool isInverted = false) : base(isInverted)
|
||||||
{
|
{
|
||||||
_center = new DoublePosition(center);
|
_center = new Position(center);
|
||||||
_radiusSq = _center.GetDoubleExactDist2dSq(new DoublePosition(pointOnCircle));
|
_radiusSq = _center.GetExactDist2dSq(new Position(pointOnCircle));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsWithinBoundaryArea(Position pos)
|
public override bool IsWithinBoundaryArea(Position pos)
|
||||||
{
|
{
|
||||||
double offX = _center.GetDoublePositionX() - pos.GetPositionX();
|
return _center.GetExactDistSq(pos) <= _radiusSq;
|
||||||
double offY = _center.GetDoublePositionY() - pos.GetPositionY();
|
|
||||||
return offX * offX + offY * offY <= _radiusSq;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DoublePosition _center;
|
Position _center;
|
||||||
double _radiusSq;
|
float _radiusSq;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EllipseBoundary : AreaBoundary
|
public class EllipseBoundary : AreaBoundary
|
||||||
{
|
{
|
||||||
public EllipseBoundary(Position center, double radiusX, double radiusY, bool isInverted = false) : base(isInverted)
|
public EllipseBoundary(Position center, float radiusX, float radiusY, bool isInverted = false) : base(isInverted)
|
||||||
{
|
{
|
||||||
_center = new DoublePosition(center);
|
_center = new Position(center);
|
||||||
_radiusYSq = radiusY * radiusY;
|
_radiusYSq = radiusY * radiusY;
|
||||||
_scaleXSq = _radiusYSq / (radiusX * radiusX);
|
_scaleXSq = _radiusYSq / (radiusX * radiusX);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsWithinBoundaryArea(Position pos)
|
public override bool IsWithinBoundaryArea(Position pos)
|
||||||
{
|
{
|
||||||
double offX = _center.GetDoublePositionX() - pos.GetPositionX();
|
float offX = _center.GetPositionX() - pos.GetPositionX();
|
||||||
double offY = _center.GetDoublePositionY() - pos.GetPositionY();
|
float offY = _center.GetPositionY() - pos.GetPositionY();
|
||||||
return (offX * offX) * _scaleXSq + (offY * offY) <= _radiusYSq;
|
return (offX * offX) * _scaleXSq + (offY * offY) <= _radiusYSq;
|
||||||
}
|
}
|
||||||
|
|
||||||
DoublePosition _center;
|
Position _center;
|
||||||
double _radiusYSq;
|
float _radiusYSq;
|
||||||
double _scaleXSq;
|
float _scaleXSq;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TriangleBoundary : AreaBoundary
|
public class TriangleBoundary : AreaBoundary
|
||||||
{
|
{
|
||||||
public TriangleBoundary(Position pointA, Position pointB, Position pointC, bool isInverted = false) : base(isInverted)
|
public TriangleBoundary(Position pointA, Position pointB, Position pointC, bool isInverted = false) : base(isInverted)
|
||||||
{
|
{
|
||||||
_a = new DoublePosition(pointA);
|
_a = new Position(pointA);
|
||||||
_b = new DoublePosition(pointB);
|
_b = new Position(pointB);
|
||||||
_c = new DoublePosition(pointC);
|
_c = new Position(pointC);
|
||||||
|
|
||||||
_abx = _b.GetDoublePositionX() - _a.GetDoublePositionX();
|
_abx = _b.GetPositionX() - _a.GetPositionX();
|
||||||
_bcx = _c.GetDoublePositionX() - _b.GetDoublePositionX();
|
_bcx = _c.GetPositionX() - _b.GetPositionX();
|
||||||
_cax = _a.GetDoublePositionX() - _c.GetDoublePositionX();
|
_cax = _a.GetPositionX() - _c.GetPositionX();
|
||||||
_aby = _b.GetDoublePositionY() - _a.GetDoublePositionY();
|
_aby = _b.GetPositionY() - _a.GetPositionY();
|
||||||
_bcy = _c.GetDoublePositionY() - _b.GetDoublePositionY();
|
_bcy = _c.GetPositionY() - _b.GetPositionY();
|
||||||
_cay = _a.GetDoublePositionY() - _c.GetDoublePositionY();
|
_cay = _a.GetPositionY() - _c.GetPositionY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsWithinBoundaryArea(Position pos)
|
public override bool IsWithinBoundaryArea(Position pos)
|
||||||
{
|
{
|
||||||
// half-plane signs
|
// half-plane signs
|
||||||
bool sign1 = ((-_b.GetDoublePositionX() + pos.GetPositionX()) * _aby - (-_b.GetDoublePositionY() + pos.GetPositionY()) * _abx) < 0;
|
bool sign1 = ((-_b.GetPositionX() + pos.GetPositionX()) * _aby - (-_b.GetPositionY() + pos.GetPositionY()) * _abx) < 0;
|
||||||
bool sign2 = ((-_c.GetDoublePositionX() + pos.GetPositionX()) * _bcy - (-_c.GetDoublePositionY() + pos.GetPositionY()) * _bcx) < 0;
|
bool sign2 = ((-_c.GetPositionX() + pos.GetPositionX()) * _bcy - (-_c.GetPositionY() + pos.GetPositionY()) * _bcx) < 0;
|
||||||
bool sign3 = ((-_a.GetDoublePositionX() + pos.GetPositionX()) * _cay - (-_a.GetDoublePositionY() + pos.GetPositionY()) * _cax) < 0;
|
bool sign3 = ((-_a.GetPositionX() + pos.GetPositionX()) * _cay - (-_a.GetPositionY() + pos.GetPositionY()) * _cax) < 0;
|
||||||
|
|
||||||
// if all signs are the same, the point is inside the triangle
|
// if all signs are the same, the point is inside the triangle
|
||||||
return ((sign1 == sign2) && (sign2 == sign3));
|
return ((sign1 == sign2) && (sign2 == sign3));
|
||||||
}
|
}
|
||||||
|
|
||||||
DoublePosition _a;
|
Position _a;
|
||||||
DoublePosition _b;
|
Position _b;
|
||||||
DoublePosition _c;
|
Position _c;
|
||||||
double _abx;
|
float _abx;
|
||||||
double _bcx;
|
float _bcx;
|
||||||
double _cax;
|
float _cax;
|
||||||
double _aby;
|
float _aby;
|
||||||
double _bcy;
|
float _bcy;
|
||||||
double _cay;
|
float _cay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ParallelogramBoundary : AreaBoundary
|
public class ParallelogramBoundary : AreaBoundary
|
||||||
@@ -170,36 +168,36 @@ namespace Game.Maps
|
|||||||
// Note: AB must be orthogonal to AD
|
// Note: AB must be orthogonal to AD
|
||||||
public ParallelogramBoundary(Position cornerA, Position cornerB, Position cornerD, bool isInverted = false) : base(isInverted)
|
public ParallelogramBoundary(Position cornerA, Position cornerB, Position cornerD, bool isInverted = false) : base(isInverted)
|
||||||
{
|
{
|
||||||
_a = new DoublePosition(cornerA);
|
_a = new Position(cornerA);
|
||||||
_b = new DoublePosition(cornerB);
|
_b = new Position(cornerB);
|
||||||
_d = new DoublePosition(cornerD);
|
_d = new Position(cornerD);
|
||||||
_c = new DoublePosition(_d.GetDoublePositionX() + (_b.GetDoublePositionX() - _a.GetDoublePositionX()), _d.GetDoublePositionY() + (_b.GetDoublePositionY() - _a.GetDoublePositionY()));
|
_c = new Position(_d.GetPositionX() + (_b.GetPositionX() - _a.GetPositionX()), _d.GetPositionY() + (_b.GetPositionY() - _a.GetPositionY()));
|
||||||
_abx = _b.GetDoublePositionX() - _a.GetDoublePositionX();
|
_abx = _b.GetPositionX() - _a.GetPositionX();
|
||||||
_dax = _a.GetDoublePositionX() - _d.GetDoublePositionX();
|
_dax = _a.GetPositionX() - _d.GetPositionX();
|
||||||
_aby = _b.GetDoublePositionY() - _a.GetDoublePositionY();
|
_aby = _b.GetPositionY() - _a.GetPositionY();
|
||||||
_day = _a.GetDoublePositionY() - _d.GetDoublePositionY();
|
_day = _a.GetPositionY() - _d.GetPositionY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsWithinBoundaryArea(Position pos)
|
public override bool IsWithinBoundaryArea(Position pos)
|
||||||
{
|
{
|
||||||
// half-plane signs
|
// half-plane signs
|
||||||
bool sign1 = ((-_b.GetDoublePositionX() + pos.GetPositionX()) * _aby - (-_b.GetDoublePositionY() + pos.GetPositionY()) * _abx) < 0;
|
bool sign1 = ((-_b.GetPositionX() + pos.GetPositionX()) * _aby - (-_b.GetPositionY() + pos.GetPositionY()) * _abx) < 0;
|
||||||
bool sign2 = ((-_a.GetDoublePositionX() + pos.GetPositionX()) * _day - (-_a.GetDoublePositionY() + pos.GetPositionY()) * _dax) < 0;
|
bool sign2 = ((-_a.GetPositionX() + pos.GetPositionX()) * _day - (-_a.GetPositionY() + pos.GetPositionY()) * _dax) < 0;
|
||||||
bool sign3 = ((-_d.GetDoublePositionY() + pos.GetPositionY()) * _abx - (-_d.GetDoublePositionX() + pos.GetPositionX()) * _aby) < 0; // AB = -CD
|
bool sign3 = ((-_d.GetPositionY() + pos.GetPositionY()) * _abx - (-_d.GetPositionX() + pos.GetPositionX()) * _aby) < 0; // AB = -CD
|
||||||
bool sign4 = ((-_c.GetDoublePositionY() + pos.GetPositionY()) * _dax - (-_c.GetDoublePositionX() + pos.GetPositionX()) * _day) < 0; // DA = -BC
|
bool sign4 = ((-_c.GetPositionY() + pos.GetPositionY()) * _dax - (-_c.GetPositionX() + pos.GetPositionX()) * _day) < 0; // DA = -BC
|
||||||
|
|
||||||
// if all signs are equal, the point is inside
|
// if all signs are equal, the point is inside
|
||||||
return ((sign1 == sign2) && (sign2 == sign3) && (sign3 == sign4));
|
return ((sign1 == sign2) && (sign2 == sign3) && (sign3 == sign4));
|
||||||
}
|
}
|
||||||
|
|
||||||
DoublePosition _a;
|
Position _a;
|
||||||
DoublePosition _b;
|
Position _b;
|
||||||
DoublePosition _d;
|
Position _d;
|
||||||
DoublePosition _c;
|
Position _c;
|
||||||
double _abx;
|
float _abx;
|
||||||
double _dax;
|
float _dax;
|
||||||
double _aby;
|
float _aby;
|
||||||
double _day;
|
float _day;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ZRangeBoundary : AreaBoundary
|
public class ZRangeBoundary : AreaBoundary
|
||||||
@@ -212,7 +210,7 @@ namespace Game.Maps
|
|||||||
|
|
||||||
public override bool IsWithinBoundaryArea(Position pos)
|
public override bool IsWithinBoundaryArea(Position pos)
|
||||||
{
|
{
|
||||||
return (_minZ <= pos.GetPositionZ() && pos.GetPositionZ() <= _maxZ);
|
return pos.GetPositionZ() >= _minZ && pos.GetPositionZ() <= _maxZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
float _minZ;
|
float _minZ;
|
||||||
|
|||||||
Reference in New Issue
Block a user