Search in sources :

Example 6 with BoundingBox

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

the class OsmQuestDownloadTest method testIgnoreBlacklistedPositionsAndInvalidGeometry.

public void testIgnoreBlacklistedPositionsAndInvalidGeometry() {
    LatLon blacklistPos = new OsmLatLon(3.0, 4.0);
    ElementWithGeometry blacklistElement = new ElementWithGeometry();
    blacklistElement.element = new OsmNode(0, 0, blacklistPos, null);
    blacklistElement.geometry = new ElementGeometry(blacklistPos);
    ElementWithGeometry invalidGeometryElement = new ElementWithGeometry();
    invalidGeometryElement.element = new OsmNode(0, 0, new OsmLatLon(1.0, 1.0), null);
    invalidGeometryElement.geometry = null;
    OsmElementQuestType questType = new ListBackedQuestType(Arrays.asList(blacklistElement, invalidGeometryElement));
    setUpOsmQuestDaoMockWithNoPreviousElements();
    OsmQuestDownload dl = new OsmQuestDownload(geometryDb, elementDb, osmQuestDao, countryBoundariesFuture);
    VisibleQuestListener listener = mock(VisibleQuestListener.class);
    dl.setQuestListener(listener);
    dl.download(questType, new BoundingBox(0, 0, 1, 1), Collections.singleton(blacklistPos));
    verify(listener, times(0)).onQuestsCreated(any(Collection.class), any(QuestGroup.class));
}
Also used : VisibleQuestListener(de.westnordost.streetcomplete.data.VisibleQuestListener) LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) OsmNode(de.westnordost.osmapi.map.data.OsmNode) OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) Collection(java.util.Collection) QuestGroup(de.westnordost.streetcomplete.data.QuestGroup) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 7 with BoundingBox

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

the class FiltersParserTest method testBoundingBoxWithMultipleElementTypes.

public void testBoundingBoxWithMultipleElementTypes() {
    BoundingBox bbox = new BoundingBox(0, 0, 5, 10);
    check("nodes, ways, relations", "[bbox:0.0,0.0,5.0,10.0];(node;way;rel;);out meta geom;", bbox);
    check("nodes, ways, relations with highway", "[bbox:0.0,0.0,5.0,10.0];(" + "node[\"highway\"];" + "way[\"highway\"];" + "rel[\"highway\"];" + ");" + "out meta geom;", bbox);
    check("nodes, ways, relations with highway or railway", "[bbox:0.0,0.0,5.0,10.0];(" + "node[\"highway\"];" + "node[\"railway\"];" + "way[\"highway\"];" + "way[\"railway\"];" + "rel[\"highway\"];" + "rel[\"railway\"];" + ");" + "out meta geom;", bbox);
}
Also used : BoundingBox(de.westnordost.osmapi.map.data.BoundingBox)

Example 8 with BoundingBox

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

the class OsmNotesDownloadTest method testDeleteObsoleteQuests.

public void testDeleteObsoleteQuests() {
    when(preferences.getBoolean(Prefs.SHOW_NOTES_NOT_PHRASED_AS_QUESTIONS, false)).thenReturn(true);
    // in the quest database mock, there are quests for note 4 and note 5
    List<OsmNoteQuest> quests = new ArrayList<>();
    Note note1 = createANote();
    note1.id = 4L;
    quests.add(new OsmNoteQuest(12L, note1, QuestStatus.NEW, null, new Date(), new OsmNoteQuestType(), null));
    Note note2 = createANote();
    note2.id = 5L;
    quests.add(new OsmNoteQuest(13L, note2, QuestStatus.NEW, null, new Date(), new OsmNoteQuestType(), null));
    when(noteQuestDB.getAll(any(BoundingBox.class), any(QuestStatus.class))).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(noteQuestDB).deleteAll(any(Collection.class));
    // note dao mock will only "find" the note #4
    List<Note> notes = new ArrayList<>();
    notes.add(note1);
    NotesDao noteServer = new TestListBasedNotesDao(notes);
    OsmNotesDownload dl = new OsmNotesDownload(noteServer, noteDB, noteQuestDB, createNoteDB, preferences, new OsmNoteQuestType());
    VisibleQuestListener listener = mock(VisibleQuestListener.class);
    dl.setQuestListener(listener);
    dl.download(new BoundingBox(0, 0, 1, 1), null, 1000);
    verify(noteQuestDB).deleteAll(any(Collection.class));
    verify(listener).onQuestsRemoved(any(Collection.class), any(QuestGroup.class));
}
Also used : ArrayList(java.util.ArrayList) QuestGroup(de.westnordost.streetcomplete.data.QuestGroup) QuestStatus(de.westnordost.streetcomplete.data.QuestStatus) Date(java.util.Date) VisibleQuestListener(de.westnordost.streetcomplete.data.VisibleQuestListener) Note(de.westnordost.osmapi.notes.Note) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) NotesDao(de.westnordost.osmapi.notes.NotesDao) Collection(java.util.Collection)

Example 9 with BoundingBox

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

the class SphericalEarthMathTest method testEnclosingBoundingBox.

public void testEnclosingBoundingBox() {
    LatLon pos = new OsmLatLon(0, 0);
    BoundingBox bbox = SphericalEarthMath.enclosingBoundingBox(pos, 5000);
    int dist = (int) (Math.sqrt(2) * 5000);
    // all four corners of the bbox should be 'radius' away
    assertEquals(dist, Math.round(SphericalEarthMath.distance(pos, bbox.getMin())));
    assertEquals(dist, Math.round(SphericalEarthMath.distance(pos, bbox.getMax())));
    assertEquals(dist, Math.round(SphericalEarthMath.distance(pos, new OsmLatLon(bbox.getMinLatitude(), bbox.getMaxLongitude()))));
    assertEquals(dist, Math.round(SphericalEarthMath.distance(pos, new OsmLatLon(bbox.getMaxLatitude(), bbox.getMinLongitude()))));
    assertEquals(225, Math.round(SphericalEarthMath.bearing(pos, bbox.getMin())));
    assertEquals(45, Math.round(SphericalEarthMath.bearing(pos, bbox.getMax())));
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 10 with BoundingBox

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

the class SlippyMapMathTest method testForthAndBack.

public void testForthAndBack() {
    LatLon p = new OsmLatLon(53.0, 9.0);
    Point tile = SlippyMapMath.enclosingTile(p, 15);
    BoundingBox bbox = SlippyMapMath.asBoundingBox(tile, 15);
    assertTrue(bbox.getMinLatitude() <= p.getLatitude());
    assertTrue(bbox.getMaxLatitude() >= p.getLatitude());
    assertTrue(bbox.getMinLongitude() <= p.getLongitude());
    assertTrue(bbox.getMaxLongitude() >= p.getLongitude());
    Rect r = SlippyMapMath.enclosingTiles(bbox, 15);
    BoundingBox bbox2 = SlippyMapMath.asBoundingBox(r, 15);
    assertEquals(bbox, bbox2);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) Rect(android.graphics.Rect) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) Point(android.graphics.Point) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Aggregations

BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)28 LatLon (de.westnordost.osmapi.map.data.LatLon)13 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)11 ArrayList (java.util.ArrayList)7 Rect (android.graphics.Rect)4 ElementGeometry (de.westnordost.streetcomplete.data.osm.ElementGeometry)4 Point (android.graphics.Point)3 Note (de.westnordost.osmapi.notes.Note)3 QuestGroup (de.westnordost.streetcomplete.data.QuestGroup)3 VisibleQuestListener (de.westnordost.streetcomplete.data.VisibleQuestListener)3 OsmElementQuestType (de.westnordost.streetcomplete.data.osm.OsmElementQuestType)3 Collection (java.util.Collection)3 List (java.util.List)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 OsmNode (de.westnordost.osmapi.map.data.OsmNode)2 QuestStatus (de.westnordost.streetcomplete.data.QuestStatus)2 OsmQuest (de.westnordost.streetcomplete.data.osm.OsmQuest)2 Date (java.util.Date)2 Cursor (android.database.Cursor)1 PointF (android.graphics.PointF)1