1
1
__precompile__ ()
2
2
module Clipper
3
+
4
+ const depsfile = joinpath (@__DIR__ , " .." , " deps" , " deps.jl" )
5
+
6
+ if isfile (depsfile)
7
+ include (depsfile)
8
+ else
9
+ error (" Clipper not build correctly. Please run Pkg.build(\" Clipper\" )" )
10
+ end
11
+
12
+ function __init__ ()
13
+ check_deps ()
14
+ end
15
+
16
+
3
17
export PolyType, PolyTypeSubject, PolyTypeClip,
4
18
ClipType, ClipTypeIntersection, ClipTypeUnion, ClipTypeDifference, ClipTypeXor,
5
19
PolyFillType, PolyFillTypeEvenOdd, PolyFillTypeNonZero, PolyFillTypePositive, PolyFillTypeNegative,
@@ -19,43 +33,36 @@ module Clipper
19
33
20
34
@enum EndType EndTypeClosedPolygon= 0 EndTypeClosedLine= 1 EndTypeOpenSquare= 2 EndTypeOpenRound= 3 EndTypeOpenButt= 4
21
35
22
- @static if is_windows ()
23
- const library_path = joinpath (dirname (@__FILE__ ), " cclipper.dll" )
24
- end
25
-
26
- @static if is_unix ()
27
- const library_path = joinpath (dirname (@__FILE__ ), " cclipper.so" )
28
- end
29
36
30
37
immutable IntPoint
31
38
X:: Int64
32
39
Y:: Int64
33
40
end
34
41
35
- type PolyNode{T}
42
+ mutable struct PolyNode{T}
36
43
contour:: Vector{T}
37
44
hole:: Bool
38
45
open:: Bool
39
46
children:: Vector{PolyNode{T}}
40
47
parent:: PolyNode{T}
41
- ( :: Type{ PolyNode{T}} ){T} (a,b,c) = new {T} (a,b,c)
42
- function ( :: Type{ PolyNode{T}} ){T} (a,b,c,d)
48
+ PolyNode {T} (a,b,c) where {T} = new {T} (a,b,c)
49
+ function PolyNode {T} (a,b,c,d) where T
43
50
p = new {T} (a,b,c,d)
44
51
p. parent = p
45
52
return p
46
53
end
47
- ( :: Type{ PolyNode{T}} ){T} (a,b,c,d,e) = new {T} (a,b,c,d,e)
54
+ PolyNode {T} (a,b,c,d,e) where {T} = new {T} (a,b,c,d,e)
48
55
end
49
56
50
- Base. convert {T} (:: Type{PolyNode{T}} , x:: PolyNode{T} ) = x
51
- function Base. convert {S,T} (:: Type{PolyNode{S}} , x:: PolyNode{T} )
57
+ Base. convert (:: Type{PolyNode{T}} , x:: PolyNode{T} ) where {T} = x
58
+ function Base. convert (:: Type{PolyNode{S}} , x:: PolyNode{T} ) where {S,T}
52
59
parent (x) != = x && error (" must convert a top-level PolyNode (i.e. a PolyTree)." )
53
60
54
61
pn = PolyNode {S} (convert (Vector{S}, contour (x)), ishole (x), isopen (x))
55
62
pn. children = [PolyNode (y,pn) for y in children (x)]
56
63
pn. parent = pn
57
64
end
58
- function PolyNode {S} (x:: PolyNode , parent:: PolyNode{S} )
65
+ function PolyNode (x:: PolyNode , parent:: PolyNode{S} ) where S
59
66
pn = PolyNode {S} (contour (x), ishole (x), isopen (x))
60
67
pn. children = [PolyNode (y,pn) for y in children (x)]
61
68
pn. parent = parent
@@ -118,19 +125,19 @@ module Clipper
118
125
# Static functions
119
126
#= =============================================================#
120
127
function orientation (path:: Vector{IntPoint} )
121
- ccall ((:orientation , library_path ), Cuchar, (Ptr{IntPoint}, Csize_t),
128
+ ccall ((:orientation , cclipper ), Cuchar, (Ptr{IntPoint}, Csize_t),
122
129
path,
123
130
length (path)) == 1 ? true : false
124
131
end
125
132
126
133
function area (path:: Vector{IntPoint} )
127
- ccall ((:area , library_path ), Float64, (Ptr{IntPoint}, Csize_t),
134
+ ccall ((:area , cclipper ), Float64, (Ptr{IntPoint}, Csize_t),
128
135
path,
129
136
length (path))
130
137
end
131
138
132
139
function pointinpolygon (pt:: IntPoint , path:: Vector{IntPoint} )
133
- ccall ((:pointinpolygon , library_path ), Cint, (IntPoint, Ptr{IntPoint}, Csize_t),
140
+ ccall ((:pointinpolygon , cclipper ), Cint, (IntPoint, Ptr{IntPoint}, Csize_t),
134
141
pt,
135
142
path,
136
143
length (path))
@@ -139,19 +146,18 @@ module Clipper
139
146
#= =============================================================#
140
147
# Clipper object
141
148
#= =============================================================#
142
- type Clip
149
+ mutable struct Clip
143
150
clipper_ptr:: Ptr{Void}
144
151
145
152
function Clip ()
146
- clipper = new (ccall ((:get_clipper , library_path), Ptr{Void}, ()))
147
- finalizer (clipper, c -> ccall ((:delete_clipper , library_path), Void, (Ptr{Void},), c. clipper_ptr))
148
-
153
+ clipper = new (ccall ((:get_clipper , cclipper), Ptr{Void}, ()))
154
+ finalizer (clipper, c -> ccall ((:delete_clipper , cclipper), Void, (Ptr{Void},), c. clipper_ptr))
149
155
clipper
150
156
end
151
157
end
152
158
153
159
function add_path! (c:: Clip , path:: Vector{IntPoint} , polyType:: PolyType , closed:: Bool )
154
- ccall ((:add_path , library_path ), Cuchar, (Ptr{Void}, Ptr{IntPoint}, Csize_t, Cint, Cuchar),
160
+ ccall ((:add_path , cclipper ), Cuchar, (Ptr{Void}, Ptr{IntPoint}, Csize_t, Cint, Cuchar),
155
161
c. clipper_ptr,
156
162
path,
157
163
length (path),
@@ -165,7 +171,7 @@ module Clipper
165
171
push! (lengths, length (path))
166
172
end
167
173
168
- ccall ((:add_paths , library_path ), Cuchar, (Ptr{Void}, Ptr{Ptr{IntPoint}}, Ptr{Csize_t}, Csize_t, Cint, Cuchar),
174
+ ccall ((:add_paths , cclipper ), Cuchar, (Ptr{Void}, Ptr{Ptr{IntPoint}}, Ptr{Csize_t}, Csize_t, Cint, Cuchar),
169
175
c. clipper_ptr,
170
176
paths,
171
177
lengths,
@@ -177,7 +183,7 @@ module Clipper
177
183
function execute (c:: Clip , clipType:: ClipType , subjFillType:: PolyFillType , clipFillType:: PolyFillType )
178
184
polys = Vector {Vector{IntPoint}} ()
179
185
180
- result = ccall ((:execute , library_path ), Cuchar, (Ptr{Void}, Cint, Cint, Cint, Any, Ptr{Void}),
186
+ result = ccall ((:execute , cclipper ), Cuchar, (Ptr{Void}, Cint, Cint, Cint, Any, Ptr{Void}),
181
187
c. clipper_ptr,
182
188
Int (clipType),
183
189
Int (subjFillType),
@@ -191,7 +197,7 @@ module Clipper
191
197
function execute_pt (c:: Clip , clipType:: ClipType , subjFillType:: PolyFillType , clipFillType:: PolyFillType )
192
198
pt = PolyNode {IntPoint} (IntPoint[], false , false , PolyNode{IntPoint}[])
193
199
194
- result = ccall ((:execute_pt , library_path ), Cuchar,
200
+ result = ccall ((:execute_pt , cclipper ), Cuchar,
195
201
(Ptr{Void}, Cint, Cint, Cint, Any, Ptr{Void}, Ptr{Void}),
196
202
c. clipper_ptr,
197
203
Int (clipType),
@@ -205,36 +211,36 @@ module Clipper
205
211
end
206
212
207
213
function clear! (c:: Clip )
208
- ccall ((:clear , library_path ), Void, (Ptr{Void},), c. clipper_ptr)
214
+ ccall ((:clear , cclipper ), Void, (Ptr{Void},), c. clipper_ptr)
209
215
end
210
216
211
- type IntRect
217
+ mutable struct IntRect
212
218
left:: Int64
213
219
top:: Int64
214
220
right:: Int64
215
221
bottom:: Int64
216
222
end
217
223
218
224
function get_bounds (c:: Clip )
219
- ccall ((:get_bounds , library_path ), IntRect, (Ptr{Void}, ), c. clipper_ptr)
225
+ ccall ((:get_bounds , cclipper ), IntRect, (Ptr{Void}, ), c. clipper_ptr)
220
226
end
221
227
222
228
#= =============================================================#
223
229
# ClipperOffset object
224
230
#= =============================================================#
225
- type ClipperOffset
231
+ mutable struct ClipperOffset
226
232
clipper_ptr:: Ptr{Void}
227
233
228
234
function ClipperOffset (miterLimit:: Float64 = 2.0 , roundPrecision:: Float64 = 0.25 )
229
- clipper = new (ccall ((:get_clipper_offset , library_path ), Ptr{Void}, (Cdouble, Cdouble), miterLimit, roundPrecision))
230
- finalizer (clipper, c -> ccall ((:delete_clipper_offset , library_path ), Void, (Ptr{Void},), c. clipper_ptr))
235
+ clipper = new (ccall ((:get_clipper_offset , cclipper ), Ptr{Void}, (Cdouble, Cdouble), miterLimit, roundPrecision))
236
+ finalizer (clipper, c -> ccall ((:delete_clipper_offset , cclipper ), Void, (Ptr{Void},), c. clipper_ptr))
231
237
232
238
clipper
233
239
end
234
240
end
235
241
236
242
function add_path! (c:: ClipperOffset , path:: Vector{IntPoint} , joinType:: JoinType , endType:: EndType )
237
- ccall ((:add_offset_path , library_path ), Void, (Ptr{Void}, Ptr{IntPoint}, Csize_t, Cint, Cint),
243
+ ccall ((:add_offset_path , cclipper ), Void, (Ptr{Void}, Ptr{IntPoint}, Csize_t, Cint, Cint),
238
244
c. clipper_ptr,
239
245
path,
240
246
length (path),
@@ -248,7 +254,7 @@ module Clipper
248
254
push! (lengths, length (path))
249
255
end
250
256
251
- ccall ((:add_offset_paths , library_path ), Void, (Ptr{Void}, Ptr{Ptr{IntPoint}}, Ptr{Csize_t}, Csize_t, Cint, Cint),
257
+ ccall ((:add_offset_paths , cclipper ), Void, (Ptr{Void}, Ptr{Ptr{IntPoint}}, Ptr{Csize_t}, Csize_t, Cint, Cint),
252
258
c. clipper_ptr,
253
259
paths,
254
260
lengths,
@@ -258,13 +264,12 @@ module Clipper
258
264
end
259
265
260
266
function clear! (c:: ClipperOffset )
261
- ccall ((:clear_offset , library_path ), Void, (Ptr{Void},), c. clipper_ptr)
267
+ ccall ((:clear_offset , cclipper ), Void, (Ptr{Void},), c. clipper_ptr)
262
268
end
263
269
264
270
function execute (c:: ClipperOffset , delta:: Float64 )
265
271
polys = Vector {Vector{IntPoint}} ()
266
-
267
- result = ccall ((:execute_offset , library_path), Void, (Ptr{Void}, Cdouble, Any, Ptr{Void}),
272
+ result = ccall ((:execute_offset , cclipper), Void, (Ptr{Void}, Cdouble, Any, Ptr{Void}),
268
273
c. clipper_ptr,
269
274
delta,
270
275
polys,
0 commit comments