示例#1
0
        public double Sum(double y)
        {
            Accumulator a = new Accumulator(this);

            a.Add(y);
            return(a._s);
        }
示例#2
0
        /**
         * Add a point to the polygon or polyline.
         * <p>
         * @param lat the latitude of the point (degrees).
         * @param lon the latitude of the point (degrees).
         * <p>
         * <i>lat</i> should be in the range [&minus;90&deg;, 90&deg;].
         **********************************************************************/

        public void AddPoint(double lat, double lon)
        {
            lon = GeoMath.AngNormalize(lon);
            if (_num == 0)
            {
                _lat0 = _lat1 = lat;
                _lon0 = _lon1 = lon;
            }
            else
            {
                GeodesicData g = _earth.Inverse(_lat1, _lon1, lat, lon, _mask);
                _perimetersum.Add(g.Distance);
                if (!_polyline)
                {
                    _areasum.Add(g.GeodesicScale12);
                    _crossings += Transit(_lon1, lon);
                }
                _lat1 = lat; _lon1 = lon;
            }
            ++_num;
        }
示例#3
0
        /**
         * Return the results so far.
         * <p>
         * @param reverse if true then clockwise (instead of counter-clockwise)
         *   traversal counts as a positive area.
         * @param sign if true then return a signed result for the area if
         *   the polygon is traversed in the "wrong" direction instead of returning
         *   the area for the rest of the earth.
         * @return PolygonResult(<i>num</i>, <i>perimeter</i>, <i>area</i>) where
         *   <i>num</i> is the number of vertices, <i>perimeter</i> is the perimeter
         *   of the polygon or the length of the polyline (meters), and <i>area</i>
         *   is the area of the polygon (meters<sup>2</sup>) or Double.NaN of
         *   <i>polyline</i> is true in the constructor.
         * <p>
         * More points can be added to the polygon after this call.
         **********************************************************************/

        public PolygonResult Compute(bool reverse, bool sign)
        {
            if (_num < 2)
            {
                return(new PolygonResult(_num, 0, _polyline ? Double.NaN : 0));
            }
            if (_polyline)
            {
                return(new PolygonResult(_num, _perimetersum.Sum(), Double.NaN));
            }

            GeodesicData g       = _earth.Inverse(_lat1, _lon1, _lat0, _lon0, _mask);
            Accumulator  tempsum = new Accumulator(_areasum);

            tempsum.Add(g.GeodesicScale12);
            int crossings = _crossings + Transit(_lon1, _lon0);

            if ((crossings & 1) != 0)
            {
                tempsum.Add((tempsum.Sum() < 0 ? 1 : -1) * _area0 / 2);
            }
            // area is with the clockwise sense.  If !reverse convert to
            // counter-clockwise convention.
            if (!reverse)
            {
                tempsum.Negate();
            }
            // If sign put area in (-area0/2, area0/2], else put area in [0, area0)
            if (sign)
            {
                if (tempsum.Sum() > _area0 / 2)
                {
                    tempsum.Add(-_area0);
                }
                else if (tempsum.Sum() <= -_area0 / 2)
                {
                    tempsum.Add(+_area0);
                }
            }
            else
            {
                if (tempsum.Sum() >= _area0)
                {
                    tempsum.Add(-_area0);
                }
                else if (tempsum.Sum() < 0)
                {
                    tempsum.Add(+_area0);
                }
            }
            return
                (new PolygonResult(_num, _perimetersum.Sum(g.Distance), 0 + tempsum.Sum()));
        }