@Test public void containsWorks() { assertFalse(polygonView.contains(new Vector(-100, 100))); assertFalse(polygonView.contains(new Vector(101, 101))); assertTrue(polygonView.contains(new Vector(5, 5))); assertFalse(polygonView.contains(new Vector(50, 100))); }
@Override protected boolean contains(Vector loc) { List<Segment> segments = getSegments(); Rectangle bounds = calculateBounds(); Segment outSegment = new Segment(loc, new Vector(bounds.origin.x + bounds.dimension.x * 2, 0)); int intersections = 0; for (Segment s : segments) { if (outSegment.intersection(s) != null) { intersections++; } } return intersections % 2 == 1; }
PolygonView extends MultiPointView { @Override protected boolean contains(Vector loc) { List<Segment> segments = getSegments(); Rectangle bounds = calculateBounds(); Segment outSegment = new Segment(loc, new Vector(bounds.origin.x + bounds.dimension.x * 2, 0)); int intersections = 0; for (Segment s : segments) { if (outSegment.intersection(s) != null) { intersections++; } } return intersections % 2 == 1; } }
PolygonView extends MultiPointView { @Override protected boolean contains(Vector loc) { List<Segment> segments = getSegments(); Rectangle bounds = calculateBounds(); Segment outSegment = new Segment(loc, new Vector(bounds.origin.x + bounds.dimension.x * 2, 0)); int intersections = 0; for (Segment s : segments) { if (outSegment.intersection(s) != null) { intersections++; } } return intersections % 2 == 1; }  }
PolygonView extends MultiPointView { @Override protected boolean contains(Vector loc) { List<Segment> segments = getSegments(); Rectangle bounds = calculateBounds(); Segment outSegment = new Segment(loc, new Vector(bounds.origin.x + bounds.dimension.x * 2, 0)); int intersections = 0; for (Segment s : segments) { if (outSegment.intersection(s) != null) { intersections++; } } return intersections % 2 == 1; }   }
PolygonView extends MultiPointView { @Override protected boolean contains(Vector loc) { List<Segment> segments = getSegments(); Rectangle bounds = calculateBounds(); Segment outSegment = new Segment(loc, new Vector(bounds.origin.x + bounds.dimension.x * 2, 0)); int intersections = 0; for (Segment s : segments) { if (outSegment.intersection(s) != null) { intersections++; } } return intersections % 2 == 1; }    }