~ubuntu-branches/ubuntu/vivid/mkgmap/vivid

« back to all changes in this revision

Viewing changes to src/uk/me/parabola/imgfmt/app/net/RouteCenter.java

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2014-08-13 22:13:41 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140813221341-i9dzzjuto2o7hfh6
Tags: 0.0.0+svn3333-1
* New upstream version
  Closes: #745097
* add debian/classpath (thanks for the patch to Manfred Stock
  <manfred.stock+debian@gmail.com>)
  Closes: #741596
* d/copyright: DEP5

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
                log.info("new RouteCenter at " + centralPoint.toDegreeString() +
53
53
                                 ", nodes: " + nodes.size()     + " tabA: " + tabA.size() +
54
54
                                 " tabB: " + tabB.size());
 
55
        }
55
56
 
56
 
                // update lat/lon offsets; update arcs with table indices; populate tabC
 
57
        /**
 
58
         * update arcs with table indices; populate tabC
 
59
         */
 
60
        private void updateOffsets(){
57
61
                for (RouteNode node : nodes) {
58
62
                        node.setOffsets(centralPoint);
59
63
                        for (RouteArc arc : node.arcsIteration()) {
60
64
                                arc.setIndexA(tabA.getIndex(arc));
 
65
                                arc.setInternal(nodes.contains(arc.getDest()));
61
66
                                if (!arc.isInternal())
62
67
                                        arc.setIndexB(tabB.getIndex(arc.getDest()));
63
68
                        }
64
 
                        for (RouteRestriction restr : node.getRestrictions())
 
69
 
 
70
                        for (RouteRestriction restr : node.getRestrictions()){
 
71
                                if (restr.getArcs().size() >= 3){
 
72
                                        // only restrictions with more than 2 arcs can contain further arcs 
 
73
                                        for (RouteArc arc : restr.getArcs()){
 
74
                                                if (arc.getSource() == node)
 
75
                                                        continue;
 
76
                                                arc.setIndexA(tabA.getIndex(arc));
 
77
                                                arc.setInternal(nodes.contains(arc.getDest()));
 
78
                                                if (!arc.isInternal())
 
79
                                                        arc.setIndexB(tabB.getIndex(arc.getDest()));
 
80
                                        }
 
81
                                }
65
82
                                restr.setOffsetC(tabC.addRestriction(restr));
 
83
                        }
66
84
                }
67
85
                // update size of tabC offsets, now that tabC has been populated
68
86
                tabC.propagateSizeBytes();
69
87
        }
70
 
 
 
88
        
71
89
        /**
72
90
         * Write a route center.
73
91
         *
74
92
         * writer.position() is relative to the start of NOD 1.
75
93
         * Space for Table A is reserved but not written. See writeTableA.
76
94
         */
77
 
        public void write(ImgFileWriter writer) {
 
95
        public void write(ImgFileWriter writer, int[] classBoundaries) {
78
96
                assert !nodes.isEmpty(): "RouteCenter without nodes";
79
 
 
80
 
                for (RouteNode node : nodes)
 
97
                updateOffsets();
 
98
                int centerPos = writer.position();
 
99
                for (RouteNode node : nodes){
81
100
                        node.write(writer);
82
 
 
83
 
                int mult = 1 << NODHeader.DEF_ALIGN;
84
 
 
85
 
                // Get the position of the tables, and position there.
86
 
                int roundpos = (writer.position() + mult - 1) 
87
 
                                        >> NODHeader.DEF_ALIGN
88
 
                                        << NODHeader.DEF_ALIGN;
89
 
                int tablesOffset = roundpos + mult;
 
101
                        int group = node.getGroup();
 
102
                        if (group == 0)
 
103
                                continue;
 
104
                        if (centerPos < classBoundaries[group-1]){
 
105
                                // update positions (loop is used because style might not use all classes  
 
106
                                for (int i = group-1; i >= 0; i--){
 
107
                                        if (centerPos < classBoundaries[i] )
 
108
                                                classBoundaries[i] = centerPos;
 
109
                                }
 
110
                        }
 
111
                }
 
112
                int alignment = 1 << NODHeader.DEF_ALIGN;
 
113
                int alignMask = alignment - 1;
 
114
 
 
115
                // Calculate the position of the tables.
 
116
                int tablesOffset = (writer.position() + alignment) & ~alignMask;
90
117
                log.debug("write table a at offset", Integer.toHexString(tablesOffset));
91
118
 
92
119
                // Go back and fill in all the table offsets