Subversion Repositories display

Rev

Rev 310 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 * Copyright (C) 2006 - 2012.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 or
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */


package test.elements;

import java.util.ArrayList;
import java.util.List;

import uk.me.parabola.imgfmt.app.Coord;
import uk.me.parabola.imgfmt.app.net.RoadDef;
import uk.me.parabola.imgfmt.app.trergn.Subdivision;
import uk.me.parabola.log.Logger;

/**
 * Represents a multi-segment line.  Eg for a road. As with all map objects
 * it can only exist as part of a subdivision.
 *
 * Writing these out is particularly tricky as deltas between points are packed
 * into the smallest number of bits possible.
 *
 * I am not trying to make the smallest map, so it will not be totally optimum.
 *
 * @author Steve Ratcliffe
 */

public class Line extends MapObject {
        private static final Logger log = Logger.getLogger(Line.class);

        // flags in the label offset
        private static final int FLAG_NETINFO = 0x800000;
        private static final int FLAG_EXTRABIT = 0x400000;

        // flags in the type
        private static final int FLAG_DIR = 0x40;
        private static final int FLAG_2BYTE_LEN = 0x80;

        private int net1Offset;

        // If a road gets subdivided into several segments, this
        // says whether this line is the last segment. Need this
        // for writing extra bits.
        private boolean lastSegment = true;

        // Set if it is a one-way street for example.
        private boolean direction;

        // The actual points that make up the line.
        private final List<Coord> points = new ArrayList<Coord>();
        private boolean nodeFlags;

        public Line(Subdivision div) {
                setSubdiv(div);
        }

        public void addCoord(Coord co) {
                points.add(co);
        }
       
        public void addCoords(List<Coord> coords) {
                points.addAll(coords);
        }

        List<Coord> getPoints() {
                return points;
        }

        public void setDirection(boolean direction) {
                this.direction = direction;
        }

        public void setLastSegment(boolean last) {
                lastSegment = last;
        }

        public boolean isLastSegment() {
                return lastSegment;
        }

        public int getNet1Offset() {
                return net1Offset;
        }

        public void setNet1Offset(int net1Offset) {
                this.net1Offset = net1Offset;
        }

        public boolean sharesNodeWith(Line other) {
                for (Coord p1 : points) {
                        if (p1.getId() != 0) {
                                // point is a node, see if the other line contain the
                                // same node
                                for (Coord p2 : other.points)
                                        if (p1.getId() == p2.getId())
                                                return true;
                        }
                }

                return false;
        }

        public Coord getFirstPoint() {
                return points.get(0);
        }

        public Coord getLastPoint() {
                return points.get(points.size() - 1);
        }

        public List<Coord> getCoords() {
                return points;
        }

        public void setNodeFlags(boolean nodeFlags) {
                this.nodeFlags = nodeFlags;
        }

        public boolean hasNodeFlags() {
                return nodeFlags;
        }
}