use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.
the class RulesTest method checkEmpty.
/**
* Check if this rule would match an empty way.
*
* Such rules are not allowed.
*
* The problem case is length(). The length of the test way is 3.3 and we always make
* sure that length is only used in expressions with GTE and values of 1 or 2 so they
* are always true. However if there is a NOT in front if it it will then be false and
* so the simple test of of an empty way returning true could miss this case.
*
* So we also check with a way of length zero.
*
* Then there is still the problem that we do not detect an expression such as (length()>=2 & !(length()>=2))
*
* So reject any rule that has length() beneath a not.
*/
private static boolean checkEmpty(Op expr) {
Way way = makeWay();
boolean invalid = expr.eval(way);
Way way1 = new Way(2);
way1.addPoint(new Coord(1, 1));
if (expr.eval(way1))
invalid = true;
// So if there is a length() anywhere beneath a NOT then throw this rule out.
if (checkNotLength(expr, expr.isType(NOT)))
invalid = true;
return invalid;
}
use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.
the class ElementQuadTreeNode method split.
/**
* Splits this quadtree node into 4 subnodes.
*/
private void split() {
if (bounds.getHeight() <= 5 || bounds.getWidth() <= 5) {
log.error("Do not split more due to too small bounds: " + bounds);
return;
}
int halfLat = (bounds.getMinLat() + bounds.getMaxLat()) / 2;
int halfLong = (bounds.getMinLong() + bounds.getMaxLong()) / 2;
children = new ElementQuadTreeNode[4];
Area[] childBounds = new Area[4];
childBounds[0] = new Area(bounds.getMinLat(), bounds.getMinLong(), halfLat, halfLong);
childBounds[1] = new Area(halfLat, bounds.getMinLong(), bounds.getMaxLat(), halfLong);
childBounds[2] = new Area(bounds.getMinLat(), halfLong, halfLat, bounds.getMaxLong());
childBounds[3] = new Area(halfLat, halfLong, bounds.getMaxLat(), bounds.getMaxLong());
List<Map<Element, List<Coord>>> childElems = new ArrayList<Map<Element, List<Coord>>>(4);
for (int i = 0; i < 4; i++) {
childElems.add(new HashMap<Element, List<Coord>>());
}
for (Entry<Element, List<Coord>> elem : elementMap.entrySet()) {
if (elem.getKey() instanceof Node) {
Node node = (Node) elem.getKey();
for (int i = 0; i < childBounds.length; i++) {
if (childBounds[i].contains(node.getLocation())) {
childElems.get(i).put(node, EMPTY_LIST);
break;
}
}
} else if (elem.getKey() instanceof Way) {
List<List<Coord>> points = new ArrayList<List<Coord>>(4);
for (int i = 0; i < 4; i++) {
// usually ways are quite local
// therefore there is a high probability that only one child is covered
// dim the new list as the old list
points.add(new ArrayList<Coord>(elem.getValue().size()));
}
for (Coord c : elem.getValue()) {
for (int i = 0; i < childBounds.length; i++) {
if (childBounds[i].contains(c)) {
points.get(i).add(c);
break;
}
}
}
for (int i = 0; i < 4; i++) {
if (points.get(i).isEmpty() == false) {
childElems.get(i).put(elem.getKey(), points.get(i));
}
}
}
}
for (int i = 0; i < 4; i++) {
children[i] = new ElementQuadTreeNode(childBounds[i], childElems.get(i));
}
elementMap = null;
}
use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.
the class ElementQuadTreeNode method get.
/**
* Retrieves all elements that intersects the given polygon.
* @param polygon the polygon
* @param resultList results are stored in this collection
* @return the resultList
*/
public Set<Element> get(ElementQuadTreePolygon polygon, Set<Element> resultList) {
if (isEmpty()) {
return resultList;
}
if (polygon.getBbox().intersects(getBounds())) {
if (isLeaf()) {
for (Entry<Element, List<Coord>> elem : elementMap.entrySet()) {
if (resultList.contains(elem.getKey())) {
continue;
}
if (elem.getKey() instanceof Node) {
Node n = (Node) elem.getKey();
Coord c = n.getLocation();
if (polygon.getArea().contains(c.getLongitude(), c.getLatitude())) {
resultList.add(n);
}
} else if (elem.getKey() instanceof Way) {
for (Coord c : elem.getValue()) {
if (polygon.getArea().contains(c.getLongitude(), c.getLatitude())) {
resultList.add(elem.getKey());
break;
}
}
}
}
} else {
for (ElementQuadTreeNode child : children) {
if (child.isEmpty() == false && polygon.getArea().intersects(child.getBoundsAsRectangle())) {
java.awt.geom.Area subArea = (java.awt.geom.Area) polygon.getArea().clone();
subArea.intersect(Java2DConverter.createBoundsArea(new Area(child.getBounds().getMinLat() - 1, child.getBounds().getMinLong() - 1, child.getBounds().getMaxLat() + 1, child.getBounds().getMaxLong() + 1)));
child.get(new ElementQuadTreePolygon(subArea), resultList);
}
}
}
}
return resultList;
}
use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.
the class ActionReaderTest method makeElement.
/**
* Make a standard element for the tests.
*/
private Element makeElement() {
Element el = new Way(0);
el.addTag("park", "no");
el.addTag("test", "1");
return el;
}
use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.
the class RuleFileReaderTest method testContinueRepeat.
@Test
public void testContinueRepeat() {
RuleSet rs = makeRuleSet("highway=primary [0x1 continue]" + "highway=primary [0x2 continue]" + "highway=primary [0x3]" + "highway=primary [0x4]");
Way el = new Way(1);
el.addTag("highway", "primary");
for (int i = 0; i < 3; i++) {
GType type = getFirstType(rs, el);
assertNotNull(type);
assertEquals("first type", 1, type.getType());
assertEquals("continue search", true, type.isContinueSearch());
}
}
Aggregations