Skip to content

Commit

Permalink
Added functions to reverse a path
Browse files Browse the repository at this point in the history
  • Loading branch information
Alendt committed Nov 26, 2024
1 parent 1e4fa86 commit 229f70e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion modules/ILL/ILL.moon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module_version = "1.5.1"
module_version = "1.5.2"

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

Expand Down
5 changes: 5 additions & 0 deletions modules/ILL/ILL/Ass/Shape/Curve.moon
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,9 @@ class Curve
return index / len
return (index + (targetLength - lengthBefore) / (lengths[index + 2] - lengthBefore)) / len

reverse: =>
a2, b2, c2, d2 = @a\clone!, @b\clone!, @c\clone!, @d\clone!
@a, @b, @c, @d = d2, c2, b2, a2
@a.id, @d.id = "l", "b"

{:Curve}
23 changes: 21 additions & 2 deletions modules/ILL/ILL/Ass/Shape/Path.moon
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,38 @@ class Path

-- Callback to access the Curves and Segments
callBackPath: (fn) =>
k = 1
for contour in *@path
j = 2
while j <= #contour
prev = contour[j-1]
curr = contour[j]
if curr.id == "b"
if "break" == fn "b", Curve prev, curr, contour[j+1], contour[j+2]
if "break" == fn "b", Curve(prev, curr, contour[j+1], contour[j+2]), k
return
j += 2
else
if "break" == fn "l", Segment prev, curr
if "break" == fn "l", Segment(prev, curr), k
return
j += 1
k += 1
return @

reverse: =>
reversedPath = {}
@callBackPath (id, seg, index) ->
if reversedPath[index] == nil
reversedPath[index] = {seg.a}

seg\reverse!
if id == "l"
table.insert reversedPath[index], 1, seg.a
if id == "b"
table.insert reversedPath[index], 1, seg.c
table.insert reversedPath[index], 1, seg.b
table.insert reversedPath[index], 1, seg.a

@path = reversedPath
return @

-- Gets the bounding box and other information from the Path
Expand Down
4 changes: 4 additions & 0 deletions modules/ILL/ILL/Ass/Shape/Segment.moon
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,9 @@ class Segment
d = @b\clone!
a.id, b.id, c.id, d.id = "l", "b", "b", "b"
return a, b, c, d

reverse: =>
a2, b2 = @a\clone!, @b\clone!
@a, @b = b2, a2

{:Segment}

0 comments on commit 229f70e

Please sign in to comment.