public class LineCrossDetector
extends java.lang.Object
The implementation given here works. You do not need to change it.
This file will be further altered in Checkpoint 3.
Constructor and Description |
---|
LineCrossDetector() |
Modifier and Type | Method and Description |
---|---|
static boolean |
linesCross(double firstStartLat,
double firstStartLng,
double firstEndLat,
double firstEndLng,
double secondStartLat,
double secondStartLng,
double secondEndLat,
double secondEndLng)
Determines whether two lines cross.
|
public static boolean linesCross(double firstStartLat, double firstStartLng, double firstEndLat, double firstEndLng, double secondStartLat, double secondStartLng, double secondEndLat, double secondEndLng)
Crossing is not always the same as intersecting. Lines that share a tip intersect but do not cross for purposes of this function. However, a line that has an endpoint on the middle of another line must be considered to cross that line (to prevent circumventing the snake rule).
For simplicity, longitude and latitude are treated as X and Y, respectively, on a 2D coordinate plane. This ignores the roundness of the earth, but it's undetectable at reasonable scales of the game.
All parameters are assumed to be valid: both lines have positive length.
firstStartLat
- the latitude of the start of one linefirstStartLng
- the longitude of the start of that linefirstEndLat
- the latitude of the end of that linefirstEndLng
- the longitude of the end of that linesecondStartLat
- the latitude of the start of another linesecondStartLng
- the longitude of the start of that other linesecondEndLat
- the latitude of the end of that other linesecondEndLng
- the longitude of the end of that other line