#include <C4MapScript.h>
Definition at line 138 of file C4MapScript.h.
◆ C4MapScriptAlgoPolygon()
| C4MapScriptAlgoPolygon::C4MapScriptAlgoPolygon |
( |
const C4PropList * |
props | ) |
|
Definition at line 139 of file C4MapScriptAlgo.cpp.
145 if (!ptx || !pty || ptx->
GetSize() != pty->GetSize())
146 throw C4AulExecError(R
"(C4MapScriptAlgoPolygon: Expected two equally sized int arrays in properties "X" and "Y".)");
148 for (int32_t i=0; i<ptx->
GetSize(); ++i)
151 poly[i].y = pty->GetItem(i).getInt();
157 if (open && !empty)
throw C4AulExecError(
"C4MapScriptAlgoPolygon: Only empty polygons may be open.");
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val=0) const
bool GetProperty(C4PropertyName k, C4Value *pResult) const
const C4Value & GetItem(int32_t iElem) const
C4ValueArray * getArray() const
References C4Value::getArray(), C4Value::getInt(), C4ValueArray::GetItem(), C4PropList::GetProperty(), C4PropList::GetPropertyInt(), C4ValueArray::GetSize(), P_Empty, P_Open, P_Wdt, P_X, and P_Y.
◆ GetXYProps()
Definition at line 26 of file C4MapScriptAlgo.cpp.
33 if (zero_defaults) out_xy[0] = out_xy[1] = 0;
47 out_xy[0] = out_xy[1] = val.
getInt();
StdStrBuf FormatString(const char *szFmt,...)
bool HasProperty(C4String *k) const
const char * GetCStr() const
const char * getData() const
References FormatString(), C4Value::getArray(), C4String::GetCStr(), StdStrBuf::getData(), C4Value::getInt(), C4ValueArray::GetItem(), C4PropList::GetProperty(), C4ValueArray::GetSize(), C4PropList::HasProperty(), C4StringTable::P, and Strings.
Referenced by C4MapScriptAlgoBorder::C4MapScriptAlgoBorder(), and C4MapScriptAlgoTurbulence::C4MapScriptAlgoTurbulence().
◆ operator()()
| bool C4MapScriptAlgoPolygon::operator() |
( |
int32_t |
x, |
|
|
int32_t |
y, |
|
|
uint8_t & |
fg, |
|
|
uint8_t & |
bg |
|
) |
| const |
|
overridevirtual |
Implements C4MapScriptAlgo.
Definition at line 160 of file C4MapScriptAlgo.cpp.
163 int32_t crossings = 0;
164 for (
size_t i=0; i<poly.size(); ++i)
167 Pt pt2 = poly[(i+1)%poly.size()];
169 int32_t pdx = pt2.x-pt1.x, pdy = pt2.y-pt1.y, dx = x-pt1.x, dy = y-pt1.y;
170 if (i!=poly.size()-1 || !open)
172 int64_t d = dx*pdy-dy*pdx;
173 int32_t lsq = (pdx*pdx+pdy*pdy);
174 if (d*d < wdt*wdt*lsq)
176 if (
Inside(dx*pdx+dy*pdy, 0, lsq))
181 if (dx*dx+dy*dy < wdt*wdt)
return true;
183 if (!empty && (pt1.y<=y) != (pt2.y<=y))
186 crossings += (dx>dy*pdx/pdy);
190 return (crossings % 2)==1;
bool Inside(T ival, U lbound, V rbound)
References Inside().
The documentation for this class was generated from the following files: