package algs.boundary; /** * Author: areful * Date: 2018/8/9 */ public class Boundary { private final BoundaryPoint[] points; Boundary(BoundaryPoint[] points) { this.points = points; } boolean contains(BoundaryPoint test) { boolean result = false; int i = 0; for (int j = this.points.length - 1; i < this.points.length; j = i++) { if (this.points[i].y > test.y != this.points[j].y > test.y && test.x < (this.points[j].x - this.points[i].x) * (test.y - this.points[i].y) / (this.points[j].y - this.points[i].y) + this.points[i].x) { result = !result; } } return result; } }
package algs.boundary; /** * Author: areful * Date: 2018/8/9 */ public class BoundaryPoint { public final double x; public final double y; public BoundaryPoint(double x, double y) { this.x = x; this.y = y; } }