-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagg_ellipse.h.html
148 lines (128 loc) · 14.8 KB
/
agg_ellipse.h.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<HTML><HEAD><TITLE>Anti-Grain Geometry - </TITLE>
<META http-equiv="Content-Type" content="text/html"/>
<LINK rel="stylesheet" type="text/css" href="../../agg.styles.css"/>
</HEAD>
<TABLE width="640px" border="0" cellspacing="0" cellpadding="0"><TR><TD><PRE><SPAN class="rem">//----------------------------------------------------------------------------</SPAN>
<SPAN class="rem">// Anti-Grain Geometry (AGG) - Version 2.5</SPAN>
<SPAN class="rem">// A high quality rendering engine for C++</SPAN>
<SPAN class="rem">// Copyright (C) 2002-2006 Maxim Shemanarev</SPAN>
<SPAN class="rem">// Contact: [email protected]</SPAN>
<SPAN class="rem">// [email protected]</SPAN>
<SPAN class="rem">// http://antigrain.com</SPAN>
<SPAN class="rem">// </SPAN>
<SPAN class="rem">// AGG is free software; you can redistribute it and/or</SPAN>
<SPAN class="rem">// modify it under the terms of the GNU General Public License</SPAN>
<SPAN class="rem">// as published by the Free Software Foundation; either version 2</SPAN>
<SPAN class="rem">// of the License, or (at your option) any later version.</SPAN>
<SPAN class="rem">// </SPAN>
<SPAN class="rem">// AGG is distributed in the hope that it will be useful,</SPAN>
<SPAN class="rem">// but WITHOUT ANY WARRANTY; without even the implied warranty of</SPAN>
<SPAN class="rem">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</SPAN>
<SPAN class="rem">// GNU General Public License for more details.</SPAN>
<SPAN class="rem">// </SPAN>
<SPAN class="rem">// You should have received a copy of the GNU General Public License</SPAN>
<SPAN class="rem">// along with AGG; if not, write to the Free Software</SPAN>
<SPAN class="rem">// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, </SPAN>
<SPAN class="rem">// MA 02110-1301, USA.</SPAN>
<SPAN class="rem">//----------------------------------------------------------------------------</SPAN>
<SPAN class="kw2">#ifndef</SPAN> AGG_ELLIPSE_INCLUDED
<SPAN class="kw2">#define</SPAN> AGG_ELLIPSE_INCLUDED
<SPAN class="kw2">#include</SPAN> <SPAN class="str">"<A href="agg_basics.h.html">agg_basics.h</A>"</SPAN>
<SPAN class="kw2">#include</SPAN> <SPAN class="op"><</SPAN>math<SPAN class="op">.</SPAN>h<SPAN class="op">></SPAN>
<SPAN class="kw1">namespace</SPAN> agg
<SPAN class="op">{</SPAN>
<SPAN class="rem">//----------------------------------------------------------------<A name="ellipse"><B></B></A><A href="agg_ellipse.h.html#ellipse">ellipse</A></SPAN>
<SPAN class="kw1">class</SPAN> <A href="agg_ellipse.h.html#ellipse">ellipse</A>
<SPAN class="op">{</SPAN>
<SPAN class="kw1">public</SPAN>:
<A href="agg_ellipse.h.html#ellipse">ellipse</A><SPAN class="op">(</SPAN><SPAN class="op">)</SPAN> :
m_x<SPAN class="op">(</SPAN><SPAN class="num">0</SPAN><SPAN class="op">.</SPAN><SPAN class="num">0</SPAN><SPAN class="op">)</SPAN><SPAN class="op">,</SPAN> m_y<SPAN class="op">(</SPAN><SPAN class="num">0</SPAN><SPAN class="op">.</SPAN><SPAN class="num">0</SPAN><SPAN class="op">)</SPAN><SPAN class="op">,</SPAN> m_rx<SPAN class="op">(</SPAN><SPAN class="num">1</SPAN><SPAN class="op">.</SPAN><SPAN class="num">0</SPAN><SPAN class="op">)</SPAN><SPAN class="op">,</SPAN> m_ry<SPAN class="op">(</SPAN><SPAN class="num">1</SPAN><SPAN class="op">.</SPAN><SPAN class="num">0</SPAN><SPAN class="op">)</SPAN><SPAN class="op">,</SPAN> m_scale<SPAN class="op">(</SPAN><SPAN class="num">1</SPAN><SPAN class="op">.</SPAN><SPAN class="num">0</SPAN><SPAN class="op">)</SPAN><SPAN class="op">,</SPAN>
m_num<SPAN class="op">(</SPAN><SPAN class="num">4</SPAN><SPAN class="op">)</SPAN><SPAN class="op">,</SPAN> m_step<SPAN class="op">(</SPAN><SPAN class="num">0</SPAN><SPAN class="op">)</SPAN><SPAN class="op">,</SPAN> m_cw<SPAN class="op">(</SPAN><SPAN class="kw1">false</SPAN><SPAN class="op">)</SPAN> <SPAN class="op">{</SPAN><SPAN class="op">}</SPAN>
<A href="agg_ellipse.h.html#ellipse">ellipse</A><SPAN class="op">(</SPAN><SPAN class="kw1">double</SPAN> x<SPAN class="op">,</SPAN> <SPAN class="kw1">double</SPAN> y<SPAN class="op">,</SPAN> <SPAN class="kw1">double</SPAN> rx<SPAN class="op">,</SPAN> <SPAN class="kw1">double</SPAN> ry<SPAN class="op">,</SPAN>
<SPAN class="kw1">unsigned</SPAN> num_steps<SPAN class="op">=</SPAN><SPAN class="num">0</SPAN><SPAN class="op">,</SPAN> <SPAN class="kw1">bool</SPAN> cw<SPAN class="op">=</SPAN><SPAN class="kw1">false</SPAN><SPAN class="op">)</SPAN> :
m_x<SPAN class="op">(</SPAN>x<SPAN class="op">)</SPAN><SPAN class="op">,</SPAN> m_y<SPAN class="op">(</SPAN>y<SPAN class="op">)</SPAN><SPAN class="op">,</SPAN> m_rx<SPAN class="op">(</SPAN>rx<SPAN class="op">)</SPAN><SPAN class="op">,</SPAN> m_ry<SPAN class="op">(</SPAN>ry<SPAN class="op">)</SPAN><SPAN class="op">,</SPAN> m_scale<SPAN class="op">(</SPAN><SPAN class="num">1</SPAN><SPAN class="op">.</SPAN><SPAN class="num">0</SPAN><SPAN class="op">)</SPAN><SPAN class="op">,</SPAN>
m_num<SPAN class="op">(</SPAN>num_steps<SPAN class="op">)</SPAN><SPAN class="op">,</SPAN> m_step<SPAN class="op">(</SPAN><SPAN class="num">0</SPAN><SPAN class="op">)</SPAN><SPAN class="op">,</SPAN> m_cw<SPAN class="op">(</SPAN>cw<SPAN class="op">)</SPAN>
<SPAN class="op">{</SPAN>
<SPAN class="kw1">if</SPAN><SPAN class="op">(</SPAN>m_num <SPAN class="op">==</SPAN> <SPAN class="num">0</SPAN><SPAN class="op">)</SPAN> calc_num_steps<SPAN class="op">(</SPAN><SPAN class="op">)</SPAN><SPAN class="op">;</SPAN>
<SPAN class="op">}</SPAN>
<SPAN class="kw1">void</SPAN> init<SPAN class="op">(</SPAN><SPAN class="kw1">double</SPAN> x<SPAN class="op">,</SPAN> <SPAN class="kw1">double</SPAN> y<SPAN class="op">,</SPAN> <SPAN class="kw1">double</SPAN> rx<SPAN class="op">,</SPAN> <SPAN class="kw1">double</SPAN> ry<SPAN class="op">,</SPAN>
<SPAN class="kw1">unsigned</SPAN> num_steps<SPAN class="op">=</SPAN><SPAN class="num">0</SPAN><SPAN class="op">,</SPAN> <SPAN class="kw1">bool</SPAN> cw<SPAN class="op">=</SPAN><SPAN class="kw1">false</SPAN><SPAN class="op">)</SPAN><SPAN class="op">;</SPAN>
<SPAN class="kw1">void</SPAN> approximation_scale<SPAN class="op">(</SPAN><SPAN class="kw1">double</SPAN> scale<SPAN class="op">)</SPAN><SPAN class="op">;</SPAN>
<SPAN class="kw1">void</SPAN> rewind<SPAN class="op">(</SPAN><SPAN class="kw1">unsigned</SPAN> path_id<SPAN class="op">)</SPAN><SPAN class="op">;</SPAN>
<SPAN class="kw1">unsigned</SPAN> vertex<SPAN class="op">(</SPAN><SPAN class="kw1">double</SPAN><SPAN class="op">*</SPAN> x<SPAN class="op">,</SPAN> <SPAN class="kw1">double</SPAN><SPAN class="op">*</SPAN> y<SPAN class="op">)</SPAN><SPAN class="op">;</SPAN>
<SPAN class="kw1">private</SPAN>:
<SPAN class="kw1">void</SPAN> calc_num_steps<SPAN class="op">(</SPAN><SPAN class="op">)</SPAN><SPAN class="op">;</SPAN>
<SPAN class="kw1">double</SPAN> m_x<SPAN class="op">;</SPAN>
<SPAN class="kw1">double</SPAN> m_y<SPAN class="op">;</SPAN>
<SPAN class="kw1">double</SPAN> m_rx<SPAN class="op">;</SPAN>
<SPAN class="kw1">double</SPAN> m_ry<SPAN class="op">;</SPAN>
<SPAN class="kw1">double</SPAN> m_scale<SPAN class="op">;</SPAN>
<SPAN class="kw1">unsigned</SPAN> m_num<SPAN class="op">;</SPAN>
<SPAN class="kw1">unsigned</SPAN> m_step<SPAN class="op">;</SPAN>
<SPAN class="kw1">bool</SPAN> m_cw<SPAN class="op">;</SPAN>
<SPAN class="op">}</SPAN><SPAN class="op">;</SPAN>
<SPAN class="rem">//------------------------------------------------------------------------</SPAN>
<SPAN class="kw1">inline</SPAN> <SPAN class="kw1">void</SPAN> ellipse::init<SPAN class="op">(</SPAN><SPAN class="kw1">double</SPAN> x<SPAN class="op">,</SPAN> <SPAN class="kw1">double</SPAN> y<SPAN class="op">,</SPAN> <SPAN class="kw1">double</SPAN> rx<SPAN class="op">,</SPAN> <SPAN class="kw1">double</SPAN> ry<SPAN class="op">,</SPAN>
<SPAN class="kw1">unsigned</SPAN> num_steps<SPAN class="op">,</SPAN> <SPAN class="kw1">bool</SPAN> cw<SPAN class="op">)</SPAN>
<SPAN class="op">{</SPAN>
m_x <SPAN class="op">=</SPAN> x<SPAN class="op">;</SPAN>
m_y <SPAN class="op">=</SPAN> y<SPAN class="op">;</SPAN>
m_rx <SPAN class="op">=</SPAN> rx<SPAN class="op">;</SPAN>
m_ry <SPAN class="op">=</SPAN> ry<SPAN class="op">;</SPAN>
m_num <SPAN class="op">=</SPAN> num_steps<SPAN class="op">;</SPAN>
m_step <SPAN class="op">=</SPAN> <SPAN class="num">0</SPAN><SPAN class="op">;</SPAN>
m_cw <SPAN class="op">=</SPAN> cw<SPAN class="op">;</SPAN>
<SPAN class="kw1">if</SPAN><SPAN class="op">(</SPAN>m_num <SPAN class="op">==</SPAN> <SPAN class="num">0</SPAN><SPAN class="op">)</SPAN> calc_num_steps<SPAN class="op">(</SPAN><SPAN class="op">)</SPAN><SPAN class="op">;</SPAN>
<SPAN class="op">}</SPAN>
<SPAN class="rem">//------------------------------------------------------------------------</SPAN>
<SPAN class="kw1">inline</SPAN> <SPAN class="kw1">void</SPAN> ellipse::approximation_scale<SPAN class="op">(</SPAN><SPAN class="kw1">double</SPAN> scale<SPAN class="op">)</SPAN>
<SPAN class="op">{</SPAN>
m_scale <SPAN class="op">=</SPAN> scale<SPAN class="op">;</SPAN>
calc_num_steps<SPAN class="op">(</SPAN><SPAN class="op">)</SPAN><SPAN class="op">;</SPAN>
<SPAN class="op">}</SPAN>
<SPAN class="rem">//------------------------------------------------------------------------</SPAN>
<SPAN class="kw1">inline</SPAN> <SPAN class="kw1">void</SPAN> ellipse::calc_num_steps<SPAN class="op">(</SPAN><SPAN class="op">)</SPAN>
<SPAN class="op">{</SPAN>
<SPAN class="kw1">double</SPAN> ra <SPAN class="op">=</SPAN> <SPAN class="op">(</SPAN>fabs<SPAN class="op">(</SPAN>m_rx<SPAN class="op">)</SPAN> <SPAN class="op">+</SPAN> fabs<SPAN class="op">(</SPAN>m_ry<SPAN class="op">)</SPAN><SPAN class="op">)</SPAN> <SPAN class="op">/</SPAN> <SPAN class="num">2</SPAN><SPAN class="op">;</SPAN>
<SPAN class="kw1">double</SPAN> da <SPAN class="op">=</SPAN> acos<SPAN class="op">(</SPAN>ra <SPAN class="op">/</SPAN> <SPAN class="op">(</SPAN>ra <SPAN class="op">+</SPAN> <SPAN class="num">0</SPAN><SPAN class="op">.</SPAN><SPAN class="num">125</SPAN> <SPAN class="op">/</SPAN> m_scale<SPAN class="op">)</SPAN><SPAN class="op">)</SPAN> <SPAN class="op">*</SPAN> <SPAN class="num">2</SPAN><SPAN class="op">;</SPAN>
m_num <SPAN class="op">=</SPAN> <A href="agg_basics.h.html#uround">uround</A><SPAN class="op">(</SPAN><SPAN class="num">2</SPAN><SPAN class="op">*</SPAN><A href="agg_basics.h.html#pi">pi</A> <SPAN class="op">/</SPAN> da<SPAN class="op">)</SPAN><SPAN class="op">;</SPAN>
<SPAN class="op">}</SPAN>
<SPAN class="rem">//------------------------------------------------------------------------</SPAN>
<SPAN class="kw1">inline</SPAN> <SPAN class="kw1">void</SPAN> ellipse::rewind<SPAN class="op">(</SPAN><SPAN class="kw1">unsigned</SPAN><SPAN class="op">)</SPAN>
<SPAN class="op">{</SPAN>
m_step <SPAN class="op">=</SPAN> <SPAN class="num">0</SPAN><SPAN class="op">;</SPAN>
<SPAN class="op">}</SPAN>
<SPAN class="rem">//------------------------------------------------------------------------</SPAN>
<SPAN class="kw1">inline</SPAN> <SPAN class="kw1">unsigned</SPAN> ellipse::vertex<SPAN class="op">(</SPAN><SPAN class="kw1">double</SPAN><SPAN class="op">*</SPAN> x<SPAN class="op">,</SPAN> <SPAN class="kw1">double</SPAN><SPAN class="op">*</SPAN> y<SPAN class="op">)</SPAN>
<SPAN class="op">{</SPAN>
<SPAN class="kw1">if</SPAN><SPAN class="op">(</SPAN>m_step <SPAN class="op">==</SPAN> m_num<SPAN class="op">)</SPAN>
<SPAN class="op">{</SPAN>
<SPAN class="op">++</SPAN>m_step<SPAN class="op">;</SPAN>
<SPAN class="kw1">return</SPAN> <A href="agg_basics.h.html#path_cmd_end_poly">path_cmd_end_poly</A> <SPAN class="op">|</SPAN> <A href="agg_basics.h.html#path_flags_close">path_flags_close</A> <SPAN class="op">|</SPAN> <A href="agg_basics.h.html#path_flags_ccw">path_flags_ccw</A><SPAN class="op">;</SPAN>
<SPAN class="op">}</SPAN>
<SPAN class="kw1">if</SPAN><SPAN class="op">(</SPAN>m_step <SPAN class="op">></SPAN> m_num<SPAN class="op">)</SPAN> <SPAN class="kw1">return</SPAN> <A href="agg_basics.h.html#path_cmd_stop">path_cmd_stop</A><SPAN class="op">;</SPAN>
<SPAN class="kw1">double</SPAN> angle <SPAN class="op">=</SPAN> <SPAN class="kw1">double</SPAN><SPAN class="op">(</SPAN>m_step<SPAN class="op">)</SPAN> <SPAN class="op">/</SPAN> <SPAN class="kw1">double</SPAN><SPAN class="op">(</SPAN>m_num<SPAN class="op">)</SPAN> <SPAN class="op">*</SPAN> <SPAN class="num">2</SPAN><SPAN class="op">.</SPAN><SPAN class="num">0</SPAN> <SPAN class="op">*</SPAN> <A href="agg_basics.h.html#pi">pi</A><SPAN class="op">;</SPAN>
<SPAN class="kw1">if</SPAN><SPAN class="op">(</SPAN>m_cw<SPAN class="op">)</SPAN> angle <SPAN class="op">=</SPAN> <SPAN class="num">2</SPAN><SPAN class="op">.</SPAN><SPAN class="num">0</SPAN> <SPAN class="op">*</SPAN> <A href="agg_basics.h.html#pi">pi</A> <SPAN class="op">-</SPAN> angle<SPAN class="op">;</SPAN>
<SPAN class="op">*</SPAN>x <SPAN class="op">=</SPAN> m_x <SPAN class="op">+</SPAN> cos<SPAN class="op">(</SPAN>angle<SPAN class="op">)</SPAN> <SPAN class="op">*</SPAN> m_rx<SPAN class="op">;</SPAN>
<SPAN class="op">*</SPAN>y <SPAN class="op">=</SPAN> m_y <SPAN class="op">+</SPAN> sin<SPAN class="op">(</SPAN>angle<SPAN class="op">)</SPAN> <SPAN class="op">*</SPAN> m_ry<SPAN class="op">;</SPAN>
m_step<SPAN class="op">++</SPAN><SPAN class="op">;</SPAN>
<SPAN class="kw1">return</SPAN> <SPAN class="op">(</SPAN><SPAN class="op">(</SPAN>m_step <SPAN class="op">==</SPAN> <SPAN class="num">1</SPAN><SPAN class="op">)</SPAN> ? <A href="agg_basics.h.html#path_cmd_move_to">path_cmd_move_to</A> : <A href="agg_basics.h.html#path_cmd_line_to">path_cmd_line_to</A><SPAN class="op">)</SPAN><SPAN class="op">;</SPAN>
<SPAN class="op">}</SPAN>
<SPAN class="op">}</SPAN>
<SPAN class="kw2">#endif</SPAN>
</PRE></TD></TR></TABLE><FONT style="margin-left:1em"><I></I></FONT><TABLE width="640px" bgcolor="#583927" height="1px" border="0" cellspacing="0" cellpadding="0" style="margin:0px;"><TR><TD></TD></TR></TABLE>
<TABLE width="640px" border="0" cellspacing="0" cellpadding="0">
<TR><TD><CENTER><SPAN class="authors">
Copyright <SPAN class="larger">©</SPAN> 2002-2006
<A href="../../mcseem/index.html"><B>Maxim Shemanarev</B></A>
</SPAN></CENTER></TD></TR>
<TR><TD><CENTER><SPAN class="authors">
Web Design and Programming
<A href="../../mcseem/index.html"><B>Maxim Shemanarev</B></A>
</SPAN></CENTER></TD></TR>
</TABLE>
<BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/>
<BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/>
<BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/>
<BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/><BR/>
</HTML>