Example #1
0
        public bool IsEqual(VertexDistance val)
        {
            bool ret = (dist = agg_math.calc_distance(x, y, val.x, val.y)) > agg_math.vertex_dist_epsilon;

            if (!ret)
            {
                dist = 1.0 / agg_math.vertex_dist_epsilon;
            }
            return(ret);
        }
Example #2
0
        //-------------------------------------------------------calc_polygon_area
        public static double calc_polygon_area(VertexSequence st)
        {
            int    i;
            double sum = 0.0;
            double x   = st[0].x;
            double y   = st[0].y;
            double xs  = x;
            double ys  = y;

            for (i = 1; i < st.size(); i++)
            {
                VertexDistance v = st[i];
                sum += x * v.y - y * v.x;
                x    = v.x;
                y    = v.y;
            }
            return((sum + x * ys - y * xs) * 0.5);
        }
Example #3
0
 static public void shorten_path(VertexSequence vs, double s, int closed)
 {
     if (s > 0.0 && vs.size() > 1)
     {
         double d;
         int    n = (int)(vs.size() - 2);
         while (n != 0)
         {
             d = vs[n].dist;
             if (d > s)
             {
                 break;
             }
             vs.RemoveLast();
             s -= d;
             --n;
         }
         if (vs.size() < 2)
         {
             vs.remove_all();
         }
         else
         {
             n = (int)vs.size() - 1;
             VertexDistance prev = vs[n - 1];
             VertexDistance last = vs[n];
             d = (prev.dist - s) / prev.dist;
             double x = prev.x + (last.x - prev.x) * d;
             double y = prev.y + (last.y - prev.y) * d;
             last.x = x;
             last.y = y;
             if (!prev.IsEqual(last))
             {
                 vs.RemoveLast();
             }
             vs.close(closed != 0);
         }
     }
 }