TrinityCore
ObjectPosSelector.cpp
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#include "ObjectPosSelector.h"
19
20ObjectPosSelector::ObjectPosSelector(float x, float y, float size, float dist)
21: m_center_x(x), m_center_y(y), m_size(size), m_dist(dist)
22{
23 m_anglestep = std::acos(m_dist/(m_dist+2*m_size));
24
27
30
33
36}
37
38ObjectPosSelector::UsedPosList::value_type const* ObjectPosSelector::nextUsedPos(UsedPosType uptype)
39{
40 UsedPosList::const_iterator itr = m_nextUsedPos[uptype];
41 if (itr!=m_UsedPosLists[uptype].end())
42 ++itr;
43
44 if (itr == m_UsedPosLists[uptype].end())
45 {
46 if (!m_UsedPosLists[~uptype].empty())
47 return &*m_UsedPosLists[~uptype].rbegin();
48 else
49 return nullptr;
50 }
51 else
52 return &*itr;
53}
54
55void ObjectPosSelector::AddUsedPos(float size, float angle, float dist)
56{
57 if (angle >= 0)
58 m_UsedPosLists[USED_POS_PLUS].insert(UsedPosList::value_type(angle, UsedPos(1.0f, size, dist)));
59 else
60 m_UsedPosLists[USED_POS_MINUS].insert(UsedPosList::value_type(-angle, UsedPos(-1.0f, size, dist)));
61}
62
64{
67
70
73}
74
76{
78 return NextAngleFor(*m_UsedPosLists[USED_POS_MINUS].begin(), 1.0f, USED_POS_PLUS, angle);
79 else if (m_UsedPosLists[USED_POS_MINUS].empty() && !m_UsedPosLists[USED_POS_PLUS].empty())
80 return NextAngleFor(*m_UsedPosLists[USED_POS_PLUS].begin(), -1.0f, USED_POS_MINUS, angle);
81
82 return false;
83}
84
86{
90 {
91 // calculate next possible angle
92 if (NextPosibleAngle(angle))
93 return true;
94 }
95
96 return false;
97}
98
100{
103 {
104 // calculate next possible angle
105 if (!NextPosibleAngle(angle))
106 return true;
107 }
108
109 return false;
110}
111
113{
114 // ++ direction less updated
117 {
118 bool ok;
120 ok = NextSmallStepAngle(1.0f, USED_POS_PLUS, angle);
121 else
123
124 if (!ok)
125 ++m_nextUsedPos[USED_POS_PLUS]; // increase. only at fail (original or checked)
126 return ok;
127 }
128 // -- direction less updated
130 {
131 bool ok;
133 ok = NextSmallStepAngle(-1.0f, USED_POS_MINUS, angle);
134 else
136
137 if (!ok)
139 return ok;
140 }
141 else // both list empty
142 {
144 return NextSmallStepAngle(1.0f, USED_POS_PLUS, angle);
145 // -- direction less updated
147 return NextSmallStepAngle(-1.0f, USED_POS_MINUS, angle);
148 }
149
150 // no angles
151 return false;
152}
UsedPosType
@ USED_POS_PLUS
@ USED_POS_MINUS
constexpr std::size_t size()
Definition: UpdateField.h:796
bool NextAngleFor(UsedPosList::value_type const &usedPos, float sign, UsedPosType uptype, float &angle)
bool FirstAngle(float &angle)
ObjectPosSelector(float x, float y, float size, float dist)
bool NextPosibleAngle(float &angle)
UsedPosList::const_iterator m_nextUsedPos[2]
bool NextUsedAngle(float &angle)
bool NextSmallStepAngle(float sign, UsedPosType uptype, float &angle)
UsedPosList::value_type const * nextUsedPos(UsedPosType uptype)
UsedPosList::value_type const * m_smallStepNextUsedPos[2]
void AddUsedPos(float size, float angle, float dist)
bool NextAngle(float &angle)
UsedPosList m_UsedPosLists[2]