Skip to content

Commit 78bfa69

Browse files
committed
common: Drop custom functions for one and zero
These are pretty silly and a bit too magical. Just use casts when it is neccessary.
1 parent 6c79da8 commit 78bfa69

12 files changed

+49
-82
lines changed

src/common/constants.hpp

-26
This file was deleted.

src/contacts/contact.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#ifndef IPTSD_CONTACTS_CONTACT_HPP
44
#define IPTSD_CONTACTS_CONTACT_HPP
55

6-
#include <common/constants.hpp>
6+
#include <common/casts.hpp>
77
#include <common/types.hpp>
88

99
#include <optional>
@@ -22,21 +22,21 @@ class Contact {
2222
*
2323
* Range: [0, 1] if normalized, [0, <input dimensions>] if not.
2424
*/
25-
Vector2<T> mean {Zero<T>(), Zero<T>()};
25+
Vector2<T> mean = Vector2<T>::Zero();
2626

2727
/*
2828
* The size of the contact (diameter of major and minor axis).
2929
*
3030
* Range: [0, 1] if normalized, [0, <hypot of input dimensions>] if not.
3131
*/
32-
Vector2<T> size {Zero<T>(), Zero<T>()};
32+
Vector2<T> size = Vector2<T>::Zero();
3333

3434
/*
3535
* The orientation of the contact.
3636
*
3737
* Range: [0, 1) if normalized, [0, pi) if not.
3838
*/
39-
T orientation = Zero<T>();
39+
T orientation = casts::to<T>(0);
4040

4141
/*
4242
* Whether the stored values are normalized.

src/contacts/detection/algorithms/convolution.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ void run_generic(const DenseBase<DerivedData> &in,
3030
{
3131
using T = typename DenseBase<DerivedKernel>::Scalar;
3232

33+
constexpr isize size_zero = 0;
34+
3335
const Eigen::Index cols = in.cols();
3436
const Eigen::Index rows = in.rows();
3537

@@ -47,13 +49,13 @@ void run_generic(const DenseBase<DerivedData> &in,
4749

4850
for (Eigen::Index oy = 0; oy < rows; oy++) {
4951
const isize sy = casts::to_signed(oy + ky) - dy;
50-
const isize cy = std::clamp(sy, Zero<isize>(), rows - 1);
52+
const isize cy = std::clamp(sy, size_zero, rows - 1);
5153

5254
const Eigen::Index iy = casts::to_eigen(cy);
5355

5456
for (Eigen::Index ox = 0; ox < cols; ox++) {
5557
const isize sx = casts::to_signed(ox + kx) - dx;
56-
const isize cx = std::clamp(sx, Zero<isize>(), cols - 1);
58+
const isize cx = std::clamp(sx, size_zero, cols - 1);
5759

5860
const Eigen::Index ix = casts::to_eigen(cx);
5961

src/contacts/detection/algorithms/gaussian.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#define IPTSD_CONTACTS_DETECTION_ALGORITHMS_GAUSSIAN_HPP
55

66
#include <common/casts.hpp>
7-
#include <common/constants.hpp>
87
#include <common/types.hpp>
98

109
#include <gsl/gsl>
@@ -222,7 +221,7 @@ void update_weight_maps(std::vector<Parameters<typename DenseBase<Derived>::Scal
222221
for (Eigen::Index x = bmin.x(); x <= bmax.x(); x++) {
223222
const T t = total(y, x);
224223

225-
if (t > Zero<T>())
224+
if (t > casts::to<T>(0))
226225
p.weights(y - bmin.y(), x - bmin.x()) /= t;
227226
}
228227
}
@@ -250,7 +249,7 @@ bool ge_solve(Matrix6<T> a, Vector6<T> b, Vector6<T> &x)
250249
{
251250
// step 1: find element with largest absolute value in column
252251
Eigen::Index r = 0;
253-
T v = Zero<T>();
252+
T v = casts::to<T>(0);
254253

255254
for (Eigen::Index i = c; i < 6; ++i) {
256255
const T vi = std::abs(a(c, i));

src/contacts/detection/algorithms/optimized/convolution.3x3-extend.hpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <common/buildopts.hpp>
44
#include <common/casts.hpp>
5-
#include <common/constants.hpp>
65
#include <common/types.hpp>
76

87
namespace iptsd::contacts::detection::convolution::impl {
@@ -58,7 +57,7 @@ inline void run_3x3(const DenseBase<DerivedData> &in,
5857
{
5958
// x = 0
6059
{
61-
auto v = Zero<T>();
60+
auto v = casts::to<T>(0);
6261

6362
v += d(i, 0, 0) * k(-1, -1); // extended
6463
v += d(i, 0, 0) * k(0, -1); // extended
@@ -78,7 +77,7 @@ inline void run_3x3(const DenseBase<DerivedData> &in,
7877
// 0 < x < n
7978
const auto limit = i + cols - 2;
8079
while (i < limit) {
81-
auto v = Zero<T>();
80+
auto v = casts::to<T>(0);
8281

8382
v += d(i, -1, 0) * k(-1, -1); // extended
8483
v += d(i, 0, 0) * k(0, -1); // extended
@@ -97,7 +96,7 @@ inline void run_3x3(const DenseBase<DerivedData> &in,
9796

9897
// x = n - 1
9998
{
100-
auto v = Zero<T>();
99+
auto v = casts::to<T>(0);
101100

102101
v += d(i, -1, 0) * k(-1, -1); // extended
103102
v += d(i, 0, 0) * k(0, -1); // extended
@@ -119,7 +118,7 @@ inline void run_3x3(const DenseBase<DerivedData> &in,
119118
while (i < cols * (rows - 1)) {
120119
// x = 0
121120
{
122-
auto v = Zero<T>();
121+
auto v = casts::to<T>(0);
123122

124123
v += d(i, 0, -1) * k(-1, -1); // extended
125124
v += d(i, 0, -1) * k(0, -1);
@@ -139,7 +138,7 @@ inline void run_3x3(const DenseBase<DerivedData> &in,
139138
// 0 < x < n
140139
const auto limit = i + cols - 2;
141140
while (i < limit) {
142-
auto v = Zero<T>();
141+
auto v = casts::to<T>(0);
143142

144143
v += d(i, -1, -1) * k(-1, -1);
145144
v += d(i, 0, -1) * k(0, -1);
@@ -158,7 +157,7 @@ inline void run_3x3(const DenseBase<DerivedData> &in,
158157

159158
// x = n - 1
160159
{
161-
auto v = Zero<T>();
160+
auto v = casts::to<T>(0);
162161

163162
v += d(i, -1, -1) * k(-1, -1);
164163
v += d(i, 0, -1) * k(0, -1);
@@ -180,7 +179,7 @@ inline void run_3x3(const DenseBase<DerivedData> &in,
180179
{
181180
// x = 0
182181
{
183-
auto v = Zero<T>();
182+
auto v = casts::to<T>(0);
184183

185184
v += d(i, 0, -1) * k(-1, -1); // extended
186185
v += d(i, 0, -1) * k(0, -1);
@@ -200,7 +199,7 @@ inline void run_3x3(const DenseBase<DerivedData> &in,
200199
// 1 < x < n - 2
201200
const auto limit = i + cols - 2;
202201
while (i < limit) {
203-
auto v = Zero<T>();
202+
auto v = casts::to<T>(0);
204203

205204
v += d(i, -1, -1) * k(-1, -1);
206205
v += d(i, 0, -1) * k(0, -1);
@@ -219,7 +218,7 @@ inline void run_3x3(const DenseBase<DerivedData> &in,
219218

220219
// x = n - 1
221220
{
222-
auto v = Zero<T>();
221+
auto v = casts::to<T>(0);
223222

224223
v += d(i, -1, -1) * k(-1, -1);
225224
v += d(i, 0, -1) * k(0, -1);

0 commit comments

Comments
 (0)