1
- import points
1
+ from points import P
2
2
from math import *
3
3
import inkex
4
+ from csp import CSP , CSPsubpath
5
+ pi2 = pi * 2
4
6
5
7
################################################################################
6
8
### Biarc classes - Arc, Line and Biarc
7
9
################################################################################
8
10
class Arc ():
9
11
def __init__ (self ,st ,end ,c ,a ,r = None ) :
10
- debugger .add_debugger_to_class (self .__class__ )
12
+ # debugger.add_debugger_to_class(self.__class__)
11
13
# a - arc's angle, it's not defining actual angle before now, but defines direction so it's value does not mather matters only the sign.
12
14
if st .__class__ == P : st = st .to_list ()
13
15
if end .__class__ == P : end = end .to_list ()
@@ -28,6 +30,27 @@ def __repr__(self) :
28
30
def copy (self ) :
29
31
return Arc (self .st ,self .end ,self .c ,self .a ,self .r )
30
32
33
+ def to_csp (self ) :
34
+ # Taken from cubicsuperpath's ArcToCsp
35
+ O = self .c
36
+ sectors = int (abs (self .a )* 2 / pi )+ 1
37
+ da = self .a / sectors
38
+ v = 4 * tan (da / 4 )/ 3
39
+ angle = (self .st - self .c ).angle ()
40
+ cspsubpath = CSPsubpath ()
41
+ for i in range (sectors + 1 ) :
42
+ c ,s = cos (angle )* self .r , sin (angle )* self .r
43
+ v1 = P ([O .x + c - (- v )* s , O .y + s + (- v )* c ])
44
+ pt = P ([O .x + c , O .y + s ])
45
+ v2 = P ([O .x + c - v * s , O .y + s + v * c ])
46
+ cspsubpath .points .append ([v1 ,pt ,v2 ])
47
+ angle += da
48
+ cspsubpath .points [0 ][0 ] = cspsubpath .points [0 ][1 ].copy ()
49
+ cspsubpath .points [- 1 ][2 ] = cspsubpath .points [- 1 ][1 ].copy ()
50
+ csp = CSP ()
51
+ csp .items .append (cspsubpath )
52
+ return csp
53
+
31
54
def rebuild (self ,st = None ,end = None ,c = None ,a = None ,r = None ) :
32
55
if st == None : st = self .st
33
56
if end == None : end = self .end
@@ -59,7 +82,7 @@ def bounds(self) :
59
82
x1 ,y1 , x2 ,y2 = ( min (self .st .x ,self .end .x ),min (self .st .y ,self .end .y ),
60
83
max (self .st .x ,self .end .x ),max (self .st .y ,self .end .y ) )
61
84
# Then check 0,pi/2,pi and 2pi angles.
62
- if self .point_inside_angle (self .c + P (0 ,self .r )) :
85
+ if self .point_Gde_angle (self .c + P (0 ,self .r )) :
63
86
y2 = max (y2 , self .c .y + self .r )
64
87
if self .point_inside_angle (self .c + P (0 ,- self .r )) :
65
88
y1 = min (y1 , self .c .y - self .r )
@@ -174,7 +197,7 @@ def point_d2(self, p):
174
197
class Line ():
175
198
176
199
def __init__ (self ,st ,end ):
177
- debugger .add_debugger_to_class (self .__class__ )
200
+ # debugger.add_debugger_to_class(self.__class__)
178
201
if st .__class__ == P : st = st .to_list ()
179
202
if end .__class__ == P : end = end .to_list ()
180
203
self .st = P (st )
@@ -233,7 +256,7 @@ def draw(self, group=None, style=None, layer=None, transform=None, num = 0, reve
233
256
attr ["transform" ] = transform
234
257
inkex .etree .SubElement ( group , inkex .addNS ('path' ,'svg' ), attr )
235
258
236
- def intersect (self ,b ) :
259
+ def intersect (self ,b , false_intersection = False ) :
237
260
if b .__class__ == Line :
238
261
if self .l < 10e-8 or b .l < 10e-8 : return []
239
262
v1 = self .end - self .st
@@ -260,7 +283,7 @@ def intersect(self,b) :
260
283
t1 = ( v2 .x * (self .st .y - b .st .y ) - v2 .y * (self .st .x - b .st .x ) ) / x
261
284
t2 = ( v1 .x * (self .st .y - b .st .y ) - v1 .y * (self .st .x - b .st .x ) ) / x
262
285
263
- if 0 <= t1 <= 1 and 0 <= t2 <= 1 : return [ self .st + v1 * t1 ]
286
+ if 0 <= t1 <= 1 and 0 <= t2 <= 1 or false_intersection : return [ self .st + v1 * t1 ]
264
287
else : return []
265
288
else :
266
289
# taken from http://mathworld.wolfram.com/Circle-LineIntersection.html
@@ -277,10 +300,14 @@ def intersect(self,b) :
277
300
if descr == 0 : return self .check_intersection (b .check_intersection ([ P ([D * dy / dr + b .c .x ,- D * dx / dr + b .c .y ]) ]))
278
301
sign = - 1. if dy < 0 else 1.
279
302
descr = sqrt (descr )
280
- return self . check_intersection ( b . check_intersection ( [
281
- P ( [ (D * dy + sign * dx * descr )/ dr + b .c .x , (- D * dx + abs (dy )* descr )/ dr + b .c .y ] ),
303
+ points = [
304
+ P ( [ (D * dy + sign * dx * descr )/ dr + b .c .x , (- D * dx + abs (dy )* descr )/ dr + b .c .y ] ),
282
305
P ( [ (D * dy - sign * dx * descr )/ dr + b .c .x , (- D * dx - abs (dy )* descr )/ dr + b .c .y ] )
283
- ]))
306
+ ]
307
+ if false_intersection :
308
+ return points
309
+ else :
310
+ return self .check_intersection (b .check_intersection ( points ))
284
311
285
312
286
313
def check_intersection (self , points ):
@@ -349,7 +376,7 @@ def point_d2(self, p) :
349
376
350
377
class Biarc :
351
378
def __init__ (self , items = None ):
352
- debugger .add_debugger_to_class (self .__class__ )
379
+ # debugger.add_debugger_to_class(self.__class__)
353
380
if items == None :
354
381
self .items = []
355
382
else :
0 commit comments