Search in sources :

Example 46 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class ElementGeometryTest method testFindCenterOfPolylineWithZeroLength.

public void testFindCenterOfPolylineWithZeroLength() {
    List<List<LatLon>> polylines = new ArrayList<>();
    List<LatLon> polyline = new ArrayList<>();
    polyline.add(new OsmLatLon(20, 20));
    polyline.add(new OsmLatLon(20, 20));
    polylines.add(polyline);
    ElementGeometry geom = new ElementGeometry(polylines, null);
    assertEquals(null, geom.center);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 47 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class ElementGeometryTest method createSquareAroundOrigin.

private static List<LatLon> createSquareAroundOrigin(double offsetLat, double offsetLon) {
    List<LatLon> square = new ArrayList<>();
    square.add(new OsmLatLon(-offsetLat, -offsetLon));
    square.add(new OsmLatLon(+offsetLat, -offsetLon));
    square.add(new OsmLatLon(+offsetLat, +offsetLon));
    square.add(new OsmLatLon(-offsetLat, +offsetLon));
    square.add(new OsmLatLon(-offsetLat, -offsetLon));
    return square;
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) ArrayList(java.util.ArrayList) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 48 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class ElementCreatorTestGeometry method testCreateForSimpleAreaWay.

public void testCreateForSimpleAreaWay() {
    ElementGeometry geom = createCreator().create(W2);
    assertNotNull(geom.polygons);
    assertEquals(1, geom.polygons.size());
    List<LatLon> polygon = geom.polygons.get(0);
    for (int i = 0; i < W2.getNodeIds().size(); ++i) {
        LatLon shouldBe = nodes.get(W2.getNodeIds().get(i).intValue()).getPosition();
        assertEquals(shouldBe, polygon.get(i));
    }
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry)

Example 49 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class OsmQuestDownloadTest method testDeleteObsoleteQuests.

public void testDeleteObsoleteQuests() {
    LatLon pos = new OsmLatLon(3.0, 4.0);
    ElementWithGeometry node4 = new ElementWithGeometry();
    node4.element = new OsmNode(4, 0, pos, null);
    node4.geometry = new ElementGeometry(pos);
    // questType mock will only "find" the Node #4
    OsmElementQuestType questType = new ListBackedQuestType(Collections.singletonList(node4));
    // in the quest database mock, there are quests for node 4 and node 5
    List<OsmQuest> quests = new ArrayList<>();
    quests.add(new OsmQuest(12L, questType, Element.Type.NODE, 4, QuestStatus.NEW, null, null, new Date(), new ElementGeometry(pos)));
    quests.add(new OsmQuest(13L, questType, Element.Type.NODE, 5, QuestStatus.NEW, null, null, new Date(), new ElementGeometry(pos)));
    when(osmQuestDao.getAll(any(BoundingBox.class), any(QuestStatus.class), anyString(), any(Element.Type.class), anyLong())).thenReturn(quests);
    doAnswer(invocation -> {
        Collection<Long> deletedQuests = (Collection<Long>) (invocation.getArguments()[0]);
        assertEquals(1, deletedQuests.size());
        assertEquals(13L, (long) deletedQuests.iterator().next());
        return 1;
    }).when(osmQuestDao).deleteAll(any(Collection.class));
    OsmQuestDownload dl = new OsmQuestDownload(geometryDb, elementDb, osmQuestDao, countryBoundariesFuture);
    VisibleQuestListener listener = mock(VisibleQuestListener.class);
    dl.setQuestListener(listener);
    // -> we expect that quest with node #5 is removed
    dl.download(questType, new BoundingBox(0, 0, 1, 1), null);
    verify(osmQuestDao).deleteAll(any(Collection.class));
    verify(listener).onQuestsRemoved(any(Collection.class), any(QuestGroup.class));
}
Also used : OsmNode(de.westnordost.osmapi.map.data.OsmNode) OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) ArrayList(java.util.ArrayList) QuestGroup(de.westnordost.streetcomplete.data.QuestGroup) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) QuestStatus(de.westnordost.streetcomplete.data.QuestStatus) Date(java.util.Date) VisibleQuestListener(de.westnordost.streetcomplete.data.VisibleQuestListener) LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) Matchers.anyLong(org.mockito.Matchers.anyLong) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) Collection(java.util.Collection) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 50 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class ElementGeometry method isRingDefinedClockwise.

public static boolean isRingDefinedClockwise(List<LatLon> ring) {
    double sum = 0;
    int len = ring.size();
    for (int i = 0, j = len - 1; i < len; j = i, ++i) {
        LatLon pos1 = ring.get(j);
        LatLon pos2 = ring.get(i);
        sum += pos1.getLongitude() * pos2.getLatitude() - pos2.getLongitude() * pos1.getLatitude();
    }
    return sum > 0;
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon)

Aggregations

LatLon (de.westnordost.osmapi.map.data.LatLon)63 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)45 ArrayList (java.util.ArrayList)29 BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)13 List (java.util.List)12 ElementGeometry (de.westnordost.streetcomplete.data.osm.ElementGeometry)8 OsmNode (de.westnordost.osmapi.map.data.OsmNode)5 HashMap (java.util.HashMap)5 Point (android.graphics.Point)3 PointF (android.graphics.PointF)3 Node (de.westnordost.osmapi.map.data.Node)3 OsmElementQuestType (de.westnordost.streetcomplete.data.osm.OsmElementQuestType)3 LngLat (com.mapzen.tangram.LngLat)2 Point (com.vividsolutions.jts.geom.Point)2 Element (de.westnordost.osmapi.map.data.Element)2 QuestGroup (de.westnordost.streetcomplete.data.QuestGroup)2 VisibleQuestListener (de.westnordost.streetcomplete.data.VisibleQuestListener)2 OsmNoteQuestType (de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuestType)2 Collection (java.util.Collection)2 Map (java.util.Map)2