예제 #1
0
 // Vertex Source Interface
 public void Rewind(int idx)
 {
     if (m_status == StrokeMath.status_e.initial)
     {
         m_src_vertices.close(m_closed != 0);
         ShapePath.shorten_path(m_src_vertices, m_shorten, m_closed);
         if (m_src_vertices.size() < 3)
         {
             m_closed = 0;
         }
     }
     m_status     = StrokeMath.status_e.ready;
     m_src_vertex = 0;
     m_out_vertex = 0;
 }
예제 #2
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);
				}
			}
		}
예제 #3
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;
		}
예제 #4
0
        public ShapePath.FlagsAndCommand Vertex(ref double x, ref double y)
        {
            ShapePath.FlagsAndCommand cmd = ShapePath.FlagsAndCommand.LineTo;
            while (!ShapePath.is_stop(cmd))
            {
                switch (m_status)
                {
                case StrokeMath.status_e.initial:
                    Rewind(0);
                    goto case StrokeMath.status_e.ready;

                case StrokeMath.status_e.ready:
                    if (m_src_vertices.size() < 2 + (m_closed ? 1 : 0))
                    {
                        cmd = ShapePath.FlagsAndCommand.Stop;
                        break;
                    }
                    m_status     = StrokeMath.status_e.outline1;
                    cmd          = ShapePath.FlagsAndCommand.MoveTo;
                    m_src_vertex = 0;
                    m_out_vertex = 0;
                    goto case StrokeMath.status_e.outline1;

                case StrokeMath.status_e.outline1:
                    if (m_src_vertex >= m_src_vertices.size())
                    {
                        m_status = StrokeMath.status_e.end_poly1;
                        break;
                    }
                    m_stroker.calc_join(m_out_vertices,
                                        m_src_vertices.prev(m_src_vertex),
                                        m_src_vertices.curr(m_src_vertex),
                                        m_src_vertices.next(m_src_vertex),
                                        m_src_vertices.prev(m_src_vertex).dist,
                                        m_src_vertices.curr(m_src_vertex).dist);
                    ++m_src_vertex;
                    m_status     = StrokeMath.status_e.out_vertices;
                    m_out_vertex = 0;
                    goto case StrokeMath.status_e.out_vertices;

                case StrokeMath.status_e.out_vertices:
                    if (m_out_vertex >= m_out_vertices.size())
                    {
                        m_status = StrokeMath.status_e.outline1;
                    }
                    else
                    {
                        Vector2 c = m_out_vertices[m_out_vertex++];
                        x = c.X;
                        y = c.Y;
                        return(cmd);
                    }
                    break;

                case StrokeMath.status_e.end_poly1:
                    if (!m_closed)
                    {
                        return(ShapePath.FlagsAndCommand.Stop);
                    }
                    m_status = StrokeMath.status_e.stop;
                    return(ShapePath.FlagsAndCommand.EndPoly | ShapePath.FlagsAndCommand.FlagClose | ShapePath.FlagsAndCommand.FlagCCW);

                case StrokeMath.status_e.stop:
                    return(ShapePath.FlagsAndCommand.Stop);
                }
            }
            return(cmd);
        }