@Override public Location center() { return new Segment(this.lowerLeft, this.upperRight).middle(); }
/** * Tests if this {@link Polygon} wraps (geometrically contains) a {@link Segment} * * @param segment * The {@link Segment} to test * @return True if this {@link Polygon} wraps (geometrically contains) the provided * {@link Segment} */ public boolean fullyGeometricallyEncloses(final Segment segment) { final Set<Location> intersections = this.intersections(segment); for (final Location intersection : intersections) { if (!intersection.equals(segment.start()) && !intersection.equals(segment.end())) { // This is a non-end intersection return false; } } return this.fullyGeometricallyEncloses(segment.middle()); }
@Test public void testPolygonWith45DegreeZeroAreaPartContains() { // Shape is a triangle, with a zero area line protruding from one of the corners on an // incline final Polygon polygon = Polygon.wkt("POLYGON ((-0.0065127 0.0214697, -0.0092975 0.0054797," + " -0.0233112 -0.0085339, 0.0027398 0.0175171, -0.0065127 0.0214697))"); final Location middleZeroAreaPart = polygon.segmentForIndex(1).middle(); final Location endpointZeroAreaPart = polygon.segmentForIndex(1).end(); final Location middleThirdSegment = polygon.segmentForIndex(2).middle(); // Locations on the zero area part are still on the boundary, and therefore contained Assert.assertTrue(polygon.fullyGeometricallyEncloses(middleZeroAreaPart)); // see awt definition of contains Assert.assertFalse(polygon.fullyGeometricallyEncloses(endpointZeroAreaPart)); Assert.assertTrue(polygon.fullyGeometricallyEncloses(middleThirdSegment)); }
this.store.addNode(new AtlasPrimitiveLocationItem(8, SHAPEPOINT, Maps.stringMap())); this.store.addNode(new AtlasPrimitiveLocationItem(9, new Segment(Location.TEST_6, Location.TEST_7).middle(), Maps.stringMap("tag_key", "tag_value"))); this.store.addNode(new AtlasPrimitiveLocationItem(10, DE_ANZA_AT_280,