aboutsummaryrefslogtreecommitdiff
path: root/upstream/clipper-6.4.2/Documentation/Docs/Overview/Example.htm
blob: ded5dd5c2d5403529661d465a718a434985116cb (plain)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<html>

<head>
    
  <script type="text/javascript" src="../../Scripts/jquery.js">
  </script>
    
  <script type="text/javascript" src="../../Scripts/SyntaxHighlighter/scripts/shCore.js">
  </script>
    
  <script type="text/javascript" src="../../Scripts/SyntaxHighlighter/scripts/shBrushDelphi.js">
  </script>
    
  <script type="text/javascript" src="../../Scripts/SyntaxHighlighter/scripts/shBrushCpp.js">
  </script>
    
  <script type="text/javascript" src="../../Scripts/SyntaxHighlighter/scripts/shBrushCSharp.js">
  </script>
    
  <link type="text/css" rel="stylesheet" href="../../Scripts/SyntaxHighlighter/styles/shCoreDefault.css">
    
  <link type="text/css" rel="stylesheet" href="../../Scripts/SyntaxHighlighter/styles/shThemeDefault.css">
  

  <title>Example</title>  

  <link rel="stylesheet" href="../../Styles/default.css" type="text/css">

    
  <script type="text/javascript" src="../../Scripts/bootstrap.js">
  </script>
  
</head>

<body bgcolor="#FFFFFF">
    
  <!-- THIS FILE HAS BEEN AUTOMATICALLY PROCESSED FROM A SOURCE COPY -->
    
  <!-- DO NOT EDIT MANUALLY !!! -->
  
  <table class="Banner" cellspacing="0" cellpadding="0" border="1" bordercolorlight="#303080" bordercolordark="#7070B0">
    <tr>
      <td class="Banner" nowrap=""><a href="../_Body.htm" class="Banner"><img src="../../Images/_Home.gif" align="absmiddle">Home</a>
      </td>
      <td class="Banner" nowrap=""><a href="_Body.htm" class="Banner">Overview</a>
      </td>
      <td class="Banner" width="100%" align="right"><img src="../../Images/_Project_Logo.gif" align="absmiddle">
      </td>
    </tr>
  </table>
  <h1>Example</h1>

  
  <table cellspacing="0" cellpadding="0" border="0" align="left" style="margin: 0;" width="600px">
  <th align="left">Delphi Code Sample:
    </th>
  
    <tr>
      <td class="White">
  
        <pre class="brush: delphi;">
  uses
    graphics32, clipper;
  
  function GetEllipsePoints(bounds: TIntRect): TPath;
  begin
    //code to create an elliptical polygon here
  end;
	
  procedure DrawPolygons(polys: TPaths; color: TColor32);
  begin
    //code to display the polygons here
  end;
	
  var
    sub, clp, sol: TPaths;
  begin

    //set up the subject and clip polygons ...
    setlength(sub, 3);
    sub[0] := GetEllipsePoints(IntRect(100,100,300,300));
    sub[1] := GetEllipsePoints(IntRect(125,130,275,180));
    sub[2] := GetEllipsePoints(IntRect(125,220,275,270));
	
    setlength(clp, 1);
    clp[0] := GetEllipsePoints(IntRect(140,70,220,320));

    //display the subject and clip polygons ...
    DrawPolygons(sub, 0x8033FFFF);
    DrawPolygons(clp, 0x80FFFF33);
    
    //get the intersection of the subject and clip polygons ...
    with TClipper.Create do
    try
      AddPaths(sub, ptSubject, true);
      AddPaths(clp, ptClip, true);
      Execute(ctIntersection, sol, pftEvenOdd, pftEvenOdd);
    finally
      free;
    end;
    
    //finally draw the intersection polygons ...
    DrawPolygons(sol, 0x40808080);
        </pre>
  
      </td>
    </tr>
  
  </table>
  <div style="clear:both">&nbsp;</div>
      
  
  
  <table cellspacing="0" cellpadding="0" border="0" align="left" style="margin: 0;" width="600px">
  <th align="left">C++ Code Sample:
    </th>
  
    <tr>
      <td class="White">
  
        <pre class="brush: cpp;">
  #include "clipper.hpp"
  
  ...

  //from clipper.hpp ...
  //typedef long long cInt;
  //struct IntPoint {cInt X; cInt Y;};
  //typedef std::vector&lt;IntPoint&gt; Path;
  //typedef std::vector&lt;Polygon&gt; Paths;

  using namespace ClipperLib;

  void GetEllipsePoints(IntRect& bounds, Path& p)
  {/* ... */}
  
  void DrawPolygons(Paths& p, unsigned color)
  {/* ... */}
  
  int main()
  {
    //set up the subject and clip polygons ...
    Paths sub(3);
    GetEllipsePoints(IntRect(100,100,300,300), sub[0]);
    GetEllipsePoints(IntRect(125,130,275,180), sub[1]);
    GetEllipsePoints(IntRect(125,220,275,270), sub[2]);
    
    Paths clp(1);
    GetEllipsePoints(IntRect(140,70,220,320), clp[0]);
    
    //display the subject and clip polygons ...
    DrawPolygons(sub, 0x8033FFFF);
    DrawPolygons(clp, 0x80FFFF33);
    
    //get the intersection of the subject and clip polygons ...
    Clipper clpr;
    clpr.AddPaths(sub, ptSubject, true);
    clpr.AddPaths(clp, ptClip, true);
    Paths solution;
    clpr.Execute(ctIntersection, solution, pftEvenOdd, pftEvenOdd);
    
    //finally draw the intersection polygons ...
    DrawPolygons(solution, 0x40808080);
  }
        </pre>
		
  
      </td>
    </tr>
  
  </table>
  <div style="clear:both">&nbsp;</div>
     
  
  <table cellspacing="0" cellpadding="0" border="0" align="left" style="margin: 0;" width="600px">
  <th align="left">C# Code Sample:
    </th>
  
    <tr>
      <td class="White">
  
        <pre class="brush: csharp;">
  ...
  using ClipperLib;
	
  ...
  using Path = List&lt;IntPoint&gt;;
  using Paths = List&lt;List&lt;IntPoint&gt;&gt;;
  
  static Path GetEllipsePoints(IntRect bounds)
  {/* ... */}
  
  static void DrawPolygons(Path p, uint color)
  {/* ... */}
  
  static void Main(string[] args)
  {
    Paths subjs = new Paths(3);
    subjs.Add(GetEllipsePoints(new IntRect(100,100,300,300)));
    subjs.Add(GetEllipsePoints(new IntRect(125,130,275,180)));
    subjs.Add(GetEllipsePoints(new IntRect(125,220,275,270)));
    
    Paths clips = new Paths(1);
    clips.Add(GetEllipsePoints(new IntRect(140,70,220,320)));
    
    DrawPolygons(subjs, 0x8033FFFF);
    DrawPolygons(clips, 0x80FFFF33);
    
    Paths solution = new Paths();
    Clipper c = new Clipper();
    c.AddPaths(subjs, PolyType.ptSubject, true);
    c.AddPaths(clips, PolyType.ptClip, true);
    c.Execute(ClipType.ctIntersection, solution);
    
    DrawPolygons(solution, 0x40808080);
  }
        </pre>
  
      </td>
    </tr>
  
  </table>

  <div style="clear:both">&nbsp;</div>
  <img src="../../Images/sample1.png" alt="" border="0">
  
  
    
  <p class="Copyright" id="auto"> <br><br> Copyright &copy;2010-2014 Angus Johnson&nbsp; - &nbsp; Clipper 6.2.1 &nbsp; - &nbsp; Help file built on 1-November-2014 <br><br> </p>
  
</body>


</html>