Search in sources :

Example 26 with Area

use of uk.me.parabola.imgfmt.app.Area in project mkgmap by openstreetmap.

the class QuadTreeNode method clear.

public void clear() {
    this.children = null;
    points = new HashSet<Coord>();
    coveredBounds = new Area(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Area(uk.me.parabola.imgfmt.app.Area)

Example 27 with Area

use of uk.me.parabola.imgfmt.app.Area in project mkgmap by openstreetmap.

the class QuadTreeNode method split.

private void split() {
    if (bounds.getHeight() <= 1 || bounds.getWidth() <= 1) {
        return;
    }
    int halfLat = (bounds.getMinLat() + bounds.getMaxLat()) / 2;
    int halfLong = (bounds.getMinLong() + bounds.getMaxLong()) / 2;
    children = new QuadTreeNode[4];
    Area swBounds = new Area(bounds.getMinLat(), bounds.getMinLong(), halfLat, halfLong);
    Area nwBounds = new Area(halfLat + 1, bounds.getMinLong(), bounds.getMaxLat(), halfLong);
    Area seBounds = new Area(bounds.getMinLat(), halfLong + 1, halfLat, bounds.getMaxLong());
    Area neBounds = new Area(halfLat + 1, halfLong + 1, bounds.getMaxLat(), bounds.getMaxLong());
    children[0] = new QuadTreeNode(swBounds);
    children[1] = new QuadTreeNode(nwBounds);
    children[2] = new QuadTreeNode(seBounds);
    children[3] = new QuadTreeNode(neBounds);
    Collection<Coord> copyPoints = points;
    points = null;
    for (Coord c : copyPoints) {
        add(c);
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Area(uk.me.parabola.imgfmt.app.Area)

Example 28 with Area

use of uk.me.parabola.imgfmt.app.Area in project mkgmap by openstreetmap.

the class LineClipperTest method testListClip.

/**
 * Test an original line that enters the area, leaves it and then goes back
 * into the area.  This should give two lines in the result set.
 */
@Test
public void testListClip() {
    // Add your code here
    Area a = new Area(100, 100, 200, 200);
    List<Coord> l = Arrays.asList(new Coord(20, 30), new Coord(40, 60), new Coord(102, 110), new Coord(150, 150), new Coord(210, 220), new Coord(190, 135));
    List<List<Coord>> list = LineClipper.clip(a, l);
    // There should be exactly two lines
    assertEquals("should be two lines", 2, list.size());
    // No empty lists
    for (List<Coord> lco : list) assertTrue("empty list", !lco.isEmpty());
    // Check values
    Coord[] firstExpectedLine = { new Coord(100, 108), new Coord(102, 110), new Coord(150, 150), new Coord(193, 200) };
    assertArrayEquals(firstExpectedLine, list.get(0).toArray());
    Coord[] secondExpectedLine = { new Coord(200, 178), new Coord(190, 135) };
    assertArrayEquals(secondExpectedLine, list.get(1).toArray());
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Area(uk.me.parabola.imgfmt.app.Area) List(java.util.List) Test(org.junit.Test)

Example 29 with Area

use of uk.me.parabola.imgfmt.app.Area in project mkgmap by openstreetmap.

the class TREHeader method readFileHeader.

/**
 * Read the rest of the header.  Specific to the given file.  It is guaranteed
 * that the file position will be set to the correct place before this is
 * called.
 *
 * @param reader The header is read from here.
 */
protected void readFileHeader(ImgFileReader reader) throws ReadFailedException {
    assert reader.position() == COMMON_HEADER_LEN;
    int maxLat = reader.get3();
    int maxLon = reader.get3();
    int minLat = reader.get3();
    int minLon = reader.get3();
    // fix problem with value 0x800000 that is interpreted as a negative value
    if (maxLon < minLon && maxLon == -8388608)
        // its 180 degrees, not -180
        maxLon = 8388608;
    setBounds(new Area(minLat, minLon, maxLat, maxLon));
    log.info("read area is", getBounds());
    // more to do...
    mapLevelPos = reader.getInt();
    mapLevelsSize = reader.getInt();
    subdivPos = reader.getInt();
    subdivSize = reader.getInt();
    copyright.readSectionInfo(reader, true);
    reader.getInt();
    poiDisplayFlags = reader.get();
    displayPriority = reader.get3();
    reader.getInt();
    reader.getChar();
    reader.get();
    polyline.readSectionInfo(reader, true);
    reader.getInt();
    polygon.readSectionInfo(reader, true);
    reader.getInt();
    points.readSectionInfo(reader, true);
    reader.getInt();
    int mapInfoOff = mapLevelPos;
    if (subdivPos < mapInfoOff)
        mapInfoOff = subdivPos;
    if (copyright.getPosition() < mapInfoOff)
        mapInfoOff = copyright.getPosition();
    mapInfoSize = mapInfoOff - getHeaderLength();
    if (getHeaderLength() > 116) {
        reader.position(116);
        mapId = reader.getInt();
    }
    if (getHeaderLength() > 120) {
        reader.getInt();
        extTypeOffsets.readSectionInfo(reader, true);
    }
}
Also used : Area(uk.me.parabola.imgfmt.app.Area)

Example 30 with Area

use of uk.me.parabola.imgfmt.app.Area in project mkgmap by openstreetmap.

the class MapSplitter method splitMaxSize.

// addAreasToList
/**
 * Split the area into portions that have the maximum size.  There is a
 * maximum limit to the size of a subdivision (16 bits or about 1.4 degrees
 * at the most detailed zoom level).
 *
 * The size depends on the shift level.
 *
 * We are choosing a limit smaller than the real max to allow for
 * uncertainty about what happens with features that extend beyond the box.
 *
 * If the area is already small enough then it will be returned unchanged.
 *
 * @param mapArea The area that needs to be split down.
 * @return An array of map areas.  Each will be below the max size.
 */
private MapArea[] splitMaxSize(MapArea mapArea) {
    /**
     * mapArea.getBounds() comes from the original map source or parent/split MapArea.
     * mapArea.getFullBounds() is calculated from elements added to the MapArea.
     * Normally, mapArea.getBounds() and getFullBounds() are well defined and
     * getFullBounds() is a little bit bigger than bounds() because lines/shapes are allowed
     * to go slightly out of their area.
     * MapArea.split() should use getBounds() because otherwise can get primary area overlap
     * which conflicts with concept of orderByDecreasingArea.
     * Some map sources might not set getBounds().
     * If there are no elements, getFullBounds isEmpty.
     */
    Area bounds = mapArea.getBounds();
    if (// ??? think this func is wrong for single point/horiz/vert/line
    bounds.isEmpty())
        bounds = mapArea.getFullBounds();
    if (bounds.isEmpty())
        return null;
    int shift = zoom.getShiftValue();
    int width = bounds.getWidth() >> shift;
    int height = bounds.getHeight() >> shift;
    // There is an absolute maximum size that a division can be.  Make sure
    // that we are well inside that.
    int xsplit = 1;
    if (width > MAX_DIVISION_SIZE)
        xsplit = width / MAX_DIVISION_SIZE + 1;
    int ysplit = 1;
    if (height > MAX_DIVISION_SIZE)
        ysplit = height / MAX_DIVISION_SIZE + 1;
    log.debug("splitMaxSize: bounds", bounds, "shift", shift, "width", width, "height", height, "xsplit", xsplit, "ysplit", ysplit);
    return mapArea.split(xsplit, ysplit, bounds, false);
}
Also used : Area(uk.me.parabola.imgfmt.app.Area)

Aggregations

Area (uk.me.parabola.imgfmt.app.Area)49 Test (org.junit.Test)26 Coord (uk.me.parabola.imgfmt.app.Coord)14 ArrayList (java.util.ArrayList)9 List (java.util.List)7 MapShape (uk.me.parabola.mkgmap.general.MapShape)4 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)3 Way (uk.me.parabola.mkgmap.reader.osm.Way)3 Rectangle (java.awt.Rectangle)2 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ExitException (uk.me.parabola.imgfmt.ExitException)2 MapFailedException (uk.me.parabola.imgfmt.MapFailedException)2 Point (uk.me.parabola.imgfmt.app.trergn.Point)2 Zoom (uk.me.parabola.imgfmt.app.trergn.Zoom)2 Element (uk.me.parabola.mkgmap.reader.osm.Element)2 Node (uk.me.parabola.mkgmap.reader.osm.Node)2 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)1