AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ObjectPosSelector Struct Reference

#include "ObjectPosSelector.h"

Classes

struct  UsedPos
 

Public Types

typedef std::multimap< float, UsedPosUsedPosList
 

Public Member Functions

 ObjectPosSelector (float x, float y, float size, float dist)
 
void AddUsedPos (float size, float angle, float dist)
 
void InitializeAngle ()
 
bool FirstAngle (float &angle)
 
bool NextAngle (float &angle)
 
bool NextUsedAngle (float &angle)
 
bool NextPosibleAngle (float &angle)
 
bool CheckAngle (UsedPosList::value_type const &nextUsedPos, float sign, float angle) const
 
bool CheckOriginal () const
 
bool IsNonBalanced () const
 
bool NextAngleFor (UsedPosList::value_type const &usedPos, float sign, UsedPosType uptype, float &angle)
 
bool NextSmallStepAngle (float sign, UsedPosType uptype, float &angle)
 
UsedPosList::value_type const * nextUsedPos (UsedPosType uptype)
 
float GetAngle (UsedPos const &usedPos) const
 

Public Attributes

float m_center_x
 
float m_center_y
 
float m_size
 
float m_dist
 
float m_anglestep
 
UsedPosList m_UsedPosLists [2]
 
UsedPosList::const_iterator m_nextUsedPos [2]
 
float m_smallStepAngle [2]
 
bool m_smallStepOk [2]
 
UsedPosList::value_type const * m_smallStepNextUsedPos [2]
 

Detailed Description

Member Typedef Documentation

◆ UsedPosList

typedef std::multimap<float, UsedPos> ObjectPosSelector::UsedPosList

Constructor & Destructor Documentation

◆ ObjectPosSelector()

ObjectPosSelector::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 = acos(m_dist / (m_dist + 2 * m_size));
24
27
30
33
36}
@ USED_POS_PLUS
Definition: ObjectPosSelector.h:25
@ USED_POS_MINUS
Definition: ObjectPosSelector.h:25
float m_center_x
Definition: ObjectPosSelector.h:140
float m_smallStepAngle[2]
Definition: ObjectPosSelector.h:150
float m_size
Definition: ObjectPosSelector.h:142
UsedPosList::const_iterator m_nextUsedPos[2]
Definition: ObjectPosSelector.h:147
float m_dist
Definition: ObjectPosSelector.h:143
bool m_smallStepOk[2]
Definition: ObjectPosSelector.h:151
float m_center_y
Definition: ObjectPosSelector.h:141
UsedPosList::value_type const * m_smallStepNextUsedPos[2]
Definition: ObjectPosSelector.h:152
float m_anglestep
Definition: ObjectPosSelector.h:144
UsedPosList m_UsedPosLists[2]
Definition: ObjectPosSelector.h:146

References m_anglestep, m_dist, m_nextUsedPos, m_size, m_smallStepAngle, m_smallStepNextUsedPos, m_smallStepOk, m_UsedPosLists, USED_POS_MINUS, and USED_POS_PLUS.

Member Function Documentation

◆ AddUsedPos()

void 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}

References m_UsedPosLists, USED_POS_MINUS, and USED_POS_PLUS.

◆ CheckAngle()

bool ObjectPosSelector::CheckAngle ( UsedPosList::value_type const &  nextUsedPos,
float  sign,
float  angle 
) const
inline
58 {
59 float angle_step2 = GetAngle(nextUsedPos.second);
60
61 float next_angle = nextUsedPos.first;
62 if (nextUsedPos.second.sign * sign < 0) // last node from diff. list (-pi+alpha)
63 next_angle = 2 * M_PI - next_angle; // move to positive
64
65 return std::fabs(angle) + angle_step2 <= next_angle;
66 }
UsedPosList::value_type const * nextUsedPos(UsedPosType uptype)
Definition: ObjectPosSelector.cpp:38
float GetAngle(UsedPos const &usedPos) const
Definition: ObjectPosSelector.h:138

References GetAngle(), and nextUsedPos().

Referenced by CheckOriginal(), NextAngleFor(), and NextSmallStepAngle().

◆ CheckOriginal()

bool ObjectPosSelector::CheckOriginal ( ) const
inline
69 {
70 return (m_UsedPosLists[USED_POS_PLUS].empty() || CheckAngle(*m_UsedPosLists[USED_POS_PLUS].begin(), 1.0f, 0)) &&
71 (m_UsedPosLists[USED_POS_MINUS].empty() || CheckAngle(*m_UsedPosLists[USED_POS_MINUS].begin(), -1.0f, 0));
72 }
bool CheckAngle(UsedPosList::value_type const &nextUsedPos, float sign, float angle) const
Definition: ObjectPosSelector.h:57

References CheckAngle(), m_UsedPosLists, USED_POS_MINUS, and USED_POS_PLUS.

◆ FirstAngle()

bool ObjectPosSelector::FirstAngle ( float &  angle)
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}
bool NextAngleFor(UsedPosList::value_type const &usedPos, float sign, UsedPosType uptype, float &angle)
Definition: ObjectPosSelector.h:76

References m_UsedPosLists, NextAngleFor(), USED_POS_MINUS, and USED_POS_PLUS.

◆ GetAngle()

float ObjectPosSelector::GetAngle ( UsedPos const &  usedPos) const
inline
138{ return acos(m_dist / (usedPos.dist + usedPos.size + m_size)); }

References ObjectPosSelector::UsedPos::dist, m_dist, m_size, and ObjectPosSelector::UsedPos::size.

Referenced by CheckAngle(), and NextAngleFor().

◆ InitializeAngle()

◆ IsNonBalanced()

bool ObjectPosSelector::IsNonBalanced ( ) const
inline

◆ NextAngle()

bool ObjectPosSelector::NextAngle ( float &  angle)
86{
90 {
91 // calculate next possible angle
92 if (NextPosibleAngle(angle))
93 return true;
94 }
95
96 return false;
97}
bool NextPosibleAngle(float &angle)
Definition: ObjectPosSelector.cpp:112

References m_nextUsedPos, m_smallStepOk, m_UsedPosLists, NextPosibleAngle(), USED_POS_MINUS, and USED_POS_PLUS.

◆ NextAngleFor()

bool ObjectPosSelector::NextAngleFor ( UsedPosList::value_type const &  usedPos,
float  sign,
UsedPosType  uptype,
float &  angle 
)
inline
77 {
78 float angle_step = GetAngle(usedPos.second);
79
80 // next possible angle
81 angle = usedPos.first * usedPos.second.sign + angle_step * sign;
82
83 UsedPosList::value_type const* nextNode = nextUsedPos(uptype);
84 if (nextNode)
85 {
86 // if next node permit use selected angle, then do it
87 if (!CheckAngle(*nextNode, sign, angle))
88 {
89 m_smallStepOk[uptype] = false;
90 return false;
91 }
92 }
93
94 // possible more points
95 m_smallStepOk[uptype] = true;
96 m_smallStepAngle[uptype] = angle;
97 m_smallStepNextUsedPos[uptype] = nextNode;
98
99 return true;
100 }

References CheckAngle(), GetAngle(), m_smallStepAngle, m_smallStepNextUsedPos, m_smallStepOk, and nextUsedPos().

Referenced by FirstAngle(), and NextPosibleAngle().

◆ NextPosibleAngle()

bool ObjectPosSelector::NextPosibleAngle ( float &  angle)
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}
bool NextSmallStepAngle(float sign, UsedPosType uptype, float &angle)
Definition: ObjectPosSelector.h:102

References m_nextUsedPos, m_smallStepAngle, m_smallStepOk, m_UsedPosLists, NextAngleFor(), NextSmallStepAngle(), USED_POS_MINUS, and USED_POS_PLUS.

Referenced by NextAngle(), and NextUsedAngle().

◆ NextSmallStepAngle()

bool ObjectPosSelector::NextSmallStepAngle ( float  sign,
UsedPosType  uptype,
float &  angle 
)
inline
103 {
104 // next possible angle
105 angle = m_smallStepAngle[uptype] + m_anglestep * sign;
106
107 if (std::fabs(angle) > M_PI)
108 {
109 m_smallStepOk[uptype] = false;
110 return false;
111 }
112
113 if (m_smallStepNextUsedPos[uptype])
114 {
115 if (std::fabs(angle) >= m_smallStepNextUsedPos[uptype]->first)
116 {
117 m_smallStepOk[uptype] = false;
118 return false;
119 }
120
121 // if next node permit use selected angle, then do it
122 if (!CheckAngle(*m_smallStepNextUsedPos[uptype], sign, angle))
123 {
124 m_smallStepOk[uptype] = false;
125 return false;
126 }
127 }
128
129 // possible more points
130 m_smallStepAngle[uptype] = angle;
131 return true;
132 }

References CheckAngle(), m_anglestep, m_smallStepAngle, m_smallStepNextUsedPos, and m_smallStepOk.

Referenced by NextPosibleAngle().

◆ NextUsedAngle()

bool ObjectPosSelector::NextUsedAngle ( float &  angle)
100{
103 {
104 // calculate next possible angle
105 if (!NextPosibleAngle(angle))
106 return true;
107 }
108
109 return false;
110}

References m_nextUsedPos, m_UsedPosLists, NextPosibleAngle(), USED_POS_MINUS, and USED_POS_PLUS.

◆ nextUsedPos()

ObjectPosSelector::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}

References m_nextUsedPos, and m_UsedPosLists.

Referenced by CheckAngle(), and NextAngleFor().

Member Data Documentation

◆ m_anglestep

float ObjectPosSelector::m_anglestep

◆ m_center_x

float ObjectPosSelector::m_center_x

◆ m_center_y

float ObjectPosSelector::m_center_y

◆ m_dist

float ObjectPosSelector::m_dist

Referenced by GetAngle(), and ObjectPosSelector().

◆ m_nextUsedPos

UsedPosList::const_iterator ObjectPosSelector::m_nextUsedPos[2]

◆ m_size

float ObjectPosSelector::m_size

Referenced by GetAngle(), and ObjectPosSelector().

◆ m_smallStepAngle

float ObjectPosSelector::m_smallStepAngle[2]

◆ m_smallStepNextUsedPos

UsedPosList::value_type const* ObjectPosSelector::m_smallStepNextUsedPos[2]

◆ m_smallStepOk

bool ObjectPosSelector::m_smallStepOk[2]

◆ m_UsedPosLists