-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PointLocation.isOnSegment function #1083
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// | ||
// Test Suite for geos::algorithm::PointLocation | ||
// Ported from JTS junit/algorithm/PointLocationTest.java | ||
|
||
#include <tut/tut.hpp> | ||
#include <utility.h> | ||
|
||
// geos | ||
#include <geos/geom/Coordinate.h> | ||
#include <geos/algorithm/PointLocation.h> | ||
|
||
// std | ||
#include <sstream> | ||
#include <string> | ||
#include <memory> | ||
|
||
using geos::algorithm::PointLocation; | ||
using geos::geom::CoordinateXY; | ||
|
||
namespace tut { | ||
// | ||
// Test Group | ||
// | ||
|
||
// dummy data, not used | ||
struct test_PointLocation_data { | ||
|
||
geos::io::WKTReader r_; | ||
|
||
void | ||
checkOnLine(double x, double y, const std::string& wktLine, bool isExpected) | ||
{ | ||
CoordinateXY p(x, y); | ||
std::unique_ptr<CoordinateSequence> line = readPts(wktLine); | ||
bool isOnLine = PointLocation::isOnLine(p, line.get()); | ||
ensure(isOnLine == isExpected); | ||
} | ||
|
||
void | ||
checkOnSegment(double x, double y, const std::string& wktLine, bool isExpected) | ||
{ | ||
CoordinateXY p(x, y); | ||
std::unique_ptr<CoordinateSequence> line = readPts(wktLine); | ||
|
||
bool isOnSeg = PointLocation::isOnSegment(p, line->getAt(0), line->getAt(1)); | ||
ensure(isOnSeg == isExpected); | ||
} | ||
|
||
std::unique_ptr<CoordinateSequence> | ||
readPts(const std::string& wkt) | ||
{ | ||
std::unique_ptr<Geometry> geom = r_.read(wkt); | ||
const LineString* line = dynamic_cast<LineString*>(geom.get()); | ||
if (line) | ||
return line->getCoordinatesRO()->clone(); | ||
else | ||
return nullptr; | ||
} | ||
|
||
}; | ||
|
||
|
||
typedef test_group<test_PointLocation_data> group; | ||
typedef group::object object; | ||
|
||
group test_PointLocation_data("geos::algorithm::PointLocation"); | ||
|
||
|
||
// | ||
// Test Cases | ||
// | ||
|
||
// testOnLineOnVertex | ||
template<> | ||
template<> | ||
void object::test<1> () | ||
{ | ||
checkOnLine(20, 20, "LINESTRING (0 00, 20 20, 30 30)", true); | ||
} | ||
|
||
// testOnLineInSegment | ||
template<> | ||
template<> | ||
void object::test<2> () | ||
{ | ||
checkOnLine(10, 10, "LINESTRING (0 0, 20 20, 0 40)", true); | ||
checkOnLine(10, 30, "LINESTRING (0 0, 20 20, 0 40)", true); | ||
} | ||
|
||
// testNotOnLine | ||
template<> | ||
template<> | ||
void object::test<3> () | ||
{ | ||
checkOnLine(0, 100, "LINESTRING (10 10, 20 10, 30 10)", false); | ||
} | ||
|
||
// testOnSegment | ||
template<> | ||
template<> | ||
void object::test<4> () | ||
{ | ||
checkOnSegment(5, 5, "LINESTRING(0 0, 9 9)", true); | ||
checkOnSegment(0, 0, "LINESTRING(0 0, 9 9)", true); | ||
checkOnSegment(9, 9, "LINESTRING(0 0, 9 9)", true); | ||
} | ||
|
||
// testNotOnSegment | ||
template<> | ||
template<> | ||
void object::test<5> () | ||
{ | ||
checkOnSegment(5, 6, "LINESTRING(0 0, 9 9)", false); | ||
checkOnSegment(10, 10, "LINESTRING(0 0, 9 9)", false); | ||
checkOnSegment(9, 9.00001, "LINESTRING(0 0, 9 9)", false); | ||
} | ||
|
||
// testOnZeroLengthSegment | ||
template<> | ||
template<> | ||
void object::test<6> () | ||
{ | ||
checkOnSegment(1, 1, "LINESTRING(1 1, 1 1)", true); | ||
checkOnSegment(1, 2, "LINESTRING(1 1, 1 1)", false); | ||
} | ||
|
||
|
||
} // namespace tut | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change this to a reference so you dispense with the
*
further down,There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that but was getting compile errors. Does it need to be a pointer because it gets revalued at the end of the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is to simply define references for both points each time through the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, const references hate being redefined. 🤷 Nm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to d4b654a