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);
}
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;
}
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));
}
}
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));
}
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;
}
Aggregations