TrinityCore
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 double const offX = GetDoublePositionX() - pos.GetDoublePositionX();
51 double const offY = GetDoublePositionY() - pos.GetDoublePositionY();
52 return (offX * offX) + (offY * offY);
53 }
54
56 {
57 m_positionX = float(DoublePosX);
58 m_positionY = float(DoublePosY);
59 m_positionZ = float(DoublePosZ);
60 return this;
61 }
62
63 double DoublePosX;
64 double DoublePosY;
65 double DoublePosZ;
66 };
67
68 virtual bool IsWithinBoundaryArea(Position const* pos) const = 0;
69
70 private:
72};
73
75{
76 public:
77 // X axis is north/south, Y axis is east/west, larger values are northwest
78 RectangleBoundary(float southX, float northX, float eastY, float westY, bool isInverted = false);
79
80 protected:
81 bool IsWithinBoundaryArea(Position const* pos) const override;
82
83 private:
84 float const _minX, _maxX, _minY, _maxY;
85};
86
88{
89 public:
90 CircleBoundary(Position const& center, double radius, bool isInverted = false);
91 CircleBoundary(Position const& center, Position const& pointOnCircle, bool isInverted = false);
92
93 protected:
94 bool IsWithinBoundaryArea(Position const* pos) const override;
95
96 private:
98 double const _radiusSq;
99};
100
102{
103 public:
104 EllipseBoundary(Position const& center, double radiusX, double radiusY, bool isInverted = false);
105
106 protected:
107 bool IsWithinBoundaryArea(Position const* pos) const override;
108
109 private:
111 double const _radiusYSq, _scaleXSq;
112};
113
115{
116 public:
117 TriangleBoundary(Position const& pointA, Position const& pointB, Position const& pointC, bool isInverted = false);
118
119 protected:
120 bool IsWithinBoundaryArea(Position const* pos) const override;
121
122 private:
123 DoublePosition const _a, _b, _c;
124 double const _abx, _bcx, _cax, _aby, _bcy, _cay;
125};
126
128{
129 public:
130 // Note: AB must be orthogonal to AD
131 ParallelogramBoundary(Position const& cornerA, Position const& cornerB, Position const& cornerD, bool isInverted = false);
132
133 protected:
134 bool IsWithinBoundaryArea(Position const* pos) const override;
135
136 private:
137 DoublePosition const _a, _b, _d, _c;
138 double const _abx, _dax, _aby, _day;
139};
140
142{
143 public:
144 ZRangeBoundary(float minZ, float maxZ, bool isInverted = false);
145
146 protected:
147 bool IsWithinBoundaryArea(Position const* pos) const override;
148
149 private:
150 float const _minZ, _maxZ;
151};
152
154{
155 public:
156 BoundaryUnionBoundary(AreaBoundary const* b1, AreaBoundary const* b2, bool isInverted = false);
157
158 protected:
159 virtual ~BoundaryUnionBoundary();
160 bool IsWithinBoundaryArea(Position const* pos) const override;
161
162 private:
163 AreaBoundary const* const _b1;
164 AreaBoundary const* const _b2;
165};
166
167#endif //TRINITY_AREA_BOUNDARY_H
#define TC_GAME_API
Definition: Define.h:123
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:71
AreaBoundary(bool isInverted)
Definition: AreaBoundary.h:32
virtual bool IsWithinBoundaryArea(Position const *pos) const =0
AreaBoundary const *const _b1
Definition: AreaBoundary.h:163
AreaBoundary const *const _b2
Definition: AreaBoundary.h:164
DoublePosition const _center
Definition: AreaBoundary.h:97
double const _radiusSq
Definition: AreaBoundary.h:98
DoublePosition const _center
Definition: AreaBoundary.h:110
double const _radiusYSq
Definition: AreaBoundary.h:111
DoublePosition const _a
Definition: AreaBoundary.h:137
float const _maxX
Definition: AreaBoundary.h:84
DoublePosition const _a
Definition: AreaBoundary.h:123
double const _abx
Definition: AreaBoundary.h:124
float const _maxZ
Definition: AreaBoundary.h:150
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