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 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
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:
26 bool IsWithinBoundary(Position const* pos) const { return pos && (IsWithinBoundaryArea(pos) != _isInvertedBoundary); }
27 bool IsWithinBoundary(Position const& pos) const { return IsWithinBoundary(&pos); }
28
29 virtual ~AreaBoundary() { }
30
31 protected:
32 explicit AreaBoundary(bool isInverted) : _isInvertedBoundary(isInverted) { }
33
35 {
36 DoublePosition(double x = 0.0, double y = 0.0, double z = 0.0, float o = 0.0f)
37 : Position(float(x), float(y), float(z), o), DoublePosX(x), DoublePosY(y), DoublePosZ(z) { }
38
39 DoublePosition(float x, float y = 0.0f, float z = 0.0f, float o = 0.0f)
40 : Position(x, y, z, o), DoublePosX(x), DoublePosY(y), DoublePosZ(z) { }
41
43 : Position(pos), DoublePosX(pos.m_positionX), DoublePosY(pos.m_positionY), DoublePosZ(pos.m_positionZ) { }
44
45 double GetDoublePositionX() const { return DoublePosX; }
46 double GetDoublePositionY() const { return DoublePosY; }
47 double GetDoublePositionZ() const { return DoublePosZ; }
48
49 double GetDoubleExactDist2dSq(DoublePosition const& pos) const
50 {
51 double const offX = GetDoublePositionX() - pos.GetDoublePositionX();
52 double const offY = GetDoublePositionY() - pos.GetDoublePositionY();
53 return (offX * offX) + (offY * offY);
54 }
55
57 {
58 m_positionX = float(DoublePosX);
59 m_positionY = float(DoublePosY);
60 m_positionZ = float(DoublePosZ);
61 return this;
62 }
63
64 double DoublePosX;
65 double DoublePosY;
66 double DoublePosZ;
67 };
68
69 virtual bool IsWithinBoundaryArea(Position const* pos) const = 0;
70
71 private:
73};
74
76{
77 public:
78 // X axis is north/south, Y axis is east/west, larger values are northwest
79 RectangleBoundary(float southX, float northX, float eastY, float westY, bool isInverted = false);
80
81 protected:
82 bool IsWithinBoundaryArea(Position const* pos) const override;
83
84 private:
85 float const _minX, _maxX, _minY, _maxY;
86};
87
89{
90 public:
91 CircleBoundary(Position const& center, double radius, bool isInverted = false);
92 CircleBoundary(Position const& center, Position const& pointOnCircle, bool isInverted = false);
93
94 protected:
95 bool IsWithinBoundaryArea(Position const* pos) const override;
96
97 private:
99 double const _radiusSq;
100};
101
103{
104 public:
105 EllipseBoundary(Position const& center, double radiusX, double radiusY, bool isInverted = false);
106
107 protected:
108 bool IsWithinBoundaryArea(Position const* pos) const override;
109
110 private:
112 double const _radiusYSq, _scaleXSq;
113};
114
116{
117 public:
118 TriangleBoundary(Position const& pointA, Position const& pointB, Position const& pointC, bool isInverted = false);
119
120 protected:
121 bool IsWithinBoundaryArea(Position const* pos) const override;
122
123 private:
124 DoublePosition const _a, _b, _c;
125 double const _abx, _bcx, _cax, _aby, _bcy, _cay;
126};
127
129{
130 public:
131 // Note: AB must be orthogonal to AD
132 ParallelogramBoundary(Position const& cornerA, Position const& cornerB, Position const& cornerD, bool isInverted = false);
133
134 protected:
135 bool IsWithinBoundaryArea(Position const* pos) const override;
136
137 private:
138 DoublePosition const _a, _b, _d, _c;
139 double const _abx, _dax, _aby, _day;
140};
141
143{
144 public:
145 ZRangeBoundary(float minZ, float maxZ, bool isInverted = false);
146
147 protected:
148 bool IsWithinBoundaryArea(Position const* pos) const override;
149
150 private:
151 float const _minZ, _maxZ;
152};
153
155{
156 public:
157 BoundaryUnionBoundary(AreaBoundary const* b1, AreaBoundary const* b2, bool isInverted = false);
158
159 protected:
160 virtual ~BoundaryUnionBoundary();
161 bool IsWithinBoundaryArea(Position const* pos) const override;
162
163 private:
164 AreaBoundary const* const _b1;
165 AreaBoundary const* const _b2;
166};
167
168#endif //TRINITY_AREA_BOUNDARY_H
#define TC_GAME_API
Definition: Define.h:114
bool IsWithinBoundary(Position const *pos) const
Definition: AreaBoundary.h:26
virtual ~AreaBoundary()
Definition: AreaBoundary.h:29
bool IsWithinBoundary(Position const &pos) const
Definition: AreaBoundary.h:27
bool _isInvertedBoundary
Definition: AreaBoundary.h:72
AreaBoundary(bool isInverted)
Definition: AreaBoundary.h:32
virtual bool IsWithinBoundaryArea(Position const *pos) const =0
AreaBoundary const *const _b1
Definition: AreaBoundary.h:164
AreaBoundary const *const _b2
Definition: AreaBoundary.h:165
DoublePosition const _center
Definition: AreaBoundary.h:98
double const _radiusSq
Definition: AreaBoundary.h:99
DoublePosition const _center
Definition: AreaBoundary.h:111
double const _radiusYSq
Definition: AreaBoundary.h:112
DoublePosition const _a
Definition: AreaBoundary.h:138
float const _maxX
Definition: AreaBoundary.h:85
DoublePosition const _a
Definition: AreaBoundary.h:124
double const _abx
Definition: AreaBoundary.h:125
float const _maxZ
Definition: AreaBoundary.h:151
double GetDoublePositionZ() const
Definition: AreaBoundary.h:47
double GetDoublePositionY() const
Definition: AreaBoundary.h:46
DoublePosition(Position const &pos)
Definition: AreaBoundary.h:42
DoublePosition(double x=0.0, double y=0.0, double z=0.0, float o=0.0f)
Definition: AreaBoundary.h:36
double GetDoublePositionX() const
Definition: AreaBoundary.h:45
DoublePosition(float x, float y=0.0f, float z=0.0f, float o=0.0f)
Definition: AreaBoundary.h:39
double GetDoubleExactDist2dSq(DoublePosition const &pos) const
Definition: AreaBoundary.h:49