From 229f70eaa2e290f473f2b7106e67989723dd6af6 Mon Sep 17 00:00:00 2001 From: Alendt Date: Tue, 26 Nov 2024 17:40:32 +0100 Subject: [PATCH] Added functions to reverse a path --- modules/ILL/ILL.moon | 2 +- modules/ILL/ILL/Ass/Shape/Curve.moon | 5 +++++ modules/ILL/ILL/Ass/Shape/Path.moon | 23 +++++++++++++++++++++-- modules/ILL/ILL/Ass/Shape/Segment.moon | 4 ++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/modules/ILL/ILL.moon b/modules/ILL/ILL.moon index 4170638..66ae698 100644 --- a/modules/ILL/ILL.moon +++ b/modules/ILL/ILL.moon @@ -1,4 +1,4 @@ -module_version = "1.5.1" +module_version = "1.5.2" haveDepCtrl, DependencyControl = pcall require, "l0.DependencyControl" diff --git a/modules/ILL/ILL/Ass/Shape/Curve.moon b/modules/ILL/ILL/Ass/Shape/Curve.moon index f8959ec..b1d9a29 100644 --- a/modules/ILL/ILL/Ass/Shape/Curve.moon +++ b/modules/ILL/ILL/Ass/Shape/Curve.moon @@ -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} \ No newline at end of file diff --git a/modules/ILL/ILL/Ass/Shape/Path.moon b/modules/ILL/ILL/Ass/Shape/Path.moon index e960643..ee7239d 100644 --- a/modules/ILL/ILL/Ass/Shape/Path.moon +++ b/modules/ILL/ILL/Ass/Shape/Path.moon @@ -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 diff --git a/modules/ILL/ILL/Ass/Shape/Segment.moon b/modules/ILL/ILL/Ass/Shape/Segment.moon index 6cb5725..dedf1bb 100644 --- a/modules/ILL/ILL/Ass/Shape/Segment.moon +++ b/modules/ILL/ILL/Ass/Shape/Segment.moon @@ -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} \ No newline at end of file