Format all C++ and Java code via clang-format

Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
Konstantin Pastbin
2025-08-17 14:32:37 +07:00
parent 9f0290c0ec
commit bfffa1fff4
2169 changed files with 56441 additions and 64188 deletions

View File

@@ -11,11 +11,11 @@ namespace algorithm_test
{
using namespace std;
using m2::CalculateBoundingBox;
using m2::CalculatePointOnSurface;
using m2::CalculatePolyLineCenter;
using m2::PointD;
using m2::RectD;
using m2::CalculatePolyLineCenter;
using m2::CalculatePointOnSurface;
using m2::CalculateBoundingBox;
PointD GetPolyLineCenter(vector<PointD> const & points)
{
@@ -42,52 +42,28 @@ bool PointsAlmostEqual(PointD const & p1, PointD const & p2)
UNIT_TEST(CalculatePolyLineCenter)
{
{
vector<PointD> const points {
{0, 0},
{1, 1},
{2, 2}
};
vector<PointD> const points{{0, 0}, {1, 1}, {2, 2}};
TEST_EQUAL(GetPolyLineCenter(points), PointD(1, 1), ());
}
{
vector<PointD> const points {
{0, 2},
{1, 1},
{2, 2}
};
vector<PointD> const points{{0, 2}, {1, 1}, {2, 2}};
TEST_EQUAL(GetPolyLineCenter(points), PointD(1, 1), ());
}
{
vector<PointD> const points {
{1, 1},
{2, 2},
{4, 4},
vector<PointD> const points{
{1, 1},
{2, 2},
{4, 4},
};
TEST_EQUAL(GetPolyLineCenter(points), PointD(2.5, 2.5), ());
}
{
vector<PointD> const points {
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0}
};
vector<PointD> const points{{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}};
// Also logs a warning message.
TEST_EQUAL(GetPolyLineCenter(points), PointD(0, 0), ());
}
{
vector<PointD> const points {
{0, 0},
{0, 0},
{0, 0},
{0, 0.000001},
{0, 0.000001},
{0, 0.000001},
{0, 0.000001}
};
vector<PointD> const points{{0, 0}, {0, 0}, {0, 0}, {0, 0.000001}, {0, 0.000001}, {0, 0.000001}, {0, 0.000001}};
// Also logs a warning message.
TEST(GetPolyLineCenter(points).EqualDxDy(PointD(0, .0000005), 1e-7), ());
}
@@ -96,28 +72,15 @@ UNIT_TEST(CalculatePolyLineCenter)
UNIT_TEST(CalculateCenter)
{
{
vector<PointD> const points {
{2, 2}
};
TEST_EQUAL(GetBoundingBox(points), RectD({2, 2}, {2, 2}), ());
vector<PointD> const points{{2, 2}};
TEST_EQUAL(GetBoundingBox(points), RectD({2, 2}, {2, 2}), ());
}
{
vector<PointD> const points {
{0, 0},
{1, 1},
{2, 2}
};
vector<PointD> const points{{0, 0}, {1, 1}, {2, 2}};
TEST_EQUAL(GetBoundingBox(points), RectD({0, 0}, {2, 2}), ());
}
{
vector<PointD> const points {
{0, 2},
{1, 1},
{2, 2},
{1, 2},
{2, 2},
{2, 0}
};
vector<PointD> const points{{0, 2}, {1, 1}, {2, 2}, {1, 2}, {2, 2}, {2, 0}};
TEST_EQUAL(GetBoundingBox(points), RectD({0, 0}, {2, 2}), ());
}
}
@@ -125,45 +88,30 @@ UNIT_TEST(CalculateCenter)
UNIT_TEST(CalculatePointOnSurface)
{
{
vector<PointD> const points {
{0, 0},
{1, 1},
{2, 2}
};
vector<PointD> const points{{0, 0}, {1, 1}, {2, 2}};
TEST_EQUAL(GetPointOnSurface(points), PointD(1, 1), ());
}
{
vector<PointD> const points {
{0, 2},
{1, 1},
{2, 2},
{1, 2},
{2, 2},
{2, 0}
};
vector<PointD> const points{{0, 2}, {1, 1}, {2, 2}, {1, 2}, {2, 2}, {2, 0}};
TEST_EQUAL(GetPointOnSurface(points), PointD(1, 1), ());
}
{
vector<PointD> const points {
{0, 0}, {1, 1}, {2, 0},
{1, 1}, {2, 0}, {3, 1}, // Center of this triangle is used as a result.
{2, 0}, {3, 1}, {4, 0},
vector<PointD> const points{
{0, 0}, {1, 1}, {2, 0}, {1, 1}, {2, 0}, {3, 1}, // Center of this triangle is used as a result.
{2, 0}, {3, 1}, {4, 0},
{4, 0}, {3, 1}, {4, 2},
{3, 1}, {4, 2}, {3, 3}, // Or this.
{4, 2}, {3, 3}, {4, 4},
{4, 0}, {3, 1}, {4, 2}, {3, 1}, {4, 2}, {3, 3}, // Or this.
{4, 2}, {3, 3}, {4, 4},
{3, 3}, {4, 4}, {2, 4},
{3, 3}, {2, 4}, {1, 3}, // Or this.
{1, 3}, {2, 4}, {0, 4},
{3, 3}, {4, 4}, {2, 4}, {3, 3}, {2, 4}, {1, 3}, // Or this.
{1, 3}, {2, 4}, {0, 4},
{0, 4}, {1, 3}, {0, 2},
{1, 3}, {0, 2}, {1, 1}, // Or this
{0, 2}, {1, 1}, {0, 0},
{0, 4}, {1, 3}, {0, 2}, {1, 3}, {0, 2}, {1, 1}, // Or this
{0, 2}, {1, 1}, {0, 0},
};
auto const result = GetPointOnSurface(points);
TEST(PointsAlmostEqual(result, {10.0 / 3.0, 2}) || PointsAlmostEqual(result, {2, 2.0 / 3.0}) ||
PointsAlmostEqual(result, {2, 10.0 / 3.0}) || PointsAlmostEqual(result, {2.0 / 3.0, 2}),
PointsAlmostEqual(result, {2, 10.0 / 3.0}) || PointsAlmostEqual(result, {2.0 / 3.0, 2}),
("result = ", result));
}
}

View File

@@ -6,20 +6,19 @@
#include "geometry/angles.hpp"
using namespace test;
using math::pi;
UNIT_TEST(Atan)
{
double const h4 = math::pi/4.0;
double const h4 = math::pi / 4.0;
TEST(is_equal_atan(1, 1, h4), ());
TEST(is_equal_atan(-1, 1, math::pi - h4), ());
TEST(is_equal_atan(-1, -1, h4 - math::pi), ());
TEST(is_equal_atan(1, -1, -h4), ());
double const hh = atan(1.0/2.0);
double const hh = atan(1.0 / 2.0);
TEST(is_equal_atan(2, 1, hh), ());
TEST(is_equal_atan(-2, 1, math::pi - hh), ());
@@ -29,36 +28,36 @@ UNIT_TEST(Atan)
UNIT_TEST(Atan2)
{
TEST_ALMOST_EQUAL_ULPS(atan2(1, 0), pi/2.0, ());
TEST_ALMOST_EQUAL_ULPS(atan2(-1, 0), -pi/2.0, ());
TEST_ALMOST_EQUAL_ULPS(atan2(1, 0), pi / 2.0, ());
TEST_ALMOST_EQUAL_ULPS(atan2(-1, 0), -pi / 2.0, ());
TEST_ALMOST_EQUAL_ULPS(atan2(0, 1), 0.0, ());
TEST_ALMOST_EQUAL_ULPS(atan2(0, -1), pi, ());
TEST_ALMOST_EQUAL_ULPS(atan2(1, 1), pi/4.0, ());
TEST_ALMOST_EQUAL_ULPS(atan2(1, 1), pi / 4.0, ());
}
namespace
{
void check_avg(double arr[], size_t n, double v)
{
ang::AverageCalc calc;
for (size_t i = 0; i < n; ++i)
calc.Add(arr[i]);
void check_avg(double arr[], size_t n, double v)
{
ang::AverageCalc calc;
for (size_t i = 0; i < n; ++i)
calc.Add(arr[i]);
double const avg = calc.GetAverage();
TEST(is_equal_angle(avg, v), (avg, v));
}
double const avg = calc.GetAverage();
TEST(is_equal_angle(avg, v), (avg, v));
}
} // namespace
UNIT_TEST(Average)
{
double constexpr eps = 1.0E-3;
double arr1[] = { math::pi-eps, -math::pi+eps };
double arr1[] = {math::pi - eps, -math::pi + eps};
TEST(is_equal_angle(ang::GetMiddleAngle(arr1[0], arr1[1]), math::pi), ());
check_avg(arr1, ARRAY_SIZE(arr1), math::pi);
double arr2[] = { eps, -eps };
double arr2[] = {eps, -eps};
TEST(is_equal_angle(ang::GetMiddleAngle(arr2[0], arr2[1]), 0.0), ());
check_avg(arr2, ARRAY_SIZE(arr2), 0.0);
}
@@ -75,47 +74,36 @@ UNIT_TEST(ShortestDistance)
UNIT_TEST(TwoVectorsAngle)
{
double constexpr eps = 1e-10;
TEST(AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(0, 0) /* p */,
m2::Point<double>(0, 1) /* p1 */,
m2::Point<double>(1, 0)) /* p2 */, 3 * math::pi2, eps), ());
TEST(AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(1, 1) /* p */,
m2::Point<double>(2, 2) /* p1 */,
m2::Point<double>(1, 2)) /* p2 */, math::pi4, eps), ());
TEST(AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(0, 0) /* p */,
m2::Point<double>(1, 0) /* p1 */,
m2::Point<double>(0, -1)) /* p2 */, 3 * math::pi2, eps), ());
TEST(AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(0, 0) /* p */,
m2::Point<double>(1, 0) /* p1 */,
m2::Point<double>(-1, 0)) /* p2 */, math::pi, eps), ());
TEST(AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(0, 0) /* p */, m2::Point<double>(0, 1) /* p1 */,
m2::Point<double>(1, 0)) /* p2 */,
3 * math::pi2, eps),
());
TEST(AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(1, 1) /* p */, m2::Point<double>(2, 2) /* p1 */,
m2::Point<double>(1, 2)) /* p2 */,
math::pi4, eps),
());
TEST(AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(0, 0) /* p */, m2::Point<double>(1, 0) /* p1 */,
m2::Point<double>(0, -1)) /* p2 */,
3 * math::pi2, eps),
());
TEST(AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(0, 0) /* p */, m2::Point<double>(1, 0) /* p1 */,
m2::Point<double>(-1, 0)) /* p2 */,
math::pi, eps),
());
}
UNIT_TEST(Azimuth)
{
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(-1, 0),
m2::Point<double>(0, 1),
math::pi2), -math::pi4), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(-1, 0),
m2::Point<double>(0, 1),
0.0), math::pi4), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(-1, 1),
m2::Point<double>(1, -1),
0.0), 3 * math::pi4), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(1, 1),
m2::Point<double>(0, 1),
-math::pi2), 0.0), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(1, -1),
m2::Point<double>(-1, -1),
math::pi), math::pi2), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(0, 0),
m2::Point<double>(-1, -1),
math::pi4), math::pi), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(0.5, -0.5),
m2::Point<double>(-0.5, 0.5),
math::pi4), -math::pi2), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(0.1, 0.1),
m2::Point<double>(0.2, 0.2),
math::pi4), 0.0), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(0.7, 0.7),
m2::Point<double>(-0.2, -0.2),
math::pi2), 3 * math::pi4), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(-1, 0), m2::Point<double>(0, 1), math::pi2), -math::pi4), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(-1, 0), m2::Point<double>(0, 1), 0.0), math::pi4), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(-1, 1), m2::Point<double>(1, -1), 0.0), 3 * math::pi4), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(1, 1), m2::Point<double>(0, 1), -math::pi2), 0.0), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(1, -1), m2::Point<double>(-1, -1), math::pi), math::pi2), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(0, 0), m2::Point<double>(-1, -1), math::pi4), math::pi), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(0.5, -0.5), m2::Point<double>(-0.5, 0.5), math::pi4), -math::pi2),
());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(0.1, 0.1), m2::Point<double>(0.2, 0.2), math::pi4), 0.0), ());
TEST(is_equal_angle(ang::Azimuth(m2::Point<double>(0.7, 0.7), m2::Point<double>(-0.2, -0.2), math::pi2),
3 * math::pi4),
());
}

View File

@@ -29,7 +29,7 @@ UNIT_TEST(AnyRect_TestConvertFrom)
AnyRectD const r(PointD(100, 100), ang::Angle<double>(math::pi / 6), RectD(0, 0, 10, 10));
double const sqrt3 = sqrt(3.0);
TEST(r.ConvertFrom(PointD(50, 0)).EqualDxDy(PointD(100 + 50 * sqrt3 / 2 , 100 + 50 * 1 / 2.0), 10e-5), ());
TEST(r.ConvertFrom(PointD(50, 0)).EqualDxDy(PointD(100 + 50 * sqrt3 / 2, 100 + 50 * 1 / 2.0), 10e-5), ());
TEST(r.ConvertTo(PointD(100 + 50 * sqrt3 / 2, 100 + 50 * 1.0 / 2)).EqualDxDy(PointD(50, 0), 10e-5), ());
}

View File

@@ -11,28 +11,18 @@
UNIT_TEST(AreaOnEarth_Circle)
{
double const kEarthSurfaceArea = 4.0 * math::pi * ms::kEarthRadiusMeters * ms::kEarthRadiusMeters;
TEST_ALMOST_EQUAL_ABS(ms::CircleAreaOnEarth(math::pi * ms::kEarthRadiusMeters),
kEarthSurfaceArea,
1e-1, ());
TEST_ALMOST_EQUAL_ABS(ms::CircleAreaOnEarth(math::pi * ms::kEarthRadiusMeters), kEarthSurfaceArea, 1e-1, ());
TEST_ALMOST_EQUAL_ABS(ms::CircleAreaOnEarth(2.0 /* radiusMeters */),
math::pi * 2.0 * 2.0,
1e-2, ());
TEST_ALMOST_EQUAL_ABS(ms::CircleAreaOnEarth(2.0 /* radiusMeters */), math::pi * 2.0 * 2.0, 1e-2, ());
TEST_ALMOST_EQUAL_ABS(ms::CircleAreaOnEarth(2000.0 /* radiusMeters */),
math::pi * 2000.0 * 2000.0,
1.0, ());
TEST_ALMOST_EQUAL_ABS(ms::CircleAreaOnEarth(2000.0 /* radiusMeters */), math::pi * 2000.0 * 2000.0, 1.0, ());
}
UNIT_TEST(AreaOnEarth_ThreePoints)
{
double const kEarthSurfaceArea = 4.0 * math::pi * ms::kEarthRadiusMeters * ms::kEarthRadiusMeters;
TEST_ALMOST_EQUAL_ABS(ms::AreaOnEarth({90.0, 0.0}, {0.0, 0.0}, {0.0, 90.0}),
kEarthSurfaceArea / 8.0,
1e-1, ());
TEST_ALMOST_EQUAL_ABS(ms::AreaOnEarth({90.0, 0.0}, {0.0, 0.0}, {0.0, 90.0}), kEarthSurfaceArea / 8.0, 1e-1, ());
TEST_ALMOST_EQUAL_ABS(ms::AreaOnEarth({90.0, 0.0}, {0.0, 90.0}, {0.0, -90.0}),
kEarthSurfaceArea / 4.0,
1e-1, ());
TEST_ALMOST_EQUAL_ABS(ms::AreaOnEarth({90.0, 0.0}, {0.0, 90.0}, {0.0, -90.0}), kEarthSurfaceArea / 4.0, 1e-1, ());
}

View File

@@ -30,4 +30,4 @@ UNIT_TEST(BoundingBox_Smoke)
TEST(bbox.HasPoint(0.5, 0.5), ());
}
}
} // namespace bounding_box_tests
} // namespace bounding_box_tests

View File

@@ -48,18 +48,16 @@ UNIT_TEST(CalipersBox_Smoke)
vector<PointD> const points = {
{PointD(0, 0), PointD(-2, 3), PointD(1, 5), PointD(3, 2), PointD(1, 2), PointD(0, 3)}};
CalipersBox const cbox(points);
TEST_EQUAL(cbox.Points(),
(vector<PointD>{{PointD(-2, 3), PointD(0, 0), PointD(3, 2), PointD(1, 5)}}), ());
TEST_EQUAL(cbox.Points(), (vector<PointD>{{PointD(-2, 3), PointD(0, 0), PointD(3, 2), PointD(1, 5)}}), ());
for (auto const & p : points)
TEST(cbox.HasPoint(p), (p));
TEST(!cbox.HasPoint(1, 0), ());
}
{
vector<PointD> const points = {{PointD(0, 0), PointD(1, 0), PointD(0, 5), PointD(1, 5),
PointD(-2, 2), PointD(-2, 3), PointD(3, 2), PointD(3, 3)}};
vector<PointD> const expected = {
{PointD(-2.5, 2.5), PointD(0.5, -0.5), PointD(3.5, 2.5), PointD(0.5, 5.5)}};
vector<PointD> const points = {{PointD(0, 0), PointD(1, 0), PointD(0, 5), PointD(1, 5), PointD(-2, 2),
PointD(-2, 3), PointD(3, 2), PointD(3, 3)}};
vector<PointD> const expected = {{PointD(-2.5, 2.5), PointD(0.5, -0.5), PointD(3.5, 2.5), PointD(0.5, 5.5)}};
CalipersBox const cbox(points);
TEST_EQUAL(cbox.Points(), expected, ());

View File

@@ -175,7 +175,8 @@ UNIT_TEST(CellId_LessQueueOrder)
}
sort(tst.begin(), tst.end(), m2::CellId<4>::LessLevelOrder());
TEST_EQUAL(tst, exp, ());
} while (next_permutation(e.begin(), e.end()));
}
while (next_permutation(e.begin(), e.end()));
}
UNIT_TEST(CellId_LessStackOrder)
@@ -199,7 +200,8 @@ UNIT_TEST(CellId_LessStackOrder)
}
sort(tst.begin(), tst.end(), m2::CellId<4>::LessPreOrder());
TEST_EQUAL(tst, exp, ());
} while (next_permutation(e.begin(), e.end()));
}
while (next_permutation(e.begin(), e.end()));
}
UNIT_TEST(CellId_IsStringValid)
@@ -228,27 +230,8 @@ UNIT_TEST(CellId_ToAndFromInt64ZOrder)
}
vector<string> const atDepth3 = {
"",
"0",
"00",
"01",
"02",
"03",
"1",
"10",
"11",
"12",
"13",
"2",
"20",
"21",
"22",
"23",
"3",
"30",
"31",
"32",
"33",
"", "0", "00", "01", "02", "03", "1", "10", "11", "12", "13",
"2", "20", "21", "22", "23", "3", "30", "31", "32", "33",
};
for (uint64_t id = 1; id <= atDepth3.size(); ++id)

View File

@@ -1,9 +1,9 @@
#include "testing/testing.hpp"
#include "geometry/distance_on_sphere.hpp"
#include "geometry/point2d.hpp"
#include "geometry/mercator.hpp"
#include "geometry/circle_on_earth.hpp"
#include "geometry/distance_on_sphere.hpp"
#include "geometry/mercator.hpp"
#include "geometry/point2d.hpp"
#include "base/math.hpp"
@@ -12,8 +12,7 @@
namespace
{
void TestGeometryAlmostEqualAbs(std::vector<m2::PointD> const & geometry,
std::vector<m2::PointD> const & answer,
void TestGeometryAlmostEqualAbs(std::vector<m2::PointD> const & geometry, std::vector<m2::PointD> const & answer,
double eps)
{
TEST_EQUAL(geometry.size(), answer.size(), ());
@@ -22,9 +21,8 @@ void TestGeometryAlmostEqualAbs(std::vector<m2::PointD> const & geometry,
TEST_ALMOST_EQUAL_ABS(geometry[i], answer[i], eps, ());
}
void TestGeometryAlmostEqualMeters(std::vector<m2::PointD> const & geometry,
std::vector<m2::PointD> const & answer,
double epsMeters)
void TestGeometryAlmostEqualMeters(std::vector<m2::PointD> const & geometry, std::vector<m2::PointD> const & answer,
double epsMeters)
{
TEST_EQUAL(geometry.size(), answer.size(), ());
@@ -37,15 +35,10 @@ UNIT_TEST(CircleOnEarth)
{
ms::LatLon const center(90.0 /* lat */, 0.0 /* lon */);
double const radiusMeters = 2.0 * math::pi * ms::kEarthRadiusMeters / 4.0;
auto const geometry =
ms::CreateCircleGeometryOnEarth(center, radiusMeters, 90.0 /* angleStepDegree */);
auto const geometry = ms::CreateCircleGeometryOnEarth(center, radiusMeters, 90.0 /* angleStepDegree */);
std::vector<m2::PointD> const result = {
mercator::FromLatLon(0.0, 0.0),
mercator::FromLatLon(0.0, 90.0),
mercator::FromLatLon(0.0, 180.0),
mercator::FromLatLon(0.0, -90.0)
};
std::vector<m2::PointD> const result = {mercator::FromLatLon(0.0, 0.0), mercator::FromLatLon(0.0, 90.0),
mercator::FromLatLon(0.0, 180.0), mercator::FromLatLon(0.0, -90.0)};
TestGeometryAlmostEqualAbs(geometry, result, 1e-9 /* eps */);
}
@@ -68,15 +61,13 @@ UNIT_TEST(CircleOnEarthEquator)
while (angleSumRad < 2 * math::pi)
{
angleSumRad += kStepRad;
result.emplace_back(point.x + kRadiusMercator * cos(angleRad),
point.y + kRadiusMercator * sin(angleRad));
result.emplace_back(point.x + kRadiusMercator * cos(angleRad), point.y + kRadiusMercator * sin(angleRad));
angleRad += kStepRad;
if (angleRad > 2 * math::pi)
angleRad -= 2 * math::pi;
}
auto const geometry =
ms::CreateCircleGeometryOnEarth(center, kRadiusMeters, kAngleStepDegree);
auto const geometry = ms::CreateCircleGeometryOnEarth(center, kRadiusMeters, kAngleStepDegree);
TestGeometryAlmostEqualMeters(geometry, result, 20.0 /* epsMeters */);
}

View File

@@ -72,7 +72,7 @@ UNIT_TEST(Clipping_ClipTriangleByRect)
result1.push_back(p2);
result1.push_back(p3);
});
vector<m2::PointD> expectedResult1 = { m2::PointD(0.5, 0.5), m2::PointD(0.5, -0.5), m2::PointD(0.0, 0.0) };
vector<m2::PointD> expectedResult1 = {m2::PointD(0.5, 0.5), m2::PointD(0.5, -0.5), m2::PointD(0.0, 0.0)};
TEST(CompareTriangleLists(result1, expectedResult1), (result1, expectedResult1));
// 1 point inside.
@@ -84,7 +84,7 @@ UNIT_TEST(Clipping_ClipTriangleByRect)
result2.push_back(p2);
result2.push_back(p3);
});
vector<m2::PointD> expectedResult2 = { m2::PointD(0.0, 0.0), m2::PointD(1.0, 1.0), m2::PointD(1.0, -1.0) };
vector<m2::PointD> expectedResult2 = {m2::PointD(0.0, 0.0), m2::PointD(1.0, 1.0), m2::PointD(1.0, -1.0)};
TEST(CompareTriangleLists(result2, expectedResult2), (result2, expectedResult2));
// 2 points inside.
@@ -96,8 +96,8 @@ UNIT_TEST(Clipping_ClipTriangleByRect)
result3.push_back(p2);
result3.push_back(p3);
});
vector<m2::PointD> expectedResult3 = { m2::PointD(0.0, 0.5), m2::PointD(1.0, 0.25), m2::PointD(1.0, -0.25),
m2::PointD(0.0, 0.5), m2::PointD(1.0, -0.25), m2::PointD(0.0, -0.5) };
vector<m2::PointD> expectedResult3 = {m2::PointD(0.0, 0.5), m2::PointD(1.0, 0.25), m2::PointD(1.0, -0.25),
m2::PointD(0.0, 0.5), m2::PointD(1.0, -0.25), m2::PointD(0.0, -0.5)};
TEST(CompareTriangleLists(result3, expectedResult3), (result3, expectedResult3));
// 2 edges clipping.
@@ -109,9 +109,9 @@ UNIT_TEST(Clipping_ClipTriangleByRect)
result4.push_back(p2);
result4.push_back(p3);
});
vector<m2::PointD> expectedResult4 = { m2::PointD(0.0, 0.0), m2::PointD(0.0, 1.0), m2::PointD(0.5, 1.0),
m2::PointD(0.0, 0.0), m2::PointD(0.5, 1.0), m2::PointD(1.0, 0.5),
m2::PointD(0.0, 0.0), m2::PointD(1.0, 0.5), m2::PointD(1.0, 0.0) };
vector<m2::PointD> expectedResult4 = {m2::PointD(0.0, 0.0), m2::PointD(0.0, 1.0), m2::PointD(0.5, 1.0),
m2::PointD(0.0, 0.0), m2::PointD(0.5, 1.0), m2::PointD(1.0, 0.5),
m2::PointD(0.0, 0.0), m2::PointD(1.0, 0.5), m2::PointD(1.0, 0.0)};
TEST(CompareTriangleLists(result4, expectedResult4), (result4, expectedResult4));
// 3 edges clipping.
@@ -123,10 +123,10 @@ UNIT_TEST(Clipping_ClipTriangleByRect)
result5.push_back(p2);
result5.push_back(p3);
});
vector<m2::PointD> expectedResult5 = { m2::PointD(-1.0, 0.5), m2::PointD(-0.5, 1.0), m2::PointD(0.5, 1.0),
m2::PointD(-1.0, 0.5), m2::PointD(0.5, 1.0), m2::PointD(1.0, 0.5),
m2::PointD(-1.0, 0.5), m2::PointD(1.0, 0.5), m2::PointD(1.0, 0.0),
m2::PointD(-1.0, 0.5), m2::PointD(1.0, 0.0), m2::PointD(-1.0, 0.0) };
vector<m2::PointD> expectedResult5 = {m2::PointD(-1.0, 0.5), m2::PointD(-0.5, 1.0), m2::PointD(0.5, 1.0),
m2::PointD(-1.0, 0.5), m2::PointD(0.5, 1.0), m2::PointD(1.0, 0.5),
m2::PointD(-1.0, 0.5), m2::PointD(1.0, 0.5), m2::PointD(1.0, 0.0),
m2::PointD(-1.0, 0.5), m2::PointD(1.0, 0.0), m2::PointD(-1.0, 0.0)};
TEST(CompareTriangleLists(result5, expectedResult5), (result5, expectedResult5));
// Completely outside.
@@ -150,8 +150,8 @@ UNIT_TEST(Clipping_ClipTriangleByRect)
result7.push_back(p2);
result7.push_back(p3);
});
vector<m2::PointD> expectedResult7 = { m2::PointD(0.5, 0.5), m2::PointD(0.5, 1.0), m2::PointD(1.0, 1.0),
m2::PointD(0.5, 0.5), m2::PointD(1.0, 1.0), m2::PointD(1.0, 0.5) };
vector<m2::PointD> expectedResult7 = {m2::PointD(0.5, 0.5), m2::PointD(0.5, 1.0), m2::PointD(1.0, 1.0),
m2::PointD(0.5, 0.5), m2::PointD(1.0, 1.0), m2::PointD(1.0, 0.5)};
TEST(CompareTriangleLists(result7, expectedResult7), (result7, expectedResult7));
// Triangle covers rect.
@@ -163,8 +163,8 @@ UNIT_TEST(Clipping_ClipTriangleByRect)
result8.push_back(p2);
result8.push_back(p3);
});
vector<m2::PointD> expectedResult8 = { m2::PointD(-1.0, 1.0), m2::PointD(1.0, 1.0), m2::PointD(1.0, -1.0),
m2::PointD(1.0, -1.0), m2::PointD(-1.0, -1.0), m2::PointD(-1.0, 1.0) };
vector<m2::PointD> expectedResult8 = {m2::PointD(-1.0, 1.0), m2::PointD(1.0, 1.0), m2::PointD(1.0, -1.0),
m2::PointD(1.0, -1.0), m2::PointD(-1.0, -1.0), m2::PointD(-1.0, 1.0)};
TEST(CompareTriangleLists(result8, expectedResult8), (result8, expectedResult8));
// Clip with an angle of rect.
@@ -176,7 +176,7 @@ UNIT_TEST(Clipping_ClipTriangleByRect)
result9.push_back(p2);
result9.push_back(p3);
});
vector<m2::PointD> expectedResult9 = { m2::PointD(0.5, -1.0), m2::PointD(1.0, -0.5), m2::PointD(1.0, -1.0) };
vector<m2::PointD> expectedResult9 = {m2::PointD(0.5, -1.0), m2::PointD(1.0, -0.5), m2::PointD(1.0, -1.0)};
TEST(CompareTriangleLists(result9, expectedResult9), (result9, expectedResult9));
// Clip with an angle of rect.
@@ -188,8 +188,8 @@ UNIT_TEST(Clipping_ClipTriangleByRect)
result10.push_back(p2);
result10.push_back(p3);
});
vector<m2::PointD> expectedResult10 = { m2::PointD(-1.0, -0.5), m2::PointD(-0.5, -0.5), m2::PointD(-0.5, -1.0),
m2::PointD(-1.0, -0.5), m2::PointD(-0.5, -1.0), m2::PointD(-1.0, -1.0) };
vector<m2::PointD> expectedResult10 = {m2::PointD(-1.0, -0.5), m2::PointD(-0.5, -0.5), m2::PointD(-0.5, -1.0),
m2::PointD(-1.0, -0.5), m2::PointD(-0.5, -1.0), m2::PointD(-1.0, -1.0)};
TEST(CompareTriangleLists(result10, expectedResult10), (result10, expectedResult10));
// Clip with 3 angles of rect.
@@ -201,9 +201,9 @@ UNIT_TEST(Clipping_ClipTriangleByRect)
result11.push_back(p2);
result11.push_back(p3);
});
vector<m2::PointD> expectedResult11 = { m2::PointD(0.0, -1.0), m2::PointD(-1.0, 0.0), m2::PointD(-1.0, 1.0),
m2::PointD(0.0, -1.0), m2::PointD(-1.0, 1.0), m2::PointD(1.0, 1.0),
m2::PointD(0.0, -1.0), m2::PointD(1.0, 1.0), m2::PointD(1.0, -1.0) };
vector<m2::PointD> expectedResult11 = {m2::PointD(0.0, -1.0), m2::PointD(-1.0, 0.0), m2::PointD(-1.0, 1.0),
m2::PointD(0.0, -1.0), m2::PointD(-1.0, 1.0), m2::PointD(1.0, 1.0),
m2::PointD(0.0, -1.0), m2::PointD(1.0, 1.0), m2::PointD(1.0, -1.0)};
TEST(CompareTriangleLists(result11, expectedResult11), (result11, expectedResult11));
}
@@ -217,7 +217,7 @@ UNIT_TEST(Clipping_ClipSplineByRect)
spline1->AddPoint(m2::PointD(-2.0, 0.0));
spline1->AddPoint(m2::PointD(2.0, 1.0));
vector<m2::SharedSpline> result1 = m2::ClipSplineByRect(r, spline1);
vector<m2::SharedSpline> expectedResult1 = ConstructSplineList({ { m2::PointD(-1.0, 0.25), m2::PointD(1.0, 0.75) } });
vector<m2::SharedSpline> expectedResult1 = ConstructSplineList({{m2::PointD(-1.0, 0.25), m2::PointD(1.0, 0.75)}});
TEST(CompareSplineLists(result1, expectedResult1), ());
// Intersection. Several segments.
@@ -228,8 +228,8 @@ UNIT_TEST(Clipping_ClipSplineByRect)
spline2->AddPoint(m2::PointD(0.5, -2.0));
spline2->AddPoint(m2::PointD(-0.5, -0.5));
vector<m2::SharedSpline> result2 = m2::ClipSplineByRect(r, spline2);
vector<m2::SharedSpline> expectedResult2 = ConstructSplineList({ { m2::PointD(-1.0, 0.25), m2::PointD(1.0, 0.75) },
{ m2::PointD(-0.166666666, -1.0), m2::PointD(-0.5, -0.5) } });
vector<m2::SharedSpline> expectedResult2 = ConstructSplineList(
{{m2::PointD(-1.0, 0.25), m2::PointD(1.0, 0.75)}, {m2::PointD(-0.166666666, -1.0), m2::PointD(-0.5, -0.5)}});
TEST(CompareSplineLists(result2, expectedResult2), ());
// Completely outside.
@@ -247,7 +247,7 @@ UNIT_TEST(Clipping_ClipSplineByRect)
spline4->AddPoint(m2::PointD(-0.5, 0.0));
spline4->AddPoint(m2::PointD(0.5, 0.5));
vector<m2::SharedSpline> result4 = m2::ClipSplineByRect(r, spline4);
vector<m2::SharedSpline> expectedResult4 = ConstructSplineList({ { m2::PointD(-0.5, 0.0), m2::PointD(0.5, 0.5) } });
vector<m2::SharedSpline> expectedResult4 = ConstructSplineList({{m2::PointD(-0.5, 0.0), m2::PointD(0.5, 0.5)}});
TEST(CompareSplineLists(result4, expectedResult4), ());
// Intersection. Long spline.
@@ -258,8 +258,8 @@ UNIT_TEST(Clipping_ClipSplineByRect)
spline5->AddPoint(m2::PointD(0.5, 0.5));
spline5->AddPoint(m2::PointD(2.0, 1.0));
vector<m2::SharedSpline> result5 = m2::ClipSplineByRect(r, spline5);
vector<m2::SharedSpline> expectedResult5 = ConstructSplineList({ { m2::PointD(-1.0, 0.0), m2::PointD(0.0, 0.0),
m2::PointD(0.5, 0.5), m2::PointD(1.0, 0.66666666) } });
vector<m2::SharedSpline> expectedResult5 = ConstructSplineList(
{{m2::PointD(-1.0, 0.0), m2::PointD(0.0, 0.0), m2::PointD(0.5, 0.5), m2::PointD(1.0, 0.66666666)}});
TEST(CompareSplineLists(result5, expectedResult5), ());
// Intersection. Several segments.
@@ -271,8 +271,8 @@ UNIT_TEST(Clipping_ClipSplineByRect)
spline6->AddPoint(m2::PointD(0.0, 1.5));
spline6->AddPoint(m2::PointD(0.0, 0.0));
vector<m2::SharedSpline> result6 = m2::ClipSplineByRect(r, spline6);
vector<m2::SharedSpline> expectedResult6 = ConstructSplineList({ { m2::PointD(-1.0, 0.0), m2::PointD(-0.5, 1.0) },
{ m2::PointD(0.0, 1.0), m2::PointD(0.0, 0.0) } });
vector<m2::SharedSpline> expectedResult6 = ConstructSplineList(
{{m2::PointD(-1.0, 0.0), m2::PointD(-0.5, 1.0)}, {m2::PointD(0.0, 1.0), m2::PointD(0.0, 0.0)}});
TEST(CompareSplineLists(result6, expectedResult6), ());
}
} // namespace clipping_test
} // namespace clipping_test

View File

@@ -12,7 +12,7 @@ UNIT_TEST(Rect)
{
m2::RectD rect(0, 0, 500, 300);
double factor[] = { 0.2, 0.3, 0.5, 0.7, 1.0, 1.3, 1.5, 2.0 };
double factor[] = {0.2, 0.3, 0.5, 0.7, 1.0, 1.3, 1.5, 2.0};
for (size_t i = 0; i < ARRAY_SIZE(factor); ++i)
{
m2::RectD r(rect);
@@ -35,5 +35,5 @@ UNIT_TEST(Point)
TEST(is_equal(start.Move(l, a), m2::PointD(1, 1)), ());
TEST(is_equal(start.Move(l, math::pi - a), m2::PointD(-1, 1)), ());
TEST(is_equal(start.Move(l, -math::pi + a), m2::PointD(-1, -1)), ());
TEST(is_equal(start.Move(l, - a), m2::PointD(1, -1)), ());
TEST(is_equal(start.Move(l, -a), m2::PointD(1, -1)), ());
}

View File

@@ -23,28 +23,24 @@ UNIT_TEST(ConvexHull_Smoke)
TEST_EQUAL(BuildConvexHull({PointD(0, 0)}), vector<PointD>{PointD(0, 0)}, ());
TEST_EQUAL(BuildConvexHull({PointD(0, 0), PointD(0, 0)}), vector<PointD>{PointD(0, 0)}, ());
TEST_EQUAL(BuildConvexHull({PointD(0, 0), PointD(1, 1), PointD(0, 0)}),
vector<PointD>({PointD(0, 0), PointD(1, 1)}), ());
TEST_EQUAL(BuildConvexHull({PointD(0, 0), PointD(1, 1), PointD(0, 0)}), vector<PointD>({PointD(0, 0), PointD(1, 1)}),
());
TEST_EQUAL(BuildConvexHull({PointD(0, 0), PointD(1, 1), PointD(2, 2)}),
vector<PointD>({PointD(0, 0), PointD(2, 2)}), ());
TEST_EQUAL(BuildConvexHull({PointD(0, 0), PointD(1, 1), PointD(2, 2)}), vector<PointD>({PointD(0, 0), PointD(2, 2)}),
());
{
int const kXMax = 100;
int const kYMax = 200;
vector<PointD> points;
for (int x = 0; x <= kXMax; ++x)
{
for (int y = 0; y <= kYMax; ++y)
points.emplace_back(x, y);
}
TEST_EQUAL(BuildConvexHull(points), vector<PointD>({PointD(0, 0), PointD(kXMax, 0),
PointD(kXMax, kYMax), PointD(0, kYMax)}),
());
TEST_EQUAL(BuildConvexHull(points),
vector<PointD>({PointD(0, 0), PointD(kXMax, 0), PointD(kXMax, kYMax), PointD(0, kYMax)}), ());
}
TEST_EQUAL(
BuildConvexHull({PointD(0, 0), PointD(0, 5), PointD(10, 5), PointD(3, 3), PointD(10, 0)}),
vector<PointD>({PointD(0, 0), PointD(10, 0), PointD(10, 5), PointD(0, 5)}), ());
TEST_EQUAL(BuildConvexHull({PointD(0, 0), PointD(0, 5), PointD(10, 5), PointD(3, 3), PointD(10, 0)}),
vector<PointD>({PointD(0, 0), PointD(10, 0), PointD(10, 5), PointD(0, 5)}), ());
}
} // namespace convex_hull_tests

View File

@@ -20,7 +20,7 @@ using CellId = m2::CellId<5>;
UNIT_TEST(CoverTriangle_Simple)
{
vector<CellId> v;
covering::Covering<CellId> c(m2::PointD(3*2, 3*2), m2::PointD(4*2, 12*2), m2::PointD(14*2, 3*2));
covering::Covering<CellId> c(m2::PointD(3 * 2, 3 * 2), m2::PointD(4 * 2, 12 * 2), m2::PointD(14 * 2, 3 * 2));
c.OutputToVector(v);
vector<CellId> e;
e.push_back(CellId("03"));
@@ -97,14 +97,10 @@ UNIT_TEST(Covering_Append_Simple)
UNIT_TEST(IntersectCellWithTriangle_EmptyTriangle)
{
m2::PointD pt(27.0, 31.0);
TEST_EQUAL(covering::CELL_OBJECT_NO_INTERSECTION,
covering::IntersectCellWithTriangle(CellId("0"), pt, pt, pt), ());
TEST_EQUAL(covering::CELL_OBJECT_NO_INTERSECTION,
covering::IntersectCellWithTriangle(CellId("1"), pt, pt, pt), ());
TEST_EQUAL(covering::CELL_OBJECT_NO_INTERSECTION,
covering::IntersectCellWithTriangle(CellId("2"), pt, pt, pt), ());
TEST_EQUAL(covering::OBJECT_INSIDE_CELL,
covering::IntersectCellWithTriangle(CellId("3"), pt, pt, pt), ());
TEST_EQUAL(covering::CELL_OBJECT_NO_INTERSECTION, covering::IntersectCellWithTriangle(CellId("0"), pt, pt, pt), ());
TEST_EQUAL(covering::CELL_OBJECT_NO_INTERSECTION, covering::IntersectCellWithTriangle(CellId("1"), pt, pt, pt), ());
TEST_EQUAL(covering::CELL_OBJECT_NO_INTERSECTION, covering::IntersectCellWithTriangle(CellId("2"), pt, pt, pt), ());
TEST_EQUAL(covering::OBJECT_INSIDE_CELL, covering::IntersectCellWithTriangle(CellId("3"), pt, pt, pt), ());
}
UNIT_TEST(Covering_EmptyTriangle)

View File

@@ -6,48 +6,44 @@
namespace test
{
inline bool is_equal(double a1, double a2)
{
return (fabs(a1 - a2) < 1.0E-10);
}
inline bool is_equal_atan(double x, double y, double v)
{
return is_equal(ang::AngleTo(m2::PointD(0, 0), m2::PointD(x, y)), v);
}
inline bool is_equal_angle(double a1, double a2)
{
double const two_pi = 2.0*math::pi;
if (a1 < 0.0) a1 += two_pi;
if (a2 < 0.0) a2 += two_pi;
return is_equal(a1, a2);
}
inline bool is_equal(m2::PointD const & p1, m2::PointD const & p2)
{
return p1.EqualDxDy(p2, 1.0E-8);
}
inline bool is_equal_center(m2::RectD const & r1, m2::RectD const & r2)
{
return is_equal(r1.Center(), r2.Center());
}
struct strict_equal
{
bool operator() (m2::PointD const & p1, m2::PointD const & p2) const
{
return p1 == p2;
}
};
struct epsilon_equal
{
bool operator() (m2::PointD const & p1, m2::PointD const & p2) const
{
return is_equal(p1, p2);
}
};
inline bool is_equal(double a1, double a2)
{
return (fabs(a1 - a2) < 1.0E-10);
}
inline bool is_equal_atan(double x, double y, double v)
{
return is_equal(ang::AngleTo(m2::PointD(0, 0), m2::PointD(x, y)), v);
}
inline bool is_equal_angle(double a1, double a2)
{
double const two_pi = 2.0 * math::pi;
if (a1 < 0.0)
a1 += two_pi;
if (a2 < 0.0)
a2 += two_pi;
return is_equal(a1, a2);
}
inline bool is_equal(m2::PointD const & p1, m2::PointD const & p2)
{
return p1.EqualDxDy(p2, 1.0E-8);
}
inline bool is_equal_center(m2::RectD const & r1, m2::RectD const & r2)
{
return is_equal(r1.Center(), r2.Center());
}
struct strict_equal
{
bool operator()(m2::PointD const & p1, m2::PointD const & p2) const { return p1 == p2; }
};
struct epsilon_equal
{
bool operator()(m2::PointD const & p1, m2::PointD const & p2) const { return is_equal(p1, p2); }
};
} // namespace test

View File

@@ -2,15 +2,14 @@
#include "testing/testing.hpp"
#include "geometry/rect_intersect.hpp"
#include "geometry/angles.hpp"
#include "geometry/rect_intersect.hpp"
using namespace test;
namespace
{
typedef m2::PointD P;
typedef m2::PointD P;
}
m2::PointD get_point(m2::RectD const & r, int ind)
@@ -21,9 +20,7 @@ m2::PointD get_point(m2::RectD const & r, int ind)
case 1: return r.LeftTop();
case 2: return r.RightTop();
case 3: return r.RightBottom();
default:
ASSERT ( false, () );
return m2::PointD();
default: ASSERT(false, ()); return m2::PointD();
}
}
@@ -31,14 +28,16 @@ void make_section_longer(m2::PointD & p1, m2::PointD & p2, double sm)
{
if (p1.x == p2.x)
{
if (p1.y > p2.y) sm = -sm;
if (p1.y > p2.y)
sm = -sm;
p1.y -= sm;
p2.y += sm;
}
else if (p1.y == p2.y)
{
if (p1.x > p2.x) sm = -sm;
if (p1.x > p2.x)
sm = -sm;
p1.x -= sm;
p2.x += sm;
@@ -74,8 +73,8 @@ void check_intersect_boundaries(m2::RectD const & r)
{
for (int i = 0; i < 4; ++i)
{
check_full_equal(r, get_point(r, i), get_point(r, i+1), strict_equal());
check_inside(r, get_point(r, i), get_point(r, i+1));
check_full_equal(r, get_point(r, i), get_point(r, i + 1), strict_equal());
check_inside(r, get_point(r, i), get_point(r, i + 1));
}
}
@@ -83,8 +82,8 @@ void check_intersect_diagonal(m2::RectD const & r)
{
for (int i = 0; i < 4; ++i)
{
check_full_equal(r, get_point(r, i), get_point(r, i+2), epsilon_equal());
check_inside(r, get_point(r, i), get_point(r, i+2));
check_full_equal(r, get_point(r, i), get_point(r, i + 2), epsilon_equal());
check_inside(r, get_point(r, i), get_point(r, i + 2));
}
}
@@ -92,8 +91,8 @@ void check_sides(m2::RectD const & r)
{
for (int i = 0; i < 4; ++i)
{
m2::PointD p1 = (get_point(r, i) + get_point(r, i+1)) / 2.0;
m2::PointD p2 = (get_point(r, i + 2) + get_point(r, i+3)) / 2.0;
m2::PointD p1 = (get_point(r, i) + get_point(r, i + 1)) / 2.0;
m2::PointD p2 = (get_point(r, i + 2) + get_point(r, i + 3)) / 2.0;
check_full_equal(r, p1, p2, strict_equal());
check_inside(r, p1, p2);
}
@@ -107,7 +106,7 @@ void check_eps_boundaries(m2::RectD const & r, double eps = 1.0E-6)
for (int i = 0; i < 4; ++i)
{
m2::PointD p1 = get_point(rr, i);
m2::PointD p2 = get_point(rr, i+1);
m2::PointD p2 = get_point(rr, i + 1);
TEST(!m2::Intersect(r, p1, p2), ());
}
@@ -116,7 +115,7 @@ void check_eps_boundaries(m2::RectD const & r, double eps = 1.0E-6)
rr.Inflate(-eps, -eps);
for (int i = 0; i < 4; ++i)
check_inside(r, get_point(rr, i), get_point(rr, i+1));
check_inside(r, get_point(rr, i), get_point(rr, i + 1));
}
UNIT_TEST(IntersectRect_Section)
@@ -130,15 +129,15 @@ UNIT_TEST(IntersectRect_Section)
namespace
{
void check_point_in_rect(m2::RectD const & r, m2::PointD const & p)
{
m2::PointD p1 = p;
m2::PointD p2 = p;
void check_point_in_rect(m2::RectD const & r, m2::PointD const & p)
{
m2::PointD p1 = p;
m2::PointD p2 = p;
TEST(m2::Intersect(r, p1, p2), ());
TEST(p == p1 && p == p2, ());
}
TEST(m2::Intersect(r, p1, p2), ());
TEST(p == p1 && p == p2, ());
}
} // namespace
UNIT_TEST(IntersectRect_Point)
{
@@ -147,14 +146,14 @@ UNIT_TEST(IntersectRect_Point)
for (int i = 0; i < 4; ++i)
{
check_point_in_rect(r, get_point(r, i));
check_point_in_rect(r, (get_point(r, i) + get_point(r, i+1)) / 2.0);
check_point_in_rect(r, (get_point(r, i) + get_point(r, i + 1)) / 2.0);
}
}
{
m2::RectD r(-1000, -1000, 1000, 1000);
double const eps = 1.0E-6;
P sm[] = { P(-eps, -eps), P(-eps, eps), P(eps, eps), P(eps, -eps) };
P sm[] = {P(-eps, -eps), P(-eps, eps), P(eps, eps), P(eps, -eps)};
for (int i = 0; i < 4; ++i)
{
P p1 = get_point(r, i);

View File

@@ -65,8 +65,7 @@ UNIT_TEST(IntersectionScore_TrianglesToPolygon)
std::vector<m2::PointD> triangiulated2 = {{0.0, 0.0}, {0.0, 9.0}, {10.0, 0.0},
{10.0, 0.0}, {0.0, 9.0}, {10.0, 9.0}};
auto const score =
geometry::GetIntersectionScoreForTriangulated(triangiulated1, triangiulated2);
auto const score = geometry::GetIntersectionScoreForTriangulated(triangiulated1, triangiulated2);
TEST(AlmostEqualAbs(score, 0.9, 1e-10), ());
}
@@ -87,8 +86,7 @@ UNIT_TEST(IntersectionScore_TrianglesToPolygon)
std::vector<m2::PointD> triangiulated2 = {{10.0, 10.0}, {10.0, 20.0}, {20.0, 10.0},
{20.0, 10.0}, {10.0, 20.0}, {20.0, 20.0}};
auto const score =
geometry::GetIntersectionScoreForTriangulated(triangiulated1, triangiulated2);
auto const score = geometry::GetIntersectionScoreForTriangulated(triangiulated1, triangiulated2);
TEST(AlmostEqualAbs(score, 0.0, 1e-10), ());
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
#include "testing/testing.hpp"
#include "geometry/latlon.hpp"
#include "geometry/point2d.hpp"
#include "geometry/mercator.hpp"
#include "geometry/point2d.hpp"
#include "testing/testing.hpp"
UNIT_TEST(LatLonPointConstructorTest)
{

View File

@@ -2,10 +2,9 @@
#include "geometry/mercator.hpp"
#include "base/math.hpp"
#include "base/macros.hpp"
#include "base/logging.hpp"
#include "base/macros.hpp"
#include "base/math.hpp"
UNIT_TEST(Mercator_Grid)
{
@@ -45,7 +44,7 @@ UNIT_TEST(Mercator_DirectInferseF)
UNIT_TEST(Mercator_ErrorToRadius)
{
double const points[] = { -85.0, -45.0, -10.0, -1.0, -0.003, 0.0, 0.003, 1.0, 10.0, 45.0, 85.0 };
double const points[] = {-85.0, -45.0, -10.0, -1.0, -0.003, 0.0, 0.003, 1.0, 10.0, 45.0, 85.0};
double const error1 = 1.0; // 1 metre
double const error10 = 10.0; // 10 metres
@@ -78,6 +77,5 @@ UNIT_TEST(Mercator_ErrorToRadius)
UNIT_TEST(Mercator_Sample1)
{
LOG(LINFO, (mercator::XToLon(27.531491200000001385),
mercator::YToLat(64.392864299248202542)));
LOG(LINFO, (mercator::XToLon(27.531491200000001385), mercator::YToLat(64.392864299248202542)));
}

View File

@@ -68,8 +68,7 @@ UNIT_TEST(NearbyPointsSweeper_Smoke)
{
uint8_t const priority = 0;
vector<PointD> const points = {PointD(0.0, 0.0), PointD(1.0, 1.0),
PointD(1.5, 0.0), PointD(1.5 + 1.01, 1.5 + 1.0)};
vector<PointD> const points = {PointD(0.0, 0.0), PointD(1.0, 1.0), PointD(1.5, 0.0), PointD(1.5 + 1.01, 1.5 + 1.0)};
NearbyPointsSweeper sweeper(1.0);
for (size_t i = 0; i < points.size(); ++i)
@@ -85,9 +84,8 @@ UNIT_TEST(NearbyPointsSweeper_Smoke)
{
uint8_t const priority = 0;
vector<PointD> const points = {PointD(0, 0), PointD(0, 0), PointD(1, 0),
PointD(0, 1), PointD(1, 1), PointD(1, 0),
PointD(0.5, 0.5), PointD(0, 1)};
vector<PointD> const points = {PointD(0, 0), PointD(0, 0), PointD(1, 0), PointD(0, 1),
PointD(1, 1), PointD(1, 0), PointD(0.5, 0.5), PointD(0, 1)};
NearbyPointsSweeper sweeper(10.0);
for (size_t i = 0; i < points.size(); ++i)
@@ -130,8 +128,8 @@ UNIT_TEST(NearbyPointsSweeper_Priority)
TEST_EQUAL(expected, actual, ());
}
{
vector<pair<PointD, uint8_t>> const objects = {{PointD(0.0, 0.0), 0}, {PointD(1.0, 1.0), 1},
{PointD(1.5, 0.0), 0}, {PointD(1.5 + 1.01, 1.5 + 1.0), 0}};
vector<pair<PointD, uint8_t>> const objects = {
{PointD(0.0, 0.0), 0}, {PointD(1.0, 1.0), 1}, {PointD(1.5, 0.0), 0}, {PointD(1.5 + 1.01, 1.5 + 1.0), 0}};
NearbyPointsSweeper sweeper(1.0);
for (size_t i = 0; i < objects.size(); ++i)

View File

@@ -12,7 +12,7 @@ void testDistance(ms::LatLon const & a, ms::LatLon const & b, double planDistanc
double const factDistance = oblate_spheroid::GetDistance(a, b);
TEST_ALMOST_EQUAL_ABS(factDistance, planDistance, kAccuracyEps, ());
}
}
} // namespace
UNIT_TEST(Distance_EdgeCaseEquatorialLine)
{

View File

@@ -36,15 +36,15 @@ UNIT_TEST(PackerTest_SimplePack)
m2::Packer::handle_t h2 = p.pack(5, 5);
// Possibly we should restore this checks
// Possibly we should restore this checks
// TEST_EQUAL(p.isPacked(h0), false, ());
// TEST_EQUAL(p.isPacked(h1), false, ());
// TEST_EQUAL(p.isPacked(h0), false, ());
// TEST_EQUAL(p.isPacked(h1), false, ());
TEST_EQUAL(p.isPacked(h2), true, ());
TEST_EQUAL(i, 7, ("Handlers priorities doesn't work"));
TEST_NOT_EQUAL( i, 12, ("Handlers priorities doesn't work"));
TEST_NOT_EQUAL(i, 12, ("Handlers priorities doesn't work"));
m2::RectU r2 = p.find(h2).second;
@@ -55,53 +55,23 @@ UNIT_TEST(PackerTest_HasRoom_Sequence)
{
m2::Packer p(20, 20);
m2::PointU pts[] = {
m2::PointU(10, 10),
m2::PointU(11, 3),
m2::PointU(5, 5),
m2::PointU(5, 5)
};
m2::PointU pts[] = {m2::PointU(10, 10), m2::PointU(11, 3), m2::PointU(5, 5), m2::PointU(5, 5)};
TEST(p.hasRoom(pts, sizeof(pts) / sizeof(m2::PointU)), ());
m2::PointU pts1[] = {
m2::PointU(10, 10),
m2::PointU(11, 3),
m2::PointU(5, 5),
m2::PointU(5, 5),
m2::PointU(16, 5)
};
m2::PointU pts1[] = {m2::PointU(10, 10), m2::PointU(11, 3), m2::PointU(5, 5), m2::PointU(5, 5), m2::PointU(16, 5)};
TEST(!p.hasRoom(pts1, sizeof(pts1) / sizeof(m2::PointU)), ());
m2::PointU pts2[] = {
m2::PointU(10, 10),
m2::PointU(11, 3),
m2::PointU(5, 5),
m2::PointU(5, 5),
m2::PointU(10, 6)
};
m2::PointU pts2[] = {m2::PointU(10, 10), m2::PointU(11, 3), m2::PointU(5, 5), m2::PointU(5, 5), m2::PointU(10, 6)};
TEST(!p.hasRoom(pts2, sizeof(pts2) / sizeof(m2::PointU)), ());
m2::PointU pts3[] = {
m2::PointU(10, 10),
m2::PointU(11, 3),
m2::PointU(5, 5),
m2::PointU(5, 5),
m2::PointU(15, 5)
};
m2::PointU pts3[] = {m2::PointU(10, 10), m2::PointU(11, 3), m2::PointU(5, 5), m2::PointU(5, 5), m2::PointU(15, 5)};
TEST(p.hasRoom(pts3, sizeof(pts3) / sizeof(m2::PointU)), ());
m2::PointU pts4[] = {
m2::PointU(10, 10),
m2::PointU(11, 3),
m2::PointU(5, 5),
m2::PointU(5, 5),
m2::PointU(16, 5)
};
m2::PointU pts4[] = {m2::PointU(10, 10), m2::PointU(11, 3), m2::PointU(5, 5), m2::PointU(5, 5), m2::PointU(16, 5)};
TEST(!p.hasRoom(pts4, sizeof(pts4) / sizeof(m2::PointU)), ());
}

View File

@@ -54,19 +54,12 @@ UNIT_TEST(ParametrizedSegment2D_ClosestPoint)
{
using P = m2::PointD;
P arr[][4] =
{
{ P(3, 4), P(0, 0), P(10, 0), P(3, 0) },
{ P(3, 4), P(0, 0), P(0, 10), P(0, 4) },
P arr[][4] = {{P(3, 4), P(0, 0), P(10, 0), P(3, 0)}, {P(3, 4), P(0, 0), P(0, 10), P(0, 4)},
{ P(3, 5), P(2, 2), P(5, 5), P(4, 4) },
{ P(5, 3), P(2, 2), P(5, 5), P(4, 4) },
{ P(2, 4), P(2, 2), P(5, 5), P(3, 3) },
{ P(4, 2), P(2, 2), P(5, 5), P(3, 3) },
{P(3, 5), P(2, 2), P(5, 5), P(4, 4)}, {P(5, 3), P(2, 2), P(5, 5), P(4, 4)},
{P(2, 4), P(2, 2), P(5, 5), P(3, 3)}, {P(4, 2), P(2, 2), P(5, 5), P(3, 3)},
{ P(5, 6), P(2, 2), P(5, 5), P(5, 5) },
{ P(1, 0), P(2, 2), P(5, 5), P(2, 2) }
};
{P(5, 6), P(2, 2), P(5, 5), P(5, 5)}, {P(1, 0), P(2, 2), P(5, 5), P(2, 2)}};
for (size_t i = 0; i < ARRAY_SIZE(arr); ++i)
{

View File

@@ -97,4 +97,4 @@ UNIT_TEST(Point3d_RotateXYZ)
auto const north = rotatedFirst.RotateAroundY(-angleDegree);
TEST_ALMOST_EQUAL_ABS(north, m3::PointD(0.0, 0.0, std::sqrt(3.0)), 1e-10, ());
}
} // namespace point3d_tests
} // namespace point3d_tests

View File

@@ -79,19 +79,10 @@ UNIT_TEST(GetArrowPoints)
UNIT_TEST(PointAtSegment)
{
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointF(0, 0), m2::PointF(1, 0), 0.5f),
m2::PointF(0.5f, 0.f)),
());
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointF(0, 0), m2::PointF(0, 1), 0.3f),
m2::PointF(0.f, 0.3f)),
());
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointD(0., 0.), m2::PointD(30., 40.), 5.),
m2::PointD(3., 4.)),
());
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointF(-3, -4), m2::PointF(-30, -40), 5.f),
m2::PointF(-6.f, -8.f)),
());
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointD(14., -48.), m2::PointD(70., -240.), 25.),
m2::PointD(21., -72.)),
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointF(0, 0), m2::PointF(1, 0), 0.5f), m2::PointF(0.5f, 0.f)), ());
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointF(0, 0), m2::PointF(0, 1), 0.3f), m2::PointF(0.f, 0.3f)), ());
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointD(0., 0.), m2::PointD(30., 40.), 5.), m2::PointD(3., 4.)), ());
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointF(-3, -4), m2::PointF(-30, -40), 5.f), m2::PointF(-6.f, -8.f)), ());
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointD(14., -48.), m2::PointD(70., -240.), 25.), m2::PointD(21., -72.)),
());
}

View File

@@ -116,8 +116,8 @@ UNIT_TEST(FindSingleStrip)
{
// Minsk, Bobryiskaya str., 7
P const poly[] = {P(53.8926922, 27.5460021), P(53.8926539, 27.5461821), P(53.8926164, 27.5461591),
P(53.8925455, 27.5464921), P(53.8925817, 27.5465143), P(53.8925441, 27.5466909),
P(53.8923762, 27.5465881), P(53.8925229, 27.5458984)};
P(53.8925455, 27.5464921), P(53.8925817, 27.5465143), P(53.8925441, 27.5466909),
P(53.8923762, 27.5465881), P(53.8925229, 27.5458984)};
TestFindStrip(poly, ARRAY_SIZE(poly));
}
}
@@ -150,15 +150,13 @@ UNIT_TEST(PolygonArea_Smoke)
{
{
P arr[] = {P(-1, 0), P(0, 1), P(1, -1)};
TEST_ALMOST_EQUAL_ULPS(m2::GetTriangleArea(arr[0], arr[1], arr[2]),
GetPolygonArea(arr, arr + ARRAY_SIZE(arr)), ());
TEST_ALMOST_EQUAL_ULPS(m2::GetTriangleArea(arr[0], arr[1], arr[2]), GetPolygonArea(arr, arr + ARRAY_SIZE(arr)), ());
}
{
P arr[] = {P(-5, -7), P(-3.5, 10), P(7.2, 5), P(14, -6.4)};
TEST_ALMOST_EQUAL_ULPS(
m2::GetTriangleArea(arr[0], arr[1], arr[2]) + m2::GetTriangleArea(arr[2], arr[3], arr[0]),
GetPolygonArea(arr, arr + ARRAY_SIZE(arr)), ());
TEST_ALMOST_EQUAL_ULPS(m2::GetTriangleArea(arr[0], arr[1], arr[2]) + m2::GetTriangleArea(arr[2], arr[3], arr[0]),
GetPolygonArea(arr, arr + ARRAY_SIZE(arr)), ());
}
}

View File

@@ -12,8 +12,8 @@ namespace polyline_tests
{
double constexpr kEps = 1e-5;
void TestClosest(std::vector<m2::PointD> const & points, m2::PointD const & point,
double expectedSquaredDist, uint32_t expectedIndex)
void TestClosest(std::vector<m2::PointD> const & points, m2::PointD const & point, double expectedSquaredDist,
uint32_t expectedIndex)
{
auto const closestByPoints = m2::CalcMinSquaredDistance(points.begin(), points.end(), point);
TEST_ALMOST_EQUAL_ABS(closestByPoints.first, expectedSquaredDist, kEps, ());
@@ -44,8 +44,7 @@ UNIT_TEST(Rect_PolylineMinDistanceTest)
// 1 | |
// | |
// 0----1----2----3
std::vector<m2::PointD> const poly = {{0.0, 1.0}, {0.0, 0.0}, {1.0, 0.0},
{2.0, 0.0}, {3.0, 0.0}, {3.0, 1.0}};
std::vector<m2::PointD> const poly = {{0.0, 1.0}, {0.0, 0.0}, {1.0, 0.0}, {2.0, 0.0}, {3.0, 0.0}, {3.0, 1.0}};
TestClosest(poly, m2::PointD(0.0, 1.0), 0.0 /* expectedSquaredDist */, 0 /* expectedIndex */);
TestClosest(poly, m2::PointD(0.0, 0.0), 0.0 /* expectedSquaredDist */, 0 /* expectedIndex */);

View File

@@ -1,5 +1,5 @@
#include "testing/testing.hpp"
#include "geometry/rect2d.hpp"
#include "testing/testing.hpp"
UNIT_TEST(Rect_Intersect)
{
@@ -19,4 +19,3 @@ UNIT_TEST(Rect_Intersect)
TEST(r3.IsIntersect(r), ());
TEST(r.IsIntersect(r3), ());
}

View File

@@ -16,8 +16,8 @@ using R = m2::RegionI;
UNIT_TEST(RegionIntersect_Smoke)
{
{
P arr1[] = { P(-2, 1), P(2, 1), P(2, -1), P(-2, -1) };
P arr2[] = { P(-1, 2), P(1, 2), P(1, -2), P(-1, -2) };
P arr1[] = {P(-2, 1), P(2, 1), P(2, -1), P(-2, -1)};
P arr2[] = {P(-1, 2), P(1, 2), P(1, -2), P(-1, -2)};
R r1, r2;
r1.Assign(arr1, arr1 + ARRAY_SIZE(arr1));
@@ -31,8 +31,8 @@ UNIT_TEST(RegionIntersect_Smoke)
}
{
P arr1[] = { P(0, 0), P(1, 1), P(2, 0) };
P arr2[] = { P(0, 0), P(1, -1), P(2, 0) };
P arr1[] = {P(0, 0), P(1, 1), P(2, 0)};
P arr2[] = {P(0, 0), P(1, -1), P(2, 0)};
R r1, r2;
r1.Assign(arr1, arr1 + ARRAY_SIZE(arr1));
@@ -45,8 +45,8 @@ UNIT_TEST(RegionIntersect_Smoke)
}
{
P arr1[] = { P(-10, -10), P(10, -10), P(10, 10), P(-10, 10) };
P arr2[] = { P(-5, -5), P(5, -5), P(5, 5), P(-5, 5) };
P arr1[] = {P(-10, -10), P(10, -10), P(10, 10), P(-10, 10)};
P arr2[] = {P(-5, -5), P(5, -5), P(5, 5), P(-5, 5)};
R r1, r2;
r1.Assign(arr1, arr1 + ARRAY_SIZE(arr1));
@@ -64,8 +64,8 @@ UNIT_TEST(RegionIntersect_Smoke)
UNIT_TEST(RegionDifference_Smoke)
{
{
P arr1[] = { P(-1, 1), P(1, 1), P(1, -1), P(-1, -1) };
P arr2[] = { P(-2, 2), P(2, 2), P(2, -2), P(-2, -2) };
P arr1[] = {P(-1, 1), P(1, 1), P(1, -1), P(-1, -1)};
P arr2[] = {P(-2, 2), P(2, 2), P(2, -2), P(-2, -2)};
R r1, r2;
r1.Assign(arr1, arr1 + ARRAY_SIZE(arr1));
@@ -82,8 +82,8 @@ UNIT_TEST(RegionDifference_Smoke)
}
{
P arr1[] = { P(0, 1), P(2, 1), P(2, 0), P(0, 0) };
P arr2[] = { P(1, 2), P(2, 2), P(2, -1), P(1, -1) };
P arr1[] = {P(0, 1), P(2, 1), P(2, 0), P(0, 0)};
P arr2[] = {P(1, 2), P(2, 2), P(2, -1), P(1, -1)};
R r1, r2;
r1.Assign(arr1, arr1 + ARRAY_SIZE(arr1));
@@ -100,8 +100,8 @@ UNIT_TEST(RegionDifference_Smoke)
UNIT_TEST(AddRegion_Smoke)
{
{
P arr1[] = { {0, 0}, {0, 1}, {1, 1}, {1, 0} };
P arr2[] = { {2, 2}, {2, 3}, {3, 3}, {3, 2} };
P arr1[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
P arr2[] = {{2, 2}, {2, 3}, {3, 3}, {3, 2}};
R r1, r2;
r1.Assign(arr1, arr1 + ARRAY_SIZE(arr1));
@@ -120,8 +120,8 @@ UNIT_TEST(AddRegion_Smoke)
}
{
P arr1[] = { {0, 0}, {0, 3}, {3, 3}, {3, 0} };
P arr2[] = { {1, 1}, {1, 2}, {2, 2}, {2, 1} };
P arr1[] = {{0, 0}, {0, 3}, {3, 3}, {3, 0}};
P arr2[] = {{1, 1}, {1, 2}, {2, 2}, {2, 1}};
R r1, r2;
r1.Assign(arr1, arr1 + ARRAY_SIZE(arr1));
@@ -142,8 +142,8 @@ UNIT_TEST(AddRegion_Smoke)
UNIT_TEST(RegionIntersect_Floats)
{
P arr1[] = { {0, 1}, {2, 3}, {3, 2}, {1, 0} };
P arr2[] = { {0, 2}, {1, 3}, {3, 1}, {2, 0} };
P arr1[] = {{0, 1}, {2, 3}, {3, 2}, {1, 0}};
P arr2[] = {{0, 2}, {1, 3}, {3, 1}, {2, 0}};
R r1, r2;
r1.Assign(arr1, arr1 + ARRAY_SIZE(arr1));
@@ -158,8 +158,9 @@ UNIT_TEST(RegionIntersect_Floats)
UNIT_TEST(RegionArea_2Directions)
{
P arr[] = { {1, 1}, {1, 0}, {2, 0}, {2, 1}, {1, 1}, // CCW direction
{1, 1}, {1, 0}, {0, 0}, {0, 1}, {1, 1} // CW direction
P arr[] = {
{1, 1}, {1, 0}, {2, 0}, {2, 1}, {1, 1}, // CCW direction
{1, 1}, {1, 0}, {0, 0}, {0, 1}, {1, 1} // CW direction
};
R r;

View File

@@ -8,8 +8,8 @@
#include <iostream>
#include <random>
#include <vector>
#include <type_traits>
#include <vector>
namespace region_tests
{
@@ -88,13 +88,13 @@ void TestContains()
TestContainsRectangular(data);
}
{
P const data[] = {P(-2000000000, -2000000000), P(-1000000000, -2000000000),
P(-1000000000, -1000000000), P(-2000000000, -1000000000)};
P const data[] = {P(-2000000000, -2000000000), P(-1000000000, -2000000000), P(-1000000000, -1000000000),
P(-2000000000, -1000000000)};
TestContainsRectangular(data);
}
{
P const data[] = {P(1000000000, 1000000000), P(2000000000, 1000000000),
P(2000000000, 2000000000), P(1000000000, 2000000000)};
P const data[] = {P(1000000000, 1000000000), P(2000000000, 1000000000), P(2000000000, 2000000000),
P(1000000000, 2000000000)};
TestContainsRectangular(data);
}
@@ -111,10 +111,9 @@ void TestContains()
// complex polygon
{
P const data[] = {P(0, 0), P(2, 0), P(2, 2), P(3, 1), P(4, 2), P(5, 2), P(3, 3),
P(3, 2), P(2, 4), P(6, 3), P(7, 4), P(7, 2), P(8, 5), P(8, 7),
P(7, 7), P(8, 8), P(5, 9), P(6, 6), P(5, 7), P(4, 6), P(4, 8),
P(3, 7), P(2, 7), P(3, 6), P(4, 4), P(0, 7), P(2, 3), P(0, 2)};
P const data[] = {P(0, 0), P(2, 0), P(2, 2), P(3, 1), P(4, 2), P(5, 2), P(3, 3), P(3, 2), P(2, 4), P(6, 3),
P(7, 4), P(7, 2), P(8, 5), P(8, 7), P(7, 7), P(8, 8), P(5, 9), P(6, 6), P(5, 7), P(4, 6),
P(4, 8), P(3, 7), P(2, 7), P(3, 6), P(4, 4), P(0, 7), P(2, 3), P(0, 2)};
region.Assign(data, data + ARRAY_SIZE(data));
}
TEST_EQUAL(region.GetRect(), m2::Rect<typename P::value_type>(0, 0, 8, 9), ());
@@ -160,8 +159,7 @@ UNIT_TEST(Region)
{
// equality case
{
P const data[] = {P(1, 1), P(0, 4.995), P(1, 4.999996), P(1.000003, 5.000001),
P(0.5, 10), P(10, 10), P(10, 1)};
P const data[] = {P(1, 1), P(0, 4.995), P(1, 4.999996), P(1.000003, 5.000001), P(0.5, 10), P(10, 10), P(10, 1)};
region.Assign(data, data + ARRAY_SIZE(data));
}
TEST(!region.Contains(P(0.9999987, 0.9999938)), ());
@@ -202,7 +200,10 @@ UNIT_TEST(Region_Contains_int32)
}
}
UNIT_TEST(Region_Contains_uint32) { TestContains<m2::RegionU>(); }
UNIT_TEST(Region_Contains_uint32)
{
TestContains<m2::RegionU>();
}
UNIT_TEST(Region_Contains_double)
{
@@ -279,8 +280,7 @@ UNIT_TEST(Region_border_intersecion_Test)
TEST(region.FindIntersection(P(7.0, 7.0), P(7.0, 10.0), intersection), ());
TEST(intersection == P(7.0, 10.0), ());
TEST(!region.FindIntersection(P(5.0, 5.0), P(2.0, 2.0), intersection),
("This case has no intersection"));
TEST(!region.FindIntersection(P(5.0, 5.0), P(2.0, 2.0), intersection), ("This case has no intersection"));
}
UNIT_TEST(Region_Area)
@@ -319,7 +319,8 @@ UNIT_TEST(Region_GetRandomPoint)
size_t const kNumIterations = 1000;
bool const kNeedPlot = true;
auto testConvexRegion = [&](m2::Region<P> const & region) {
auto testConvexRegion = [&](m2::Region<P> const & region)
{
minstd_rand rng(0);
vector<P> points;
points.reserve(kNumIterations);
@@ -363,4 +364,4 @@ UNIT_TEST(Region_GetRandomPoint)
testConvexRegion(region);
}
}
} // namespace region_tests
} // namespace region_tests

View File

@@ -159,7 +159,7 @@ UNIT_TEST(Triangle_PointInsidePoint)
UNIT_TEST(PolygonSelfIntersections_IntersectSmoke)
{
{
P arr[] = { P(0, 1), P(2, -1), P(2, 1), P(0, -1) };
P arr[] = {P(0, 1), P(2, -1), P(2, 1), P(0, -1)};
CheckSelfIntersections(&arr[0], arr + ARRAY_SIZE(arr), true);
}
}
@@ -167,13 +167,13 @@ UNIT_TEST(PolygonSelfIntersections_IntersectSmoke)
UNIT_TEST(PolygonSelfIntersections_TangentSmoke)
{
{
P arr[] = { P(0, 1), P(1, 0), P(2, 1), P(2, -1), P(1, 0), P(0, -1) };
P arr[] = {P(0, 1), P(1, 0), P(2, 1), P(2, -1), P(1, 0), P(0, -1)};
CheckSelfIntersections(&arr[0], arr + ARRAY_SIZE(arr), false);
}
{
P arr[] = { P(0, 0), P(2, 0), P(2, 1), P(1, 0), P(0, 1) };
P arr[] = {P(0, 0), P(2, 0), P(2, 1), P(1, 0), P(0, 1)};
CheckSelfIntersections(&arr[0], arr + ARRAY_SIZE(arr), false);
}
}
} // namespace robust_test
} // namespace robust_test

View File

@@ -70,8 +70,11 @@ UNIT_TEST(ScreenBase_3dTransform)
p3d = m2::PointD(screen.PixelRectIn3d().SizeX() / 2.0, screen.PixelRectIn3d().SizeY() / 2.0);
pp = screen.P3dtoP(p3d);
TEST(pp.EqualDxDy(m2::PointD(screen.PixelRect().SizeX() / 2.0,
screen.PixelRect().SizeY() - screen.PixelRectIn3d().SizeY() / (2.0 * cos(rotationAngle))), kEps), ());
TEST(
pp.EqualDxDy(m2::PointD(screen.PixelRect().SizeX() / 2.0,
screen.PixelRect().SizeY() - screen.PixelRectIn3d().SizeY() / (2.0 * cos(rotationAngle))),
kEps),
());
p3d = m2::PointD(0, 0);
pp = screen.P3dtoP(p3d);
@@ -147,12 +150,10 @@ UNIT_TEST(ScreenBase_CalcTransform)
double dx = 1;
double dy = 2;
double s1, a1, dx1, dy1;
math::Matrix<double, 3, 3> m = ScreenBase::CalcTransform(
m2::PointD(0, 1), m2::PointD(1, 1),
m2::PointD( s * sin(a) + dx, s * cos(a) + dy),
m2::PointD(s * cos(a) + s * sin(a) + dx, -s * sin(a) + s * cos(a) + dy),
true /* allow rotate */,
true /* allow scale*/);
math::Matrix<double, 3, 3> m =
ScreenBase::CalcTransform(m2::PointD(0, 1), m2::PointD(1, 1), m2::PointD(s * sin(a) + dx, s * cos(a) + dy),
m2::PointD(s * cos(a) + s * sin(a) + dx, -s * sin(a) + s * cos(a) + dy),
true /* allow rotate */, true /* allow scale*/);
ScreenBase::ExtractGtoPParams(m, a1, s1, dx1, dy1);
@@ -194,26 +195,18 @@ UNIT_TEST(ScreenBase_CombineTransforms)
{
// GtoP matrix for scale only.
math::Matrix<double, 3, 3> m =
math::Shift(
math::Scale(math::Identity<double, 3>(),
1.0 / fixedScale, -1.0 / fixedScale),
sCopy.PixelRect().Center());
math::Matrix<double, 3, 3> m = math::Shift(
math::Scale(math::Identity<double, 3>(), 1.0 / fixedScale, -1.0 / fixedScale), sCopy.PixelRect().Center());
TEST(is_equal(sCopy.GtoP(g1), g1 * m), ());
TEST(is_equal(sCopy.GtoP(g2), g2 * m), ());
}
// GtoP matrix to make full final transformation.
math::Matrix<double, 3, 3> m =
math::Shift(
math::Scale(
math::Rotate(
math::Shift(math::Identity<double, 3>(),
-sCopy.PixelRect().Center()),
angle),
fixedScale / scale, fixedScale / scale),
org);
math::Matrix<double, 3, 3> m = math::Shift(
math::Scale(math::Rotate(math::Shift(math::Identity<double, 3>(), -sCopy.PixelRect().Center()), angle),
fixedScale / scale, fixedScale / scale),
org);
m2::PointD pp1 = sCopy.GtoP(g1) * m;
m2::PointD pp2 = sCopy.GtoP(g2) * m;
@@ -221,4 +214,4 @@ UNIT_TEST(ScreenBase_CombineTransforms)
TEST(is_equal(p1, pp1), (p1, pp1));
TEST(is_equal(p2, pp2), (p2, pp2));
}
} // namespace screen_test
} // namespace screen_test

View File

@@ -10,7 +10,7 @@ using namespace m2;
double const kEps = 1e-10;
void TestIntersectionResult(IntersectionResult const & result, IntersectionResult::Type expectedType,
PointD const & expectedPoint)
PointD const & expectedPoint)
{
TEST_EQUAL(result.m_type, expectedType, ());
TEST(AlmostEqualAbs(result.m_point, expectedPoint, kEps), (result.m_point, expectedPoint, kEps));
@@ -55,54 +55,45 @@ UNIT_TEST(SegmentIntersection_Intersect)
UNIT_TEST(SegmentIntersection_NoIntersectionPoint)
{
TEST_EQUAL(
Intersect(Segment2D({0.0, 0.0}, {1.0, 0.0}), Segment2D({2.0, 0.0}, {4.0, 0.0}), kEps).m_type,
IntersectionResult::Type::Zero, ());
TEST_EQUAL(Intersect(Segment2D({0.0, 0.0}, {1.0, 0.0}), Segment2D({2.0, 0.0}, {4.0, 0.0}), kEps).m_type,
IntersectionResult::Type::Zero, ());
TEST_EQUAL(
Intersect(Segment2D({0.0, 0.0}, {1.0, 1.0}), Segment2D({2.0, 0.0}, {4.0, 0.0}), kEps).m_type,
IntersectionResult::Type::Zero, ());
TEST_EQUAL(Intersect(Segment2D({0.0, 0.0}, {1.0, 1.0}), Segment2D({2.0, 0.0}, {4.0, 0.0}), kEps).m_type,
IntersectionResult::Type::Zero, ());
TEST_EQUAL(
Intersect(Segment2D({0.0, 0.0}, {1.0, 1.0}), Segment2D({4.0, 4.0}, {2.0, 2.0}), kEps).m_type,
IntersectionResult::Type::Zero, ());
TEST_EQUAL(Intersect(Segment2D({0.0, 0.0}, {1.0, 1.0}), Segment2D({4.0, 4.0}, {2.0, 2.0}), kEps).m_type,
IntersectionResult::Type::Zero, ());
TEST_EQUAL(
Intersect(Segment2D({0.0, 0.0}, {4.0, 4.0}), Segment2D({10.0, 0.0}, {6.0, 4.0}), kEps).m_type,
IntersectionResult::Type::Zero, ());
TEST_EQUAL(Intersect(Segment2D({0.0, 0.0}, {4.0, 4.0}), Segment2D({10.0, 0.0}, {6.0, 4.0}), kEps).m_type,
IntersectionResult::Type::Zero, ());
}
UNIT_TEST(SegmentIntersection_OneIntersectionPoint)
{
// Two intersected segments. The intersection point is in the middle of both of them.
{
auto const result =
Intersect(Segment2D({-1.0, -1.0}, {1.0, 1.0}), Segment2D({-1.0, 0.0}, {1.0, 0.0}), kEps);
auto const result = Intersect(Segment2D({-1.0, -1.0}, {1.0, 1.0}), Segment2D({-1.0, 0.0}, {1.0, 0.0}), kEps);
TestIntersectionResult(result, IntersectionResult::Type::One, {0.0, 0.0});
}
{
auto const result =
Intersect(Segment2D({0.0, 0.0}, {10.0, 10.0}), Segment2D({10.0, 0.0}, {0.0, 10.0}), kEps);
auto const result = Intersect(Segment2D({0.0, 0.0}, {10.0, 10.0}), Segment2D({10.0, 0.0}, {0.0, 10.0}), kEps);
TestIntersectionResult(result, IntersectionResult::Type::One, {5.0, 5.0});
}
// Two intersected segments. The intersection point is in an end of both of them.
{
auto const result =
Intersect(Segment2D({-1.0, -1.0}, {0.0, 0.0}), Segment2D({0.0, 0.0}, {11.0, 0.0}), kEps);
auto const result = Intersect(Segment2D({-1.0, -1.0}, {0.0, 0.0}), Segment2D({0.0, 0.0}, {11.0, 0.0}), kEps);
TestIntersectionResult(result, IntersectionResult::Type::One, {0.0, 0.0});
}
}
UNIT_TEST(SegmentIntersection_InfinityIntersectionPoints)
{
TEST_EQUAL(
Intersect(Segment2D({0.0, 0.0}, {2.0, 0.0}), Segment2D({1.0, 0.0}, {4.0, 0.0}), kEps).m_type,
IntersectionResult::Type::Infinity, ());
TEST_EQUAL(Intersect(Segment2D({0.0, 0.0}, {2.0, 0.0}), Segment2D({1.0, 0.0}, {4.0, 0.0}), kEps).m_type,
IntersectionResult::Type::Infinity, ());
TEST_EQUAL(
Intersect(Segment2D({0.0, 0.0}, {2.0, 4.0}), Segment2D({1.0, 2.0}, {2.0, 4.0}), kEps).m_type,
IntersectionResult::Type::Infinity, ());
TEST_EQUAL(Intersect(Segment2D({0.0, 0.0}, {2.0, 4.0}), Segment2D({1.0, 2.0}, {2.0, 4.0}), kEps).m_type,
IntersectionResult::Type::Infinity, ());
}
} // namespace segment2d_tests

View File

@@ -20,8 +20,7 @@ using namespace std;
using P = m2::PointD;
using DistanceFn = m2::SquaredDistanceFromSegmentToPoint;
using PointOutput = base::BackInsertFunctor<vector<m2::PointD>>;
using SimplifyFn = void (*)(m2::PointD const *, m2::PointD const *, double, DistanceFn,
PointOutput);
using SimplifyFn = void (*)(m2::PointD const *, m2::PointD const *, double, DistanceFn, PointOutput);
struct LargePolylineTestData
{
@@ -67,14 +66,12 @@ void TestSimplificationOfPoly(m2::PointD const * points, size_t count, SimplifyF
}
}
void SimplifyNearOptimal10(m2::PointD const * f, m2::PointD const * l, double e, DistanceFn distFn,
PointOutput out)
void SimplifyNearOptimal10(m2::PointD const * f, m2::PointD const * l, double e, DistanceFn distFn, PointOutput out)
{
SimplifyNearOptimal(10, f, l, e, distFn, out);
}
void SimplifyNearOptimal20(m2::PointD const * f, m2::PointD const * l, double e, DistanceFn distFn,
PointOutput out)
void SimplifyNearOptimal20(m2::PointD const * f, m2::PointD const * l, double e, DistanceFn distFn, PointOutput out)
{
SimplifyNearOptimal(20, f, l, e, distFn, out);
}
@@ -106,30 +103,39 @@ UNIT_TEST(Simplification_TestDataIsCorrect)
TEST_EQUAL(LargePolylineTestData::m_Size, 5539, ());
}
UNIT_TEST(Simplification_DP_Smoke) { TestSimplificationSmoke(&SimplifyDP<DistanceFn>); }
UNIT_TEST(Simplification_DP_Smoke)
{
TestSimplificationSmoke(&SimplifyDP<DistanceFn>);
}
UNIT_TEST(Simplification_DP_Line) { TestSimplificationOfLine(&SimplifyDP<DistanceFn>); }
UNIT_TEST(Simplification_DP_Line)
{
TestSimplificationOfLine(&SimplifyDP<DistanceFn>);
}
UNIT_TEST(Simplification_DP_Polyline)
{
TestSimplificationOfPoly(LargePolylineTestData::m_Data, LargePolylineTestData::m_Size,
&SimplifyDP<DistanceFn>);
TestSimplificationOfPoly(LargePolylineTestData::m_Data, LargePolylineTestData::m_Size, &SimplifyDP<DistanceFn>);
}
UNIT_TEST(Simplification_Opt_Smoke) { TestSimplificationSmoke(&SimplifyNearOptimal10); }
UNIT_TEST(Simplification_Opt_Smoke)
{
TestSimplificationSmoke(&SimplifyNearOptimal10);
}
UNIT_TEST(Simplification_Opt_Line) { TestSimplificationOfLine(&SimplifyNearOptimal10); }
UNIT_TEST(Simplification_Opt_Line)
{
TestSimplificationOfLine(&SimplifyNearOptimal10);
}
UNIT_TEST(Simplification_Opt10_Polyline)
{
TestSimplificationOfPoly(LargePolylineTestData::m_Data, LargePolylineTestData::m_Size,
&SimplifyNearOptimal10);
TestSimplificationOfPoly(LargePolylineTestData::m_Data, LargePolylineTestData::m_Size, &SimplifyNearOptimal10);
}
UNIT_TEST(Simplification_Opt20_Polyline)
{
TestSimplificationOfPoly(LargePolylineTestData::m_Data, LargePolylineTestData::m_Size,
&SimplifyNearOptimal20);
TestSimplificationOfPoly(LargePolylineTestData::m_Data, LargePolylineTestData::m_Size, &SimplifyNearOptimal20);
}
UNIT_TEST(Simpfication_DP_DegenerateTrg)
@@ -137,9 +143,8 @@ UNIT_TEST(Simpfication_DP_DegenerateTrg)
P arr1[] = {P(0, 0), P(100, 100), P(100, 500), P(0, 600)};
CheckDPStrict(arr1, ARRAY_SIZE(arr1), 1.0, 4);
P arr2[] = {P(0, 0), P(100, 100), P(100.1, 150), P(100.2, 200),
P(100.3, 250), P(100.4, 300), P(100.3, 350), P(100.2, 400),
P(100.1, 450), P(100, 500), P(0, 600)};
P arr2[] = {P(0, 0), P(100, 100), P(100.1, 150), P(100.2, 200), P(100.3, 250), P(100.4, 300),
P(100.3, 350), P(100.2, 400), P(100.1, 450), P(100, 500), P(0, 600)};
CheckDPStrict(arr2, ARRAY_SIZE(arr2), 1.0, 4);
}
} // namespace simplification_test

View File

@@ -9,8 +9,8 @@ namespace spline_test
{
using namespace std;
using m2::Spline;
using m2::PointD;
using m2::Spline;
namespace
{
@@ -36,12 +36,12 @@ void TestPointDDir(PointD const & dst, PointD const & src)
}
else
{
TestEqual(dst.x/len1, src.x/len2);
TestEqual(dst.y/len1, src.y/len2);
TestEqual(dst.x / len1, src.x / len2);
TestEqual(dst.y / len1, src.y / len2);
}
}
} // namespace
} // namespace
UNIT_TEST(Spline_SmoothedDirections)
{

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
#include "testing/testing.hpp"
#include "geometry/transformations.hpp"
#include "base/matrix.hpp"
#include "geometry/point2d.hpp"
#include "geometry/transformations.hpp"
#include "testing/testing.hpp"
UNIT_TEST(Transformations_Shift)
{
@@ -28,7 +28,8 @@ UNIT_TEST(Transformations_Rotate)
UNIT_TEST(Transformations_ShiftScaleRotate)
{
math::Matrix<double, 3, 3> m = math::Rotate(math::Scale(math::Shift(math::Identity<double, 3>(), 100, 100), 2, 3), -math::pi / 2);
math::Matrix<double, 3, 3> m =
math::Rotate(math::Scale(math::Shift(math::Identity<double, 3>(), 100, 100), 2, 3), -math::pi / 2);
m2::PointD pt = m2::PointD(20, 10) * m;
TEST(pt.EqualDxDy(m2::PointD(330, -240), 1.0E-10), ());

View File

@@ -64,8 +64,7 @@ UNIT_TEST(Tree4D_ForAnyInRect)
{
Tree theTree;
R arr[] = {R(0, 0, 1, 1), R(0, 0, 5, 5), R(1, 1, 2, 2),
R(1, 1, 6.5, 6.5), R(2, 2, 3, 3), R(2, 2, 7, 7)};
R arr[] = {R(0, 0, 1, 1), R(0, 0, 5, 5), R(1, 1, 2, 2), R(1, 1, 6.5, 6.5), R(2, 2, 3, 3), R(2, 2, 7, 7)};
for (auto const & r : arr)
theTree.Add(r);
@@ -118,7 +117,7 @@ void CheckInRect(R const * arr, size_t count, R const & searchR, size_t expected
TEST_EQUAL(test.size(), expected, ());
}
}
} // namespace
UNIT_TEST(Tree4D_ForEachInRect)
{
@@ -141,10 +140,7 @@ struct TestObj : public m2::RectD
{
int m_id;
TestObj(double minX, double minY, double maxX, double maxY, int id)
: m2::RectD(minX, minY, maxX, maxY), m_id(id)
{
}
TestObj(double minX, double minY, double maxX, double maxY, int id) : m2::RectD(minX, minY, maxX, maxY), m_id(id) {}
bool operator==(TestObj const & r) const { return m_id == r.m_id; }
};

View File

@@ -8,10 +8,8 @@ template <class T, size_t N>
bool EqualArrays(T (&a1)[N], T (&a2)[N])
{
for (size_t i = 0; i < N; ++i)
{
if (!AlmostEqualULPs(a1[i], a2[i]))
return false;
}
return true;
}
} // namespace
@@ -20,14 +18,14 @@ UNIT_TEST(AvgVector_Smoke)
{
math::AvgVector<double, 3> holder(3);
double ethalon1[] = { 5, 5, 5 };
double ethalon2[] = { 5.5, 5.5, 5.5 };
double ethalon3[] = { 6, 6, 6 };
double ethalon1[] = {5, 5, 5};
double ethalon2[] = {5.5, 5.5, 5.5};
double ethalon3[] = {6, 6, 6};
double arr1[] = { 5, 5, 5 };
double arr2[] = { 6, 6, 6 };
double arr3[] = { 5, 5, 5 };
double arr4[] = { 6, 6, 6 };
double arr1[] = {5, 5, 5};
double arr2[] = {6, 6, 6};
double arr3[] = {5, 5, 5};
double arr4[] = {6, 6, 6};
holder.Next(arr1);
TEST(EqualArrays(arr1, ethalon1), ());