@@ -9,6 +9,7 @@ class Path
9
9
10
10
-- Create a new Path object
11
11
new : ( path) =>
12
+ @hasCurve = false
12
13
if type ( path) == " string"
13
14
@import path
14
15
elseif type ( path) == " table"
@@ -118,12 +119,17 @@ class Path
118
119
j += 1
119
120
insert newPath, newContour
120
121
@path = newPath
122
+ @hasCurve = false
121
123
return @
122
124
123
125
-- Simplifies the number of path points
124
126
simplify : ( tolerance = 0.5 , highestQuality = true , recreateBezier = true , angleThreshold = 170 ) =>
125
127
@cleanContours !
126
- @path = Path . Simplifier ( @path , tolerance, highestQuality, recreateBezier, angleThreshold)
128
+ if @hasCurve
129
+ @flatten !
130
+ if recreateBezier
131
+ @hasCurve = true
132
+ @path = Path . Simplifier @path , tolerance, highestQuality, recreateBezier, angleThreshold
127
133
return @
128
134
129
135
-- Move the @path by specified distance
@@ -367,33 +373,17 @@ class Path
367
373
length += seg\ getLength!
368
374
return length
369
375
370
- -- Gets the normalized tangent on the Path given a time
371
376
-- Gets the normalized tangent on the Path given a time
372
377
getNormalized : ( t = 0.5 ) =>
373
- sumLength, length, newPath, tan, p, u = 0 , t * @getLength !, Path !, nil , nil , nil
374
- @callBackPath ( id, seg, k) ->
375
- path, segmentLen = {} , seg\ getLength!
376
- if newPath. path[ k] == nil
377
- newPath. path[ k] = { seg. a}
378
+ sumLength, length, tan, p, u = 0 , t * @getLength !, nil , nil , nil
379
+ @callBackPath ( id, seg) ->
380
+ segmentLen = seg\ getLength!
378
381
if sumLength + segmentLen >= length
379
382
u = ( length - sumLength) / segmentLen
380
383
tan, p, u = seg\ getNormalized u
381
- spt = seg\ split( u) [ 1 ]
382
- if id == ' l'
383
- insert newPath. path[ k] , spt. b
384
- else if id == ' b'
385
- insert newPath. path[ k] , spt. b
386
- insert newPath. path[ k] , spt. c
387
- insert newPath. path[ k] , spt. b
388
- return " break" , p, u, newPath
389
- if id == ' l'
390
- insert newPath. path[ k] , seg. b
391
- else
392
- insert newPath. path[ k] , seg. b
393
- insert newPath. path[ k] , seg. c
394
- insert newPath. path[ k] , seg. d
384
+ return " break"
395
385
sumLength += segmentLen
396
- return tan, p, u, newPath
386
+ return tan, p, u
397
387
398
388
-- Distort the Path into another Path
399
389
-- http://www.planetclegg.com/projects/WarpingTextToSplines.html
@@ -468,6 +458,8 @@ class Path
468
458
-- checks if the shape has only m, l and b commands
469
459
unless cmd\ find " [mlb]"
470
460
error " shape unknown" , 2
461
+ if cmd == " b" and not @hasCurve
462
+ @hasCurve = true
471
463
currCmd = cmd
472
464
insert path, Point tonumber ( x) , tonumber ( y) , currCmd
473
465
path[ 1 ] . id = " l"
0 commit comments