TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
AreaBoundary.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef TRINITY_AREA_BOUNDARY_H
19 #define TRINITY_AREA_BOUNDARY_H
20 
21 #include "Position.h"
22 
24 {
25  public:
27  {
28  BOUNDARY_RECTANGLE, // Rectangle aligned with the coordinate axis
34  };
35  virtual ~AreaBoundary() { }
36  BoundaryType GetBoundaryType() const { return m_boundaryType; }
37  bool IsWithinBoundary(const Position* pos) const { return (IsWithinBoundaryArea(pos) != m_isInvertedBoundary); }
38 
40  {
41  double d_positionX, d_positionY, d_positionZ;
42  DoublePosition(double x = 0.0, double y = 0.0, double z = 0.0, float o = 0.0f)
43  : Position(float(x), float(y), float(z), o), d_positionX(x), d_positionY(y), d_positionZ(z) { }
44  DoublePosition(float x, float y = 0.0f, float z = 0.0f, float o = 0.0f)
45  : Position(x, y, z, o), d_positionX(x), d_positionY(y), d_positionZ(z) { }
47  : DoublePosition(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation()) { }
48 
49  double GetDoublePositionX() const { return d_positionX; }
50  double GetDoublePositionY() const { return d_positionY; }
51  double GetDoublePositionZ() const { return d_positionZ; }
52 
53  double GetDoubleExactDist2dSq(DoublePosition const& pos) const {
54  double offX = GetDoublePositionX() - pos.GetDoublePositionX();
55  double offY = GetDoublePositionY() - pos.GetDoublePositionY();
56  return (offX*offX) + (offY*offY);
57  }
58 
59  Position* sync() { m_positionX = (float)d_positionX; m_positionY = (float)d_positionY; m_positionZ = (float)d_positionZ; return this; }
60  };
61 
62  protected:
63  AreaBoundary(BoundaryType bType, bool isInverted) : m_boundaryType(bType), m_isInvertedBoundary(isInverted) { }
64  virtual bool IsWithinBoundaryArea(const Position* pos) const = 0;
67 };
68 
70 {
71  public:
72  // X axis is north/south, Y axis is east/west, larger values are northwest
73  RectangleBoundary(float southX, float northX, float eastY, float westY, bool isInverted = false);
74 
75  protected:
76  bool IsWithinBoundaryArea(const Position* pos) const override;
77 
78  private:
79  const float _minX, _maxX, _minY, _maxY;
80 };
81 
83 {
84  public:
85  CircleBoundary(Position const& center, double radius, bool isInverted = false);
86  CircleBoundary(DoublePosition const& center, double radius, bool isInverted = false);
87  CircleBoundary(Position const& center, Position const& pointOnCircle, bool isInverted = false);
88  CircleBoundary(DoublePosition const& center, DoublePosition const& pointOnCircle, bool isInverted = false);
89 
90  protected:
91  bool IsWithinBoundaryArea(const Position* pos) const override;
92 
93  private:
94  const DoublePosition _center;
95  const double _radiusSq;
96 };
97 
99 {
100  public:
101  EllipseBoundary(Position const& center, double radiusX, double radiusY, bool isInverted = false);
102  EllipseBoundary(DoublePosition const& center, double radiusX, double radiusY, bool isInverted = false);
103 
104  protected:
105  bool IsWithinBoundaryArea(const Position* pos) const override;
106 
107  private:
108  const DoublePosition _center;
109  const double _radiusYSq, _scaleXSq;
110 };
111 
113 {
114  public:
115  TriangleBoundary(Position const& pointA, Position const& pointB, Position const& pointC, bool isInverted = false);
116  TriangleBoundary(DoublePosition const& pointA, DoublePosition const& pointB, DoublePosition const& pointC, bool isInverted = false);
117 
118  protected:
119  bool IsWithinBoundaryArea(const Position* pos) const override;
120 
121  private:
122  const DoublePosition _a, _b, _c;
123  const double _abx, _bcx, _cax, _aby, _bcy, _cay;
124 };
125 
127 {
128  public:
129  // Note: AB must be orthogonal to AD
130  ParallelogramBoundary(Position const& cornerA, Position const& cornerB, Position const& cornerD, bool isInverted = false);
131  ParallelogramBoundary(DoublePosition const& cornerA, DoublePosition const& cornerB, DoublePosition const& cornerD, bool isInverted = false);
132 
133  protected:
134  bool IsWithinBoundaryArea(const Position* pos) const override;
135 
136  private:
137  const DoublePosition _a, _b, _d, _c;
138  const double _abx, _dax, _aby, _day;
139 };
140 
142 {
143  public:
144  ZRangeBoundary(float minZ, float maxZ, bool isInverted = false);
145 
146  protected:
147  bool IsWithinBoundaryArea(const Position* pos) const override;
148 
149  private:
150  const float _minZ, _maxZ;
151 };
152 
153 #endif //TRINITY_AREA_BOUNDARY_H
double GetDoublePositionX() const
Definition: AreaBoundary.h:49
Definition: AreaBoundary.h:28
Definition: AreaBoundary.h:33
const DoublePosition _center
Definition: AreaBoundary.h:108
Definition: AreaBoundary.h:112
Definition: AreaBoundary.h:82
bool m_isInvertedBoundary
Definition: AreaBoundary.h:66
const double _radiusSq
Definition: AreaBoundary.h:95
DoublePosition(double x=0.0, double y=0.0, double z=0.0, float o=0.0f)
Definition: AreaBoundary.h:42
Position * sync()
Definition: AreaBoundary.h:59
Definition: AreaBoundary.h:126
Definition: AreaBoundary.h:98
Definition: AreaBoundary.h:32
double GetDoubleExactDist2dSq(DoublePosition const &pos) const
Definition: AreaBoundary.h:53
const DoublePosition _d
Definition: AreaBoundary.h:137
DoublePosition(float x, float y=0.0f, float z=0.0f, float o=0.0f)
Definition: AreaBoundary.h:44
const DoublePosition _center
Definition: AreaBoundary.h:94
virtual ~AreaBoundary()
Definition: AreaBoundary.h:35
Definition: AreaBoundary.h:30
double GetDoublePositionZ() const
Definition: AreaBoundary.h:51
G3D::int16 z
Definition: Vector3int16.h:46
BoundaryType GetBoundaryType() const
Definition: AreaBoundary.h:36
const DoublePosition _c
Definition: AreaBoundary.h:122
virtual bool IsWithinBoundaryArea(const Position *pos) const =0
Definition: AreaBoundary.h:31
G3D::int16 y
Definition: Vector2int16.h:38
double GetDoublePositionY() const
Definition: AreaBoundary.h:50
const BoundaryType m_boundaryType
Definition: AreaBoundary.h:65
Definition: AreaBoundary.h:23
Definition: AreaBoundary.h:39
const double _scaleXSq
Definition: AreaBoundary.h:109
#define TC_GAME_API
Definition: Define.h:134
const double _day
Definition: AreaBoundary.h:138
Definition: AreaBoundary.h:141
Definition: Position.h:27
G3D::int16 x
Definition: Vector2int16.h:37
DoublePosition(const Position &pos)
Definition: AreaBoundary.h:46
bool IsWithinBoundary(const Position *pos) const
Definition: AreaBoundary.h:37
const float _minY
Definition: AreaBoundary.h:79
BoundaryType
Definition: AreaBoundary.h:26
const float _minZ
Definition: AreaBoundary.h:150
const double _cay
Definition: AreaBoundary.h:123
Definition: AreaBoundary.h:29
Definition: AreaBoundary.h:69
double d_positionZ
Definition: AreaBoundary.h:41
AreaBoundary(BoundaryType bType, bool isInverted)
Definition: AreaBoundary.h:63