Move fillrule to test()
diff --git a/include/rive/math/hit_test.hpp b/include/rive/math/hit_test.hpp
index 1e30bde..dadee50 100644
--- a/include/rive/math/hit_test.hpp
+++ b/include/rive/math/hit_test.hpp
@@ -20,7 +20,6 @@
Vec2D m_offset;
float m_height;
int m_IWidth, m_IHeight;
- int m_WindingMask;
bool m_ExpectsMove;
void recurse_cubic(Vec2D b, Vec2D c, Vec2D d, int count);
@@ -30,7 +29,7 @@
HitTester(const IAABB& area) { reset(area); }
void reset();
- void reset(const IAABB& area, FillRule = rive::FillRule::nonZero);
+ void reset(const IAABB& area);
void move(Vec2D);
void line(Vec2D);
@@ -40,7 +39,7 @@
void addRect(const AABB&, const Mat2D&, PathDirection = PathDirection::ccw);
- bool test(); // calls reset() afterwards
+ bool test(FillRule = rive::FillRule::nonZero);
};
}
diff --git a/src/hittest_command_path.cpp b/src/hittest_command_path.cpp
index 0b51de7..4dec9af 100644
--- a/src/hittest_command_path.cpp
+++ b/src/hittest_command_path.cpp
@@ -11,7 +11,7 @@
}
bool HitTestCommandPath::wasHit() {
- return m_Tester.test();
+ return m_Tester.test(m_FillRule);
}
void HitTestCommandPath::reset() {
@@ -19,6 +19,7 @@
}
void HitTestCommandPath::fillRule(FillRule value) {
+ // remember this here, and pass it to test()
m_FillRule = value;
}
diff --git a/src/math/hit_test.cpp b/src/math/hit_test.cpp
index 2463f1a..d652c0b 100644
--- a/src/math/hit_test.cpp
+++ b/src/math/hit_test.cpp
@@ -165,12 +165,10 @@
m_DW.clear();
}
-void HitTester::reset(const IAABB& clip, FillRule rule) {
+void HitTester::reset(const IAABB& clip) {
m_offset = Vec2D{ (float)clip.left, (float)clip.top };
m_height = (float)clip.height();
- m_WindingMask = (rule == rive::FillRule::nonZero) ? -1 : 1;
-
m_IWidth = clip.width();
m_IHeight = clip.height();
m_DW.resize(m_IWidth * m_IHeight);
@@ -320,20 +318,16 @@
close();
}
-bool HitTester::test() {
+bool HitTester::test(FillRule rule) {
if (!m_ExpectsMove) {
this->close();
}
- const int* row = m_DW.data();
- int winding = 0;
- for (int y = 0; y < m_IHeight; ++y) {
- int w = 0;
- for (int x = 0; x < m_IWidth; ++x) {
- w += *row++;
- winding |= w & m_WindingMask;
- }
+ const int mask = (rule == rive::FillRule::nonZero) ? -1 : 1;
+
+ int nonzero = 0;
+ for (auto m : m_DW) {
+ nonzero |= (m & mask);
}
- this->reset();
- return winding != 0;
+ return nonzero != 0;
}