Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/core/virtual_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,17 @@ VirtualCoordVector::size_type PathCoordVector::update(VirtualCoordVector::size_t
{
Q_ASSERT(virtual_coords.size() == flags.size());

clear();

if (flags[part_start].isHolePoint())
{
auto pos = virtual_coords[0];
qWarning("PathCoordVector at %g %g (mm) has an invalid hole at index %d.",
pos.x(), -pos.y(), part_start);
return part_start;
}

clear();
if (empty() || (part_start > 0 && flags[part_start-1].isHolePoint()))
{
emplace_back(virtual_coords[part_start], part_start, 0.0, 0.0);
}
emplace_back(virtual_coords[part_start], part_start, 0.0, 0.0);

for (auto index = part_start + 1; index <= part_end; ++index)
{
Expand Down
60 changes: 59 additions & 1 deletion test/path_object_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@

#include <QtTest>

#include "global.h"
#include "core/map.h"
#include "core/objects/object.h"
#include "core/symbols/line_symbol.h"

using namespace OpenOrienteering;

Q_DECLARE_METATYPE(MapCoord*)


namespace QTest
{
Expand Down Expand Up @@ -1150,6 +1151,63 @@ void PathObjectTest::atypicalPathTest()



void PathObjectTest::recalculatePartsTest_data()
{
static MapCoord coords[] = {
{ 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 }, { 0.0, 0.0, MapCoord::HolePoint },
{ 2.0, 2.0 }, { 2.0, 3.0 }, { 3.0, 3.0, MapCoord::HolePoint },
{ 4.0, 4.0, MapCoord::HolePoint },
{ 6.0, 6.0 }, { 6.0, 5.0 },
};
QTest::addColumn<MapCoord*>("first");
QTest::addColumn<MapCoord*>("last"); // STL sense
QTest::addColumn<int>("expected_size");

QTest::newRow("0.") << coords+0 << coords+0 << 0;
QTest::newRow("1.") << coords+0 << coords+1 << 1; // maybe not desired
QTest::newRow("2.") << coords+0 << coords+2 << 1; // maybe not desired for areas
QTest::newRow("3.") << coords+0 << coords+3 << 1;
QTest::newRow("4.") << coords+0 << coords+4 << 1;
QTest::newRow("5.") << coords+0 << coords+5 << 1;
QTest::newRow("5;1.") << coords+0 << coords+6 << 2; // maybe not desired
QTest::newRow("5;2.") << coords+0 << coords+7 << 2; // maybe not desired for areas
QTest::newRow("5;3.") << coords+0 << coords+8 << 2;
QTest::newRow("5;3;1.") << coords+0 << coords+9 << 3; // maybe not desired
QTest::newRow("5;3;1;1.") << coords+0 << coords+10 << 4; // maybe not desired
}

void PathObjectTest::recalculatePartsTest()
{
QFETCH(MapCoord*, first);
QFETCH(MapCoord*, last);
QFETCH(int, expected_size);

// The constructor calls PathObject::recalculateParts().
PathObject path { nullptr, MapCoordVector(first, last), nullptr };
{
auto& initial_parts = path.parts();
QCOMPARE(initial_parts.size(), expected_size);

for (auto& initial_part : initial_parts)
{
QVERIFY(initial_part.first_index <= initial_part.last_index);
}
}

path.updatePathCoords();
{
auto& updated_parts = path.parts();
QCOMPARE(updated_parts.size(), expected_size);

for (auto& updated_part : updated_parts)
{
QVERIFY(updated_part.first_index <= updated_part.last_index);
}
}
}



/*
* We don't need a real GUI window.
*/
Expand Down
3 changes: 3 additions & 0 deletions test/path_object_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ private slots:
/** Tests PathCoord and SplitPathCoord for a non-trivial zero-length path. */
void atypicalPathTest();

/** Tests recalculation of path parts from input coords. */
void recalculatePartsTest();
void recalculatePartsTest_data();
};

#endif