1//----------------------------------------------------------------------------
2// Anti-Grain Geometry - Version 2.4
3// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4//
5// Permission to copy, use, modify, sell and distribute this software
6// is granted provided this copyright notice appears in all copies.
7// This software is provided "as is" without express or implied
8// warranty, and with no claim as to its suitability for any purpose.
9//
10//----------------------------------------------------------------------------
11// Contact: mcseem@antigrain.com
12//          mcseemagg@yahoo.com
13//          http://www.antigrain.com
14//----------------------------------------------------------------------------
15//
16// Simple arrowhead/arrowtail generator
17//
18//----------------------------------------------------------------------------
19
20#include "agg_arrowhead.h"
21
22namespace agg
23{
24
25    //------------------------------------------------------------------------
26    arrowhead::arrowhead() :
27        m_head_d1(1.0),
28        m_head_d2(1.0),
29        m_head_d3(1.0),
30        m_head_d4(0.0),
31        m_tail_d1(1.0),
32        m_tail_d2(1.0),
33        m_tail_d3(1.0),
34        m_tail_d4(0.0),
35        m_head_flag(false),
36        m_tail_flag(false),
37        m_curr_id(0),
38        m_curr_coord(0)
39    {
40    }
41
42
43
44    //------------------------------------------------------------------------
45    void arrowhead::rewind(unsigned path_id)
46    {
47        m_curr_id = path_id;
48        m_curr_coord = 0;
49        if(path_id == 0)
50        {
51            if(!m_tail_flag)
52            {
53                m_cmd[0] = path_cmd_stop;
54                return;
55            }
56            m_coord[0]  =  m_tail_d1;             m_coord[1]  =  0.0;
57            m_coord[2]  =  m_tail_d1 - m_tail_d4; m_coord[3]  =  m_tail_d3;
58            m_coord[4]  = -m_tail_d2 - m_tail_d4; m_coord[5]  =  m_tail_d3;
59            m_coord[6]  = -m_tail_d2;             m_coord[7]  =  0.0;
60            m_coord[8]  = -m_tail_d2 - m_tail_d4; m_coord[9]  = -m_tail_d3;
61            m_coord[10] =  m_tail_d1 - m_tail_d4; m_coord[11] = -m_tail_d3;
62
63            m_cmd[0] = path_cmd_move_to;
64            m_cmd[1] = path_cmd_line_to;
65            m_cmd[2] = path_cmd_line_to;
66            m_cmd[3] = path_cmd_line_to;
67            m_cmd[4] = path_cmd_line_to;
68            m_cmd[5] = path_cmd_line_to;
69            m_cmd[7] = path_cmd_end_poly | path_flags_close | path_flags_ccw;
70            m_cmd[6] = path_cmd_stop;
71            return;
72        }
73
74        if(path_id == 1)
75        {
76            if(!m_head_flag)
77            {
78                m_cmd[0] = path_cmd_stop;
79                return;
80            }
81            m_coord[0]  = -m_head_d1;            m_coord[1]  = 0.0;
82            m_coord[2]  = m_head_d2 + m_head_d4; m_coord[3]  = -m_head_d3;
83            m_coord[4]  = m_head_d2;             m_coord[5]  = 0.0;
84            m_coord[6]  = m_head_d2 + m_head_d4; m_coord[7]  = m_head_d3;
85
86            m_cmd[0] = path_cmd_move_to;
87            m_cmd[1] = path_cmd_line_to;
88            m_cmd[2] = path_cmd_line_to;
89            m_cmd[3] = path_cmd_line_to;
90            m_cmd[4] = path_cmd_end_poly | path_flags_close | path_flags_ccw;
91            m_cmd[5] = path_cmd_stop;
92            return;
93        }
94    }
95
96
97    //------------------------------------------------------------------------
98    unsigned arrowhead::vertex(double* x, double* y)
99    {
100        if(m_curr_id < 2)
101        {
102            unsigned curr_idx = m_curr_coord * 2;
103            *x = m_coord[curr_idx];
104            *y = m_coord[curr_idx + 1];
105            return m_cmd[m_curr_coord++];
106        }
107        return path_cmd_stop;
108    }
109
110}
111