MCPcopy Create free account
hub / github.com/ElectroZybr/LatticeLab / pointInPolygon

Method pointInPolygon

App/interaction/picking/PickingSystem.cpp:190–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188
189// Ray casting алгоритм для point-in-polygon
190template <typename T> bool PickingSystem::pointInPolygon(const T& point, std::span<T> polygon) {
191 bool inside = false;
192 const int x = static_cast<int>(point.x);
193 const int y = static_cast<int>(point.y);
194 const size_t n = polygon.size();
195
196 for (size_t i = 0, j = n - 1; i < n; j = i++) {
197 const int xi = static_cast<int>(polygon[i].x), yi = static_cast<int>(polygon[i].y);
198 const int xj = static_cast<int>(polygon[j].x), yj = static_cast<int>(polygon[j].y);
199
200 const bool intersects = ((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
201 if (intersects) {
202 inside = !inside;
203 }
204 }
205
206 return inside;
207}
208
209template <typename T> bool PickingSystem::pointInRect(const T& point, const T& start, const T& end) {
210 int minX = std::min(static_cast<int>(start.x), static_cast<int>(end.x));

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected