2023-05-28 18:54:24 +08:00

24 lines
847 B
C++

#include "2d.hpp"
#include "test/u.hpp"
#include <functional>
namespace {
AddTestCase _(1, "2d.hpp", [](TestCase& t) {
t.expectEq<Float>([] { return cross({1, 2}, {4, 1}); }, -7);
t.expectEq<Float>([] { return cross({.5, 2.5}, {4, 1.5}); }, -9.25);
t.expectEq<Float>([] { return dot({1, 2}, {4, 1}); }, 6);
t.expectTrue([] { return Circle({0, 0}, 2).contain({1, 1}); });
t.expectTrue([] { return Circle({0, 0}, 1).contain({0, 1}); });
t.expectFalse([] { return Circle({1, 0}, 1.4).contain({0, -1}); });
t.expectTrue([] { return Circle({1, 1}, 1.42).contain({0, 0}); });
t.expectEq<Vec2>([] { return Polygon<3>{{0, 0}, {1, 0}, {1, 1}}.vertex[0]; }, {0, 0});
t.expectTrue([] { return Polygon<3>{{0, 0}, {1, 0}, {1, 1}}.contain({.1, .05}); });
t.expectFalse([] { return Polygon<3>{{0, 0}, {1, 0}, {1, 1}}.contain({.1, .2}); });
});
}