Rev 361 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Copyright (C) 2014 Steve Ratcliffe
*
* 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.files;
import java.util.ArrayList;
import java.util.List;
import uk.me.parabola.imgfmt.app.Label;
import uk.me.parabola.imgfmt.app.lbl.City;
import uk.me.parabola.imgfmt.app.lbl.Zip;
import test.elements.Line;
/**
* Data on a road from the NET file.
*
* @author Steve Ratcliffe
*/
public class RoadData
{
private int nodOffset
;
/** This is the offset of the road in NET */
private int offset
;
private List<Label> labels =
new ArrayList<>();
private Zip zip
;
private City city
;
private int length
;
private final List<Segment> segments =
new ArrayList<>();
private int offsetNod2
;
private Nod2Record nod2
;
private List<NodeLocator
> nodeLocations =
new ArrayList<>();
public void setNodOffset
(int nodOffset
) {
this.
nodOffset = nodOffset
;
}
public int getNodOffset
() {
return nodOffset
;
}
public void setOffset
(int offset
) {
this.
offset = offset
;
}
public int getOffset
() {
return offset
;
}
public void addLabel
(Label label
) {
labels.
add(label
);
}
public void setZip
(Zip zip
) {
this.
zip = zip
;
}
public Zip getZip
() {
return zip
;
}
public void setCity
(City city
) {
this.
city = city
;
}
public City getCity
() {
return city
;
}
public Label getLabel
(int n
) {
return labels.
get(n
);
}
public void setLength
(int length
) {
this.
length = length
;
}
public int getLength
() {
return length
;
}
public List<Segment> getSegments
() {
return segments
;
}
public List<Line> getLines
() {
List<Line> lines =
new ArrayList<>();
for (Segment seg : segments
)
lines.
add(seg.
getLine());
return lines
;
}
public void addSegment
(Segment seg
) {
segments.
add(seg
);
}
public void setOffsetNod2
(int offsetNod2
) {
this.
offsetNod2 = offsetNod2
;
}
public int getOffsetNod2
() {
return offsetNod2
;
}
public void setNod2
(Nod2Record nod2
) {
this.
nod2 = nod2
;
}
public Nod2Record getNod2
() {
return nod2
;
}
public void addNodeLocation
(NodeLocator nodeLocator
) {
nodeLocations.
add(nodeLocator
);
}
public NodeLocator locateNode
(RouteNode node
) {
for (NodeLocator loc : nodeLocations
) {
if (node.
getOffset() == loc.
getOffset())
return loc
;
}
return null;
}
public CoordLocator nextCoord
(CoordLocator loc,
boolean sign
) {
int snum = loc.
getSegmentNumber();
Segment segment = segments.
get(snum
);
int cnum = loc.
getCoordNumber();
if (sign
) {
if (++cnum
>= segment.
getNumPoints()) {
if (++snum
>= segments.
size())
return null;
segment = segments.
get(snum
);
cnum =
1;
}
} else {
cnum--
;
if (cnum
< 0)
return null;
}
CoordLocator ret =
new CoordLocator
();
ret.
setSegmentNumber(snum
);
ret.
setCoordNumber(cnum
);
ret.
setCoord(segment.
getLine().
getCoords().
get(cnum
));
return ret
;
}
}