From 3e6bcb0665acd8f619390734693050a3f7c6ee51 Mon Sep 17 00:00:00 2001 From: Mikael Capelle Date: Fri, 9 Mar 2018 14:12:21 +0100 Subject: [PATCH] Start updating length (int -> float). --- src/main/org/insa/graph/Arc.java | 2 +- src/main/org/insa/graph/ArcBackward.java | 2 +- src/main/org/insa/graph/ArcForward.java | 6 +++--- src/main/org/insa/graph/GraphStatistics.java | 6 +++--- src/main/org/insa/graph/Node.java | 2 +- src/main/org/insa/graph/io/BinaryGraphReader.java | 10 ++++++++-- src/main/org/insa/graphics/PathsPanel.java | 4 ++-- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/org/insa/graph/Arc.java b/src/main/org/insa/graph/Arc.java index 5140884..5eed3fe 100644 --- a/src/main/org/insa/graph/Arc.java +++ b/src/main/org/insa/graph/Arc.java @@ -31,7 +31,7 @@ public interface Arc { /** * @return Length of this arc, in meters. */ - public int getLength(); + public float getLength(); /** * @return Minimum time required to travel this arc, in seconds. diff --git a/src/main/org/insa/graph/ArcBackward.java b/src/main/org/insa/graph/ArcBackward.java index 4a0aaaf..0c87bf0 100644 --- a/src/main/org/insa/graph/ArcBackward.java +++ b/src/main/org/insa/graph/ArcBackward.java @@ -37,7 +37,7 @@ class ArcBackward implements Arc { } @Override - public int getLength() { + public float getLength() { return this.originalArc.getLength(); } diff --git a/src/main/org/insa/graph/ArcForward.java b/src/main/org/insa/graph/ArcForward.java index 4f906c2..edd891a 100644 --- a/src/main/org/insa/graph/ArcForward.java +++ b/src/main/org/insa/graph/ArcForward.java @@ -15,7 +15,7 @@ class ArcForward implements Arc { private final Node origin, destination; // Length of the road (in meters). - private final int length; + private final float length; // Road information. private final RoadInformation info; @@ -32,7 +32,7 @@ class ArcForward implements Arc { * @param roadInformation Road information for this arc. * @param points Points representing this arc. */ - protected ArcForward(Node origin, Node dest, int length, RoadInformation roadInformation, + protected ArcForward(Node origin, Node dest, float length, RoadInformation roadInformation, ArrayList points) { this.origin = origin; this.destination = dest; @@ -53,7 +53,7 @@ class ArcForward implements Arc { @Override - public int getLength() { + public float getLength() { return length; } diff --git a/src/main/org/insa/graph/GraphStatistics.java b/src/main/org/insa/graph/GraphStatistics.java index fa6d115..9e98023 100644 --- a/src/main/org/insa/graph/GraphStatistics.java +++ b/src/main/org/insa/graph/GraphStatistics.java @@ -14,7 +14,7 @@ public class GraphStatistics { private final int maximumSpeed; // Maximum length of any arc on this graph. - private final int maximumLength; + private final float maximumLength; /** * Create a new GraphStatistics instance with the given value. @@ -23,7 +23,7 @@ public class GraphStatistics { * be used to indicate that this graph has no maximum limitation. * @param maximumLength Maximum length of any arc of the graph. */ - public GraphStatistics(int maximumSpeed, int maximumLength) { + public GraphStatistics(int maximumSpeed, float maximumLength) { this.maximumLength = maximumLength; this.maximumSpeed = maximumSpeed; } @@ -39,7 +39,7 @@ public class GraphStatistics { /** * @return Maximum length of any arc in the graph. */ - public int getMaximumLength() { + public float getMaximumLength() { return this.maximumLength; } diff --git a/src/main/org/insa/graph/Node.java b/src/main/org/insa/graph/Node.java index 9620cfe..33ee579 100644 --- a/src/main/org/insa/graph/Node.java +++ b/src/main/org/insa/graph/Node.java @@ -31,7 +31,7 @@ public class Node implements Comparable { * * @return The newly created forward arc (origin to destination). */ - public static Arc linkNodes(Node origin, Node destination, int length, + public static Arc linkNodes(Node origin, Node destination, float length, RoadInformation roadInformation, ArrayList points) { ArcForward arc = new ArcForward(origin, destination, length, roadInformation, points); origin.addSuccessor(arc); diff --git a/src/main/org/insa/graph/io/BinaryGraphReader.java b/src/main/org/insa/graph/io/BinaryGraphReader.java index 5e15450..4495c27 100644 --- a/src/main/org/insa/graph/io/BinaryGraphReader.java +++ b/src/main/org/insa/graph/io/BinaryGraphReader.java @@ -212,7 +212,7 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader { checkByteOrThrow(254); // Read successors and convert to arcs. - int maxLength = 0; + float maxLength = 0; final int copyNbTotalSuccesors = nbTotalSuccessors; // Stupid Java... observers.forEach((observer) -> observer.notifyStartReadingArcs(copyNbTotalSuccesors)); for (int node = 0; node < nbNodes; ++node) { @@ -225,7 +225,13 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader { int descrNum = this.read24bits(); // Length of the arc. - int length = dis.readUnsignedShort(); + float length; + if (getCurrentVersion() < 8) { + length = dis.readUnsignedShort(); + } + else { + length = dis.readInt() / 1000.0f; + } maxLength = Math.max(length, maxLength); // Number of segments. diff --git a/src/main/org/insa/graphics/PathsPanel.java b/src/main/org/insa/graphics/PathsPanel.java index 7bb0f6e..fcb8301 100644 --- a/src/main/org/insa/graphics/PathsPanel.java +++ b/src/main/org/insa/graphics/PathsPanel.java @@ -126,9 +126,9 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh String info = ""; // Display length - int length = path.getLength(); + float length = path.getLength(); if (length < 2000) { - info += String.format("Length = %d meters", length); + info += String.format("Length = %.1f meters", length); } else { info += String.format("Length = %.3f kilometers", length / 1000.);