MCPcopy Create free account
hub / github.com/IENT/YUView / polygonContainsPoint

Function polygonContainsPoint

YUViewLib/src/statistics/StatisticsData.cpp:101–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101bool polygonContainsPoint(const stats::Polygon &polygon, const Point &pt)
102{
103 if (polygon.empty())
104 return false;
105
106 auto numPts = polygon.size();
107 // Test the ray against all sides
108 unsigned intersections = 0;
109 for (size_t i = 0; i < numPts - 1; i++)
110 {
111 Line side = Line(polygon.at(i), polygon.at(i + 1));
112 // Test if current side intersects with ray.
113 if (doesLineIntersectWithHorizontalLine(side, pt))
114 intersections++;
115 }
116 // close polygon
117 if (polygon.front() != polygon.back())
118 {
119 auto side = Line(polygon.front(), polygon.back());
120 // Test if current side intersects with ray.
121 if (doesLineIntersectWithHorizontalLine(side, pt))
122 intersections++;
123 }
124
125 if ((intersections & 1) == 1)
126 {
127 // Inside of polygon
128 return true;
129 }
130 else
131 {
132 // Outside of polygon
133 return false;
134 }
135}
136
137FrameTypeData StatisticsData::getFrameTypeData(int typeID)
138{

Callers 1

getValuesAtMethod · 0.85

Calls 4

LineClass · 0.85
sizeMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected