-
Notifications
You must be signed in to change notification settings - Fork 4
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
Feature point in polygon #57
Conversation
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.
Looks good! I have some comments in the good which could be good to look at.
Did you use any particular reference when you made this implementation? Is it possible to add this to the comments in the code if this is the case?
server/src/util.c
Outdated
} | ||
|
||
/*! | ||
* \brief rayFromPointIntersectsLine checks whether ray in X axis direction from point intersects |
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.
Do you mean a ray that starts in an (x,y) coordinate and travels in positive X-direction, parallell to the x-axis?
|
||
// Compare the slopes of the lines AB and AP - if the slope of AB is larger than that of AP | ||
// then a ray in X axis direction will not intersect AB | ||
if (linePointAX != linePointBX) |
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.
Might be a bit nitpicky but if the line is vertical, but wouldn't the previous two if-statements have returned a value already? To check this, assume that linePointAX = linePointBX
, then it follows that minVal = maxVal
which both of the two previous if-statements cover. pointX
will always be less than, equal or bigger than minVal
.
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 agree, but I would rather have divide-by-zero be explicitly handled so that the code is crystal clear to someone reading it. The machine code will be the same as if I had removed it since the compiler optimises away this check.
server/src/util.c
Outdated
} | ||
|
||
// If the first and last points are different, the polygon segment between them must also be included | ||
if (verticesX[0] != verticesX[nPtsInPolygon-1] || verticesY[0] != verticesY[nPtsInPolygon-1]) |
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.
It is in general hard to compare doubles, especially if you want to check that they are equal to each other. Usually you would check that the difference is small enough to count as zero. This could look something like
abs(x-y) < epsilon
where epsilon is some really small number.
Addressed comments
Implemented ray casting algorithm for checking if a point is in a polygon