Skip to content

Commit c0f1a19

Browse files
committed
core: generic: Move inverting detected contacts into Application
1 parent 660365b commit c0f1a19

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

src/apps/daemon/touch.hpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,6 @@ class TouchDevice {
289289
const Vector2<f64> size = contact.size;
290290

291291
Vector2<f64> mean = contact.mean;
292-
f64 orientation = contact.orientation;
293-
294-
if (m_config.invert_x)
295-
mean.x() = 1.0 - mean.x();
296-
297-
if (m_config.invert_y)
298-
mean.y() = 1.0 - mean.y();
299-
300-
if (m_config.invert_x != m_config.invert_y)
301-
orientation = 1.0 - orientation;
302292

303293
mean.x() = std::clamp(mean.x(), 0.0, 1.0);
304294
mean.y() = std::clamp(mean.y(), 0.0, 1.0);
@@ -308,7 +298,7 @@ class TouchDevice {
308298
const i32 x = casts::to<i32>(std::round(mean.x() * MAX_X));
309299
const i32 y = casts::to<i32>(std::round(mean.y() * MAX_Y));
310300

311-
const i32 angle = casts::to<i32>(std::round(orientation * 180));
301+
const i32 angle = casts::to<i32>(std::round(contact.orientation * 180));
312302
const i32 major = casts::to<i32>(std::round(size.maxCoeff() * DIAGONAL));
313303
const i32 minor = casts::to<i32>(std::round(size.minCoeff() * DIAGONAL));
314304

@@ -384,12 +374,6 @@ class TouchDevice {
384374
{
385375
Vector2<f64> mean = contact.mean;
386376

387-
if (m_config.invert_x)
388-
mean.x() = 1.0 - mean.x();
389-
390-
if (m_config.invert_y)
391-
mean.y() = 1.0 - mean.y();
392-
393377
mean.x() = std::clamp(mean.x(), 0.0, 1.0);
394378
mean.y() = std::clamp(mean.y(), 0.0, 1.0);
395379

src/apps/visualization/visualize.hpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,11 @@ class Visualize : public core::Application {
183183
Cairo::TextExtents extends {};
184184
m_cairo->get_text_extents(index, extends);
185185

186-
Vector2<f64> mean = contact.mean;
187-
f64 orientation = contact.orientation;
186+
const Vector2<f64> mean = contact.mean.cwiseProduct(m_size.cast<f64>());
187+
const f64 orientation = contact.orientation * M_PI;
188188

189189
const Vector2<f64> size = (contact.size.array() * diag).matrix();
190190

191-
if (m_config.invert_x)
192-
mean.x() = 1.0 - mean.x();
193-
194-
if (m_config.invert_y)
195-
mean.y() = 1.0 - mean.y();
196-
197-
if (m_config.invert_x != m_config.invert_y)
198-
orientation = 1.0 - orientation;
199-
200-
mean = mean.cwiseProduct(m_size.cast<f64>());
201-
orientation = orientation * M_PI;
202-
203191
// Center the text at the mean point of the contact
204192
m_cairo->move_to(mean.x() - (extends.x_bearing + extends.width / 2),
205193
mean.y() - (extends.y_bearing + extends.height / 2));

src/core/generic/application.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ class Application {
219219
// Search for contacts
220220
m_finder.find(m_heatmap, m_contacts);
221221

222+
// Invert contact coordinates if neccessary
223+
for (contacts::Contact<f64> &contact : m_contacts) {
224+
if (m_config.invert_x)
225+
contact.mean.x() = 1.0 - contact.mean.x();
226+
227+
if (m_config.invert_y)
228+
contact.mean.y() = 1.0 - contact.mean.y();
229+
230+
if (m_config.invert_x != m_config.invert_y)
231+
contact.orientation = 1.0 - contact.orientation;
232+
}
233+
222234
// Update touch rejection cone
223235
this->update_touch_cone();
224236

0 commit comments

Comments
 (0)