Ignore:
Timestamp:
2013-02-19T18:02:02+01:00 (13 years ago)
Author:
malcolmh
Message:

save

Location:
applications/editors/josm/plugins/smed2/src/seamap
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/smed2/src/seamap/MapHelper.java

    r29174 r29266  
    33import java.awt.geom.Point2D;
    44
    5 import seamap.SeaMap.Coord;
     5import seamap.SeaMap.*;
    66
    77public interface MapHelper {
    8         Point2D getPoint(Coord coord);
     8        Point2D getPoint(Snode coord);
    99}
  • applications/editors/josm/plugins/smed2/src/seamap/Renderer.java

    r29215 r29266  
    1010package seamap;
    1111
    12 import java.awt.BasicStroke;
    13 import java.awt.Color;
    14 import java.awt.Font;
    15 import java.awt.Graphics2D;
    16 import java.awt.Rectangle;
    17 import java.awt.RenderingHints;
    18 import java.awt.geom.AffineTransform;
    19 import java.awt.geom.GeneralPath;
    20 import java.awt.geom.Path2D;
    21 import java.awt.geom.Point2D;
    22 import java.util.ArrayList;
    23 import java.util.HashMap;
    24 
    25 import s57.S57att.Att;
    26 import s57.S57obj.Obj;
     12import java.awt.*;
     13import java.awt.geom.*;
     14import java.util.*;
     15
     16import s57.S57att.*;
     17import s57.S57obj.*;
    2718import s57.S57val.*;
    2819import s57.S57val;
     
    7162        }
    7263
    73         public static double signedArea(Feature feature) {
    74           if (feature.flag == Fflag.AREA) {
    75                         ArrayList<Long> way;
    76                         if (map.mpolys.containsKey(feature.refs)) {
    77                                 way = map.ways.get(map.mpolys.get(feature.refs));
    78                         } else {
    79                                 way = map.ways.get(feature.refs);
    80                         }
    81                         Coord coord = map.nodes.get(way.get(0));
    82             double llon = coord.lon;
    83             double llat = coord.lat;
    84             double sigma = 0.0;
    85                         for (long node : way) {
    86                                 coord = map.nodes.get(node);
    87                                 double lat = coord.lat;
    88                                 double lon = coord.lon;
    89                                 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat));
    90                                 llon = lon;
    91                                 llat = lat;
    92             }
    93             return sigma;
    94           }
    95           return 0;
    96         }
    97 
    98         public boolean handOfArea(Feature feature) {
    99                 return (signedArea(feature) < 0);
    100         }
    101        
    102         public static double calcArea(Feature feature) {
    103           return Math.abs(signedArea(feature)) * 3444 * 3444 / 2.0;
    104         }
    105 
    106         public static Coord findCentroid(Feature feature) {
    107                 Coord coord;
    108                 ArrayList<Long> way;
    109                 if (map.mpolys.containsKey(feature.refs)) {
    110                         way = map.ways.get(map.mpolys.get(feature.refs).get(0));
    111                 } else {
    112                         way = map.ways.get(feature.refs);
    113                 }
    114                 switch (feature.flag) {
    115                 case NODE:
    116                         return map.nodes.get(feature.refs);
    117                 case LINE:
    118                         coord = map.nodes.get(way.get(1));
    119                         break;
    120                 case AREA:
    121                 default:
    122                         coord = map.nodes.get(way.get(0));
    123                 }
    124     double slat = 0.0;
    125     double slon = 0.0;
    126     double sarc = 0.0;
    127     double llat = coord.lat;
    128     double llon = coord.lon;
    129                 for (long node : way) {
    130                         coord = map.nodes.get(node);
    131       double lon = coord.lon;
    132       double lat = coord.lat;
    133       double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
    134       slat += (lat * arc);
    135       slon += (lon * arc);
    136       sarc += arc;
    137       llat = lat;
    138       llon = lon;
    139                 }
    140                 return map.new Coord((sarc > 0.0 ? slat/sarc : 0.0), (sarc > 0.0 ? slon/sarc : 0.0));
    141         }
    142        
    14364        public static void symbol(Feature feature, Symbol symbol, Obj obj, Delta delta) {
    144                 Point2D point = helper.getPoint(findCentroid(feature));
     65                Point2D point = helper.getPoint(feature.centre);
    14566                if (obj == null) {
    14667                        Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), delta, null);
     
    17192       
    17293        public static void lineSymbols(Feature feature, Symbol prisymb, double space, Symbol secsymb, int ratio) {
    173                 if (feature.flag != Fflag.NODE) {
     94                if (feature.flag != Fflag.POINT) {
    17495                        Rectangle prect = symbolSize(prisymb);
    17596                        Rectangle srect = symbolSize(secsymb);
     
    180101                                double psize = Math.abs(prect.getY()) * sScale;
    181102                                double ssize = (srect != null) ? Math.abs(srect.getY()) * sScale : 0;
    182                                 if (map.outers.containsKey(feature.refs)) {
    183                                         ways.addAll(map.mpolys.get(map.outers.get(feature.refs)));
    184                                 } else {
    185                                         if (map.mpolys.containsKey(feature.refs)) {
    186                                                 ways.addAll(map.mpolys.get(feature.refs));
    187                                         } else {
    188                                                 ways.add(feature.refs);
    189                                         }
    190                                 }
     103//                              if (map.outers.containsKey(feature.refs)) {
     104//                                      ways.addAll(map.mpolys.get(map.outers.get(feature.refs)));
     105//                              } else {
     106//                                      if (map.mpolys.containsKey(feature.refs)) {
     107//                                              ways.addAll(map.mpolys.get(feature.refs));
     108//                                      } else {
     109//                                              ways.add(feature.refs);
     110//                                      }
     111//                              }
    191112                                Point2D prev = new Point2D.Double();
    192113                                Point2D next = new Point2D.Double();
     
    201122                                for (long way : ways) {
    202123                                        boolean first = true;
    203                                         for (long node : map.ways.get(way)) {
     124/*                                      for (long node : map.ways.get(way)) {
    204125                                                prev = next;
    205                                                 next = helper.getPoint(map.nodes.get(node));
     126                                                next = helper.getPoint(map.points.get(node));
    206127                                                angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
    207128                                                piv = true;
     
    246167                                                }
    247168                                        }
    248                                 }
     169*/                              }
    249170                        }
    250171                }
     
    252173
    253174        public static void lineVector (Feature feature, LineStyle style) {
    254                 if (feature.flag != Fflag.NODE) {
     175                if (feature.flag != Fflag.POINT) {
    255176                        ArrayList<Long> ways = new ArrayList<Long>();
    256                         if (map.outers.containsKey(feature.refs)) {
    257                                 ways.addAll(map.mpolys.get(map.outers.get(feature.refs)));
    258                         } else {
    259                                 if (map.mpolys.containsKey(feature.refs)) {
    260                                         ways.addAll(map.mpolys.get(feature.refs));
    261                                 } else {
    262                                         ways.add(feature.refs);
    263                                 }
    264                         }
     177//                      if (map.outers.containsKey(feature.refs)) {
     178//                              ways.addAll(map.mpolys.get(map.outers.get(feature.refs)));
     179//                      } else {
     180//                              if (map.mpolys.containsKey(feature.refs)) {
     181//                                      ways.addAll(map.mpolys.get(feature.refs));
     182//                              } else {
     183//                                      ways.add(feature.refs);
     184//                              }
     185//                      }
    265186                        Path2D.Double p = new Path2D.Double();
    266187                        p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
    267188                        for (long way : ways) {
    268189                                boolean first = true;
    269                                 for (long node : map.ways.get(way)) {
    270                                         Point2D point = helper.getPoint(map.nodes.get(node));
     190/*                              for (long node : map.ways.get(way)) {
     191                                        Point2D point = helper.getPoint(map.points.get(node));
    271192                                        if (first) {
    272193                                                p.moveTo(point.getX(), point.getY());
     
    294215                                g2.setPaint(style.fill);
    295216                                g2.fill(p);
    296                         }
     217*/                      }
    297218                }
    298219        }
     
    301222                Symbol label = new Symbol();
    302223                label.add(new Instr(Prim.TEXT, new Caption(str, font, colour, (delta == null) ? new Delta(Handle.CC, null) : delta)));
    303                 Point2D point = helper.getPoint(findCentroid(feature));
     224                Point2D point = helper.getPoint(feature.centre);
    304225                Symbols.drawSymbol(g2, label, tScale, point.getX(), point.getY(), null, null);
    305226        }
  • applications/editors/josm/plugins/smed2/src/seamap/Rules.java

    r29206 r29266  
    1010package seamap;
    1111
    12 import java.awt.BasicStroke;
    1312import java.awt.Color;
    1413import java.awt.Font;
     
    179178                        break;
    180179                case FAIRWY:
    181                         if (Renderer.calcArea(feature) > 2.0) {
     180                        if (feature.area > 2.0) {
    182181                                if (zoom < 16)
    183182                                        Renderer.lineVector(feature, new LineStyle(new Color(0xc480ff), 8, new float[] { 50, 50 }, new Color(0x40ffffff, true)));
  • applications/editors/josm/plugins/smed2/src/seamap/SeaMap.java

    r29215 r29266  
    1010package seamap;
    1111
    12 import java.util.ArrayList;
    13 import java.util.EnumMap;
    14 import java.util.HashMap;
     12import java.util.*;
    1513
    1614import s57.S57att;
     
    2321public class SeaMap {
    2422
    25         public enum Fflag {
    26                 UNKN, NODE, LINE, AREA
    27         }
    28        
    2923        public enum Nflag {
    3024                ANON, ISOL, CONN
    3125        }
    32 
    33         public class Coord {
     26       
     27        public class Snode {
    3428                public double lat;
    3529                public double lon;
    3630                public Nflag flg;
    3731
    38                 public Coord(double ilat, double ilon) {
     32                public Snode() {
     33                        flg = Nflag.ANON;
     34                        lat = 0;
     35                        lon = 0;
     36                }
     37                public Snode(double ilat, double ilon) {
     38                        flg = Nflag.ANON;
    3939                        lat = ilat;
    4040                        lon = ilon;
    41                         flg = Nflag.ANON;
    42                 }
    43                 public Coord(double ilat, double ilon, Nflag iflg) {
     41                }
     42                public Snode(double ilat, double ilon, Nflag iflg) {
    4443                        lat = ilat;
    4544                        lon = ilon;
     
    4746                }
    4847        }
     48       
     49        public class Edge {
     50                public boolean forward;
     51                public long first;
     52                public long last;
     53                public ArrayList<Long> nodes;
     54                public Edge() {
     55                        forward = true;
     56                        first = 0;
     57                        last = 0;
     58                        nodes = new ArrayList<Long>();
     59                }
     60        }
     61       
     62        public class Side {
     63                Edge edge;
     64                boolean forward;
     65                public Side(Edge iedge, boolean ifwd) {
     66                        edge = iedge;
     67                        forward = ifwd;
     68                }
     69        }
     70       
     71        public class Bound {
     72                public boolean outer;
     73                ArrayList<Side> sides;
     74                public Bound() {
     75                        outer = true;
     76                        sides = new ArrayList<Side>();
     77                }
     78                public Bound(Side iside, boolean irole) {
     79                        outer = irole;
     80                        sides = new ArrayList<Side>();
     81                        sides.add(iside);
     82                }
     83        }
     84
     85        public class Area extends ArrayList<Bound> {
     86                public Area() {
     87                        super();
     88                }
     89        }
    4990
    5091        public class AttItem {
     
    5798                }
    5899        }
    59 
     100       
    60101        public class AttMap extends EnumMap<Att, AttItem> {
    61102                public AttMap() {
     
    76117        }
    77118       
    78         public class NodeTab extends HashMap<Long, Coord> {
     119        public class NodeTab extends HashMap<Long, Snode> {
    79120                public NodeTab() {
    80121                        super();
     
    82123        }
    83124       
    84         public class WayTab extends HashMap<Long, ArrayList<Long>> {
    85                 public WayTab() {
     125        public class EdgeTab extends HashMap<Long, Edge> {
     126                public EdgeTab() {
    86127                        super();
    87128                }
    88129        }
    89130       
    90         public class MpolyTab extends HashMap<Long, Long> {
    91                 public MpolyTab() {
     131        public class AreaTab extends HashMap<Long, Area> {
     132                public AreaTab() {
    92133                        super();
    93134                }
     
    104145                        super();
    105146                }
     147        }
     148       
     149        public enum Fflag {
     150                UNKN, POINT, LINE, AREA
    106151        }
    107152       
     
    112157                public AttMap atts;
    113158                public ObjMap objs;
     159                public long area;
     160                public Snode centre;
    114161
    115162                Feature() {
     
    119166                        atts = new AttMap();
    120167                        objs = new ObjMap();
     168                        area = 0;
     169                        centre = new Snode();
    121170                }
    122171        }
    123172
    124173        public NodeTab nodes;
    125         public WayTab ways;
    126         public WayTab mpolys;
    127         public MpolyTab outers;
     174        public EdgeTab edges;
     175        public AreaTab areas;
     176       
    128177        public FtrMap features;
    129178        public FtrTab index;
    130179
    131180        private Feature feature;
    132         private ArrayList<Long> list;
     181        private Edge edge;
     182        private ArrayList<Long> outers;
     183        private ArrayList<Long> inners;
    133184
    134185        public SeaMap() {
    135186                nodes = new NodeTab();
    136                 ways = new WayTab();
    137                 mpolys = new WayTab();
    138                 outers = new MpolyTab();
     187                edges = new EdgeTab();
     188                areas = new AreaTab();
    139189                feature = new Feature();
    140190                features = new FtrMap();
     
    143193
    144194        public void addNode(long id, double lat, double lon) {
    145                 nodes.put(id, new Coord(Math.toRadians(lat), Math.toRadians(lon)));
     195                nodes.put(id, new Snode(Math.toRadians(lat), Math.toRadians(lon)));
    146196                feature = new Feature();
    147197                feature.refs = id;
    148                 feature.flag = Fflag.NODE;
    149         }
    150 
    151         public void moveNode(long id, double lat, double lon) {
    152                 nodes.put(id, new Coord(Math.toRadians(lat), Math.toRadians(lon)));
    153         }
    154 
    155         public void addWay(long id) {
    156                 list = new ArrayList<Long>();
    157                 ways.put(id, list);
     198                feature.flag = Fflag.POINT;
     199                edge = null;
     200        }
     201
     202        public void addEdge(long id) {
    158203                feature = new Feature();
    159204                feature.refs = id;
    160205                feature.flag = Fflag.LINE;
    161         }
    162 
    163         public void addMpoly(long id) {
    164                 list = new ArrayList<Long>();
    165                 mpolys.put(id, list);
     206                edge = new Edge();
     207        }
     208
     209        public void addToEdge(long node) {
     210                if (edge.first == 0) {
     211                        edge.first = node;
     212                } else {
     213                        if (edge.last != 0) {
     214                                edge.nodes.add(edge.last);
     215                        }
     216                        edge.last = node;
     217                }
     218        }
     219
     220        public void addArea(long id) {
    166221                feature = new Feature();
    167222                feature.refs = id;
    168223                feature.flag = Fflag.AREA;
    169         }
    170 
    171         public void addToWay(long node) {
    172                 list.add(node);
    173         }
    174 
    175         public void addToMpoly(long way, boolean outer) {
     224                outers = new ArrayList<Long>();
     225                inners = new ArrayList<Long>();
     226                edge = null;
     227        }
     228
     229        public void addToArea(long id, boolean outer) {
    176230                if (outer) {
    177                         list.add(0, way);
    178                         outers.put(way, feature.refs);
     231                        outers.add(id);
    179232                } else {
    180                         list.add(way);
    181                 }
    182         }
    183 
    184         public void tagsDone(long id) {
    185                 if ((feature.type != Obj.UNKOBJ) && !((feature.flag == Fflag.LINE) && (list.size() < 2))) {
    186                         index.put(id, feature);
    187                         if ((feature.flag == Fflag.LINE) && (list.size() > 0) && (list.get(0).equals(list.get(list.size() - 1)))) {
    188                                 feature.flag = Fflag.AREA;
    189                         }
    190                         if (features.get(feature.type) == null) {
    191                                 features.put(feature.type, new ArrayList<Feature>());
    192                         }
    193                         features.get(feature.type).add(feature);
    194                 }
    195         }
    196 
     233                        inners.add(id);
     234                }
     235        }
     236       
    197237        public void addTag(String key, String val) {
    198238                String subkeys[] = key.split(":");
     
    235275                }
    236276        }
     277
     278        public void tagsDone(long id) {
     279                if ((feature.type != Obj.UNKOBJ) && !((edge != null) && (edge.last == 0))) {
     280                        index.put(id, feature);
     281                        if (features.get(feature.type) == null) {
     282                                features.put(feature.type, new ArrayList<Feature>());
     283                        }
     284                        features.get(feature.type).add(feature);
     285                }
     286                switch (feature.flag) {
     287                case POINT:
     288                        Snode node = nodes.get(id);
     289                        if (node.flg != Nflag.CONN) {
     290                                node.flg = Nflag.ISOL;
     291                        }
     292                        break;
     293                case LINE:
     294                        edges.put(id, edge);
     295                        nodes.get(edge.first).flg = Nflag.CONN;
     296                        nodes.get(edge.last).flg = Nflag.CONN;
     297                        if (edge.first == edge.last) {
     298                                feature.flag = Fflag.AREA;
     299                                Area area = new Area();
     300                                area.add(new Bound(new Side(edge, edge.forward), true));
     301                                areas.put(id, area);
     302                        }
     303                        break;
     304                case AREA:
     305                        Area area = new Area();
     306                        for (ArrayList<Long> role = outers; role != null; role = inners) {
     307                                while (!role.isEmpty()) {
     308                                        Edge edge = edges.get(role.remove(0));
     309                                        long node1 = edge.first;
     310                                        long node2 = edge.last;
     311                                        Bound bound = new Bound(new Side(edge, edge.forward), (role == outers));
     312                                        if (node1 != node2) {
     313                                                for (ListIterator<Long> it = role.listIterator(0); it.hasNext(); ) {
     314                                            Edge nedge = edges.get(it.next());
     315                                            if (nedge.first == node2) {
     316                                                bound.sides.add(new Side(nedge, true));
     317                                                it.remove();
     318                                                if (nedge.last == node2) break;
     319                                            } else if (nedge.last == node2) {
     320                                                bound.sides.add(new Side(nedge, false));
     321                                                it.remove();
     322                                                if (nedge.first == node2) break;
     323                                            }
     324                                                }
     325                                        }
     326                                        area.add(bound);
     327                                }
     328                                if (role == outers) {
     329                                        if (area.isEmpty()) {
     330                                                role = null;
     331                                        } else {
     332                                                areas.put(id, area);
     333                                        }
     334                                }
     335                        }
     336                        break;
     337                }
     338                feature.centre = findCentroid(feature);
     339        }
     340
     341        public double signedArea(Bound bound) {
     342                Snode node;
     343                double lat, lon, llon, llat;
     344                lat = lon = llon = llat = 0;
     345                double sigma = 0;
     346                ListIterator<Long> it;
     347                for (Side side : bound.sides) {
     348                        if (side.forward) {
     349                                node = nodes.get(side.edge.first);
     350                                lat = node.lat;
     351                                lon = node.lon;
     352                                it = side.edge.nodes.listIterator();
     353                                while (it.hasNext()) {
     354                                        llon = lon;
     355                                        llat = lat;
     356                                        node = nodes.get(it.next());
     357                                        lat = node.lat;
     358                                        lon = node.lon;
     359                                        sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat));
     360                                }
     361                                llon = lon;
     362                                llat = lat;
     363                                node = nodes.get(side.edge.last);
     364                                lat = node.lat;
     365                                lon = node.lon;
     366                                sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat));
     367                        } else {
     368                                node = nodes.get(side.edge.last);
     369                                lat = node.lat;
     370                                lon = node.lon;
     371                                it = side.edge.nodes.listIterator(side.edge.nodes.size());
     372                                while (it.hasPrevious()) {
     373                                        llon = lon;
     374                                        llat = lat;
     375                                        node = nodes.get(it.previous());
     376                                        lat = node.lat;
     377                                        lon = node.lon;
     378                                        sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat));
     379                                }
     380                                llon = lon;
     381                                llat = lat;
     382                                node = nodes.get(side.edge.first);
     383                                lat = node.lat;
     384                                lon = node.lon;
     385                                sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat));
     386                        }
     387                }
     388                return sigma;
     389        }
     390
     391        public boolean handOfArea(Bound bound) {
     392                return (signedArea(bound) < 0);
     393        }
     394       
     395        public double calcArea(Bound bound) {
     396          return Math.abs(signedArea(bound)) * 3444 * 3444 / 2.0;
     397        }
     398
     399        public Snode findCentroid(Feature feature) {
     400    double lat, lon, slat, slon, sarc, llat, llon;
     401    lat = lon = slat = slon = sarc = llat = llon = 0;
     402                switch (feature.flag) {
     403                case POINT:
     404                        return nodes.get(feature.refs);
     405                case LINE:
     406                        Edge edge = edges.get(feature.refs);
     407                        llat = nodes.get(edge.first).lat;
     408                        llon = nodes.get(edge.first).lon;
     409                        for (long id : edge.nodes) {
     410                                lat = nodes.get(id).lat;
     411                                lon = nodes.get(id).lon;
     412                                sarc += (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
     413                                llat = lat;
     414                                llon = lon;
     415                        }
     416                        lat = nodes.get(edge.last).lat;
     417                        lon = nodes.get(edge.last).lon;
     418                        sarc += (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
     419                        double harc = sarc / 2;
     420                        sarc = 0;
     421                        llat = nodes.get(edge.first).lat;
     422                        llon = nodes.get(edge.first).lon;
     423                        for (long id : edge.nodes) {
     424                                lat = nodes.get(id).lat;
     425                                lon = nodes.get(id).lon;
     426                                sarc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
     427                                if (sarc > harc) break;
     428                                harc -= sarc;
     429                                llat = lat;
     430                                llon = lon;
     431                        }
     432                        if (sarc <= harc) {
     433                                lat = nodes.get(edge.last).lat;
     434                                lon = nodes.get(edge.last).lon;
     435                                sarc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
     436                        }
     437                        double frac = harc / sarc;
     438                        return new Snode(llat + ((lat - llat) / frac), llon + ((lon - llon) / frac));
     439                case AREA:
     440                        Bound bound = areas.get(feature.refs).get(0);
     441                        Snode node;
     442                        ListIterator<Long> it;
     443                        for (Side side : bound.sides) {
     444                                if (side.forward) {
     445                                        node = nodes.get(side.edge.first);
     446                                        lat = node.lat;
     447                                        lon = node.lon;
     448                                        it = side.edge.nodes.listIterator();
     449                                        while (it.hasNext()) {
     450                                                llon = lon;
     451                                                llat = lat;
     452                                                node = nodes.get(it.next());
     453                                                lat = node.lat;
     454                                                lon = node.lon;
     455                                                double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
     456                                                slat += (lat * arc);
     457                                                slon += (lon * arc);
     458                                                sarc += arc;
     459                                        }
     460                                        llon = lon;
     461                                        llat = lat;
     462                                        node = nodes.get(side.edge.last);
     463                                        lat = node.lat;
     464                                        lon = node.lon;
     465                                        double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
     466                                        slat += (lat * arc);
     467                                        slon += (lon * arc);
     468                                        sarc += arc;
     469                                } else {
     470                                        node = nodes.get(side.edge.last);
     471                                        lat = node.lat;
     472                                        lon = node.lon;
     473                                        it = side.edge.nodes.listIterator(side.edge.nodes.size());
     474                                        while (it.hasPrevious()) {
     475                                                llon = lon;
     476                                                llat = lat;
     477                                                node = nodes.get(it.previous());
     478                                                lat = node.lat;
     479                                                lon = node.lon;
     480                                                double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
     481                                                slat += (lat * arc);
     482                                                slon += (lon * arc);
     483                                                sarc += arc;
     484                                        }
     485                                        llon = lon;
     486                                        llat = lat;
     487                                        node = nodes.get(side.edge.first);
     488                                        lat = node.lat;
     489                                        lon = node.lon;
     490                                        double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
     491                                        slat += (lat * arc);
     492                                        slon += (lon * arc);
     493                                        sarc += arc;
     494                                }
     495                        }
     496                        return new Snode((sarc > 0.0 ? slat/sarc : 0.0), (sarc > 0.0 ? slon/sarc : 0.0));
     497                }
     498                return null;
     499        }
     500       
    237501}
Note: See TracChangeset for help on using the changeset viewer.