Skip to content

Commit 229f70e

Browse files
committed
Added functions to reverse a path
1 parent 1e4fa86 commit 229f70e

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

modules/ILL/ILL.moon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module_version = "1.5.1"
1+
module_version = "1.5.2"
22

33
haveDepCtrl, DependencyControl = pcall require, "l0.DependencyControl"
44

modules/ILL/ILL/Ass/Shape/Curve.moon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,9 @@ class Curve
200200
return index / len
201201
return (index + (targetLength - lengthBefore) / (lengths[index + 2] - lengthBefore)) / len
202202

203+
reverse: =>
204+
a2, b2, c2, d2 = @a\clone!, @b\clone!, @c\clone!, @d\clone!
205+
@a, @b, @c, @d = d2, c2, b2, a2
206+
@a.id, @d.id = "l", "b"
207+
203208
{:Curve}

modules/ILL/ILL/Ass/Shape/Path.moon

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,38 @@ class Path
4444

4545
-- Callback to access the Curves and Segments
4646
callBackPath: (fn) =>
47+
k = 1
4748
for contour in *@path
4849
j = 2
4950
while j <= #contour
5051
prev = contour[j-1]
5152
curr = contour[j]
5253
if curr.id == "b"
53-
if "break" == fn "b", Curve prev, curr, contour[j+1], contour[j+2]
54+
if "break" == fn "b", Curve(prev, curr, contour[j+1], contour[j+2]), k
5455
return
5556
j += 2
5657
else
57-
if "break" == fn "l", Segment prev, curr
58+
if "break" == fn "l", Segment(prev, curr), k
5859
return
5960
j += 1
61+
k += 1
62+
return @
63+
64+
reverse: =>
65+
reversedPath = {}
66+
@callBackPath (id, seg, index) ->
67+
if reversedPath[index] == nil
68+
reversedPath[index] = {seg.a}
69+
70+
seg\reverse!
71+
if id == "l"
72+
table.insert reversedPath[index], 1, seg.a
73+
if id == "b"
74+
table.insert reversedPath[index], 1, seg.c
75+
table.insert reversedPath[index], 1, seg.b
76+
table.insert reversedPath[index], 1, seg.a
77+
78+
@path = reversedPath
6079
return @
6180

6281
-- Gets the bounding box and other information from the Path

modules/ILL/ILL/Ass/Shape/Segment.moon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,9 @@ class Segment
6363
d = @b\clone!
6464
a.id, b.id, c.id, d.id = "l", "b", "b", "b"
6565
return a, b, c, d
66+
67+
reverse: =>
68+
a2, b2 = @a\clone!, @b\clone!
69+
@a, @b = b2, a2
6670

6771
{:Segment}

0 commit comments

Comments
 (0)