Subversion Repositories display

Rev

Rev 352 | 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.trergn.Subdivision;

/**
 * Represents a multi-segment line.  Eg for a road. As with all map objects
 * it can only exist as part of a subdivision.
 *
 * @author Steve Ratcliffe
 */

public class Line extends MapObject {
        private int netOffset;

        // The number within the subdiv
        private int lineNumber;

        // 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<>();
        private boolean nodeFlags;
        private boolean hasNet;

        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 boolean isDirection() {
                return direction;
        }

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

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

        public boolean isLastSegment() {
                return lastSegment;
        }

        public int getNetOffset() {
                return netOffset;
        }

        public void setNetOffset(int netOffset) {
                hasNet = true;
                this.netOffset = netOffset;
        }

        public boolean hasNet() {
                return hasNet;
        }

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

        public int getDivAndNum() {
                return (getSubdiv().getNumber() << 16 | (getLineNumber()));
        }

        public int getLineNumber() {
                return lineNumber;
        }

        public void setLineNumber(int lineNumber) {
                this.lineNumber = lineNumber;
        }
}