2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/point.hpp>
|
2014-02-18 15:28:28 +11:00
|
|
|
|
2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/tap.hpp>
|
|
|
|
#include <cruft/util/types.hpp>
|
|
|
|
#include <cruft/util/coord/iostream.hpp>
|
2014-02-18 15:28:28 +11:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
using namespace cruft;
|
2014-02-18 15:28:28 +11:00
|
|
|
|
2018-01-16 13:29:58 +11:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2014-02-18 15:28:28 +11:00
|
|
|
int
|
2015-07-13 16:29:01 +10:00
|
|
|
main (void)
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2015-07-13 16:29:01 +10:00
|
|
|
|
2015-01-13 18:40:45 +11:00
|
|
|
// Redim to lower dimension
|
|
|
|
{
|
2017-06-13 14:19:27 +10:00
|
|
|
const point3f p { 0.f, 1.f, 2.f };
|
2015-01-13 18:40:45 +11:00
|
|
|
const point2f q = p.redim<2> ();
|
2017-06-13 14:19:27 +10:00
|
|
|
const point2f r { 0.f, 1.f };
|
2014-02-18 15:28:28 +11:00
|
|
|
|
2017-06-13 14:19:27 +10:00
|
|
|
tap.expect_eq (q, r, "redim to lower dimension");
|
2015-01-13 18:40:45 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
// Redim to higher dimension without fill
|
|
|
|
{
|
|
|
|
const point2f p(0.f, 1.f);
|
2017-06-13 14:19:27 +10:00
|
|
|
const point2f q = p.redim<2> ();
|
2015-01-13 18:40:45 +11:00
|
|
|
|
2017-06-13 14:19:27 +10:00
|
|
|
// GCC: we can't use the equality operator here because it triggers
|
|
|
|
// an ICE on GCC 7.1.0
|
2018-02-01 13:47:14 +11:00
|
|
|
|
2015-07-13 16:29:01 +10:00
|
|
|
tap.expect (
|
2017-06-13 14:19:27 +10:00
|
|
|
std::equal (std::cbegin (p), std::cend (p), std::cbegin (q)),
|
2015-07-13 16:29:01 +10:00
|
|
|
"redim to higher dimension"
|
|
|
|
);
|
2015-01-13 18:40:45 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
// Redim to higher dimension with fill
|
2017-11-22 17:03:00 +11:00
|
|
|
//
|
|
|
|
// HACK: This fails under GCC-7.1.0, and i'm not wasting any more time
|
|
|
|
// reducing this test case. it's _really_ template heavy.
|
2015-01-13 18:40:45 +11:00
|
|
|
{
|
|
|
|
static const point4f FILL (1.f, 2.f, 3.f, 4.f);
|
2015-02-03 02:21:58 +11:00
|
|
|
const point2f p (0.1f, 1.f);
|
2015-01-13 18:40:45 +11:00
|
|
|
const point4f q = p.template redim<4> (FILL);
|
|
|
|
|
2015-07-13 16:29:01 +10:00
|
|
|
tap.expect (
|
|
|
|
almost_equal (q[0], p[0]) &&
|
|
|
|
almost_equal (q[1], p[1]) &&
|
|
|
|
almost_equal (q[2], FILL[2]) &&
|
|
|
|
almost_equal (q[3], FILL[3]),
|
|
|
|
|
|
|
|
"redim to higher with fill"
|
|
|
|
);
|
2015-01-13 18:40:45 +11:00
|
|
|
}
|
2015-02-19 13:19:27 +11:00
|
|
|
|
2015-04-09 17:58:47 +10:00
|
|
|
// Simple linking check for coord type casting. Relies on truncation.
|
|
|
|
{
|
|
|
|
const point2f pf (0.5f, 0.2f);
|
|
|
|
const point2u pu (0, 0);
|
|
|
|
|
2015-07-13 16:29:01 +10:00
|
|
|
tap.expect_eq (pf.template cast<point2u::value_type> (), pu, "type cast with truncation");
|
2015-04-09 17:58:47 +10:00
|
|
|
}
|
|
|
|
|
2015-06-01 15:29:24 +10:00
|
|
|
// redim to 4-dimension homogenous coords
|
2015-02-19 13:19:27 +11:00
|
|
|
{
|
2018-04-17 14:26:23 +10:00
|
|
|
const point3f p (3, 4, 5);
|
|
|
|
const point4f q = p.homog ();
|
2015-02-19 13:19:27 +11:00
|
|
|
|
2015-07-13 16:29:01 +10:00
|
|
|
tap.expect (
|
2018-01-31 19:33:42 +11:00
|
|
|
equal (q.x, 3.f) &&
|
|
|
|
equal (q.y, 4.f) &&
|
2018-04-17 14:26:23 +10:00
|
|
|
equal (q.z, 5.f) &&
|
2018-01-31 19:33:42 +11:00
|
|
|
equal (q.w, 1.f),
|
2015-07-13 16:29:01 +10:00
|
|
|
|
|
|
|
"homogenous redim"
|
|
|
|
);
|
2015-02-19 13:19:27 +11:00
|
|
|
}
|
2015-04-13 16:45:56 +10:00
|
|
|
|
2015-06-01 15:29:24 +10:00
|
|
|
// trivial checks for distance metrics
|
|
|
|
{
|
|
|
|
const point2f a (1, 2);
|
|
|
|
const point2f b (9, 5);
|
|
|
|
|
2015-07-13 16:29:01 +10:00
|
|
|
tap.expect_eq (distance2 (a, b), 73.f, "distance2");
|
|
|
|
tap.expect_eq (distance (a, b), std::sqrt (73.f), "distance");
|
|
|
|
tap.expect_eq (manhattan (a, b), 11.f, "manhattan");
|
|
|
|
tap.expect_eq (chebyshev (a, b), 8.f, "chebyshev");
|
2015-06-01 15:29:24 +10:00
|
|
|
}
|
|
|
|
|
2018-04-18 21:44:36 +10:00
|
|
|
// test furthest point calculation
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::point2f const cloud[] = {
|
2018-04-18 21:44:36 +10:00
|
|
|
{ 0, 0},
|
|
|
|
{-1, 2},
|
|
|
|
{ 9,-3},
|
|
|
|
{ 6, 1},
|
|
|
|
};
|
|
|
|
|
|
|
|
auto const i = 1, j = 2;
|
2018-08-05 14:42:02 +10:00
|
|
|
auto const [a,b] = furthest (cruft::view{cloud});
|
2018-04-18 21:44:36 +10:00
|
|
|
|
|
|
|
tap.expect ((a == cloud[i] && b == cloud[j]) ||
|
|
|
|
(b == cloud[i] && a == cloud[j]),
|
|
|
|
"furthest point test");
|
|
|
|
};
|
|
|
|
|
2015-07-13 16:29:01 +10:00
|
|
|
return tap.status ();
|
2014-02-18 15:28:28 +11:00
|
|
|
}
|