Skip to content

Commit ee467a1

Browse files
committed
Fix bugs in Shapery module
- Fixed 'Shapery/Offsetting': Now works in a more simplified way. - Moved 'Shapery macros:/Shape without holes' to a Path class function.
1 parent 28b693e commit ee467a1

5 files changed

Lines changed: 41 additions & 43 deletions

File tree

macros/ILL.Shapery.moon

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,31 @@
11
export script_name = "Shapery"
22
export script_description = "Does several types of shape manipulations from the simplest to the most complex"
3-
export script_version = "2.6.1"
3+
export script_version = "2.6.2"
44
export script_author = "ILLTeam"
55
export script_namespace = "ILL.Shapery"
66

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

9-
local depctrl, Clipper, ILL
9+
local depctrl, ILL
1010
if haveDepCtrl
1111
depctrl = DependencyControl {
1212
feed: "https://github.com/TypesettingTools/ILL-Aegisub-Scripts/main/DependencyControl.json",
1313
{
14-
{
15-
"clipper2.clipper2"
16-
version: "1.3.2"
17-
url: "https://github.com/TypesettingTools/ILL-Aegisub-Scripts/"
18-
feed: "https://github.com/TypesettingTools/ILL-Aegisub-Scripts/main/DependencyControl.json"
19-
}
2014
{
2115
"ILL.ILL"
22-
version: "1.6.5"
16+
version: "1.8.0"
2317
url: "https://github.com/TypesettingTools/ILL-Aegisub-Scripts/"
2418
feed: "https://github.com/TypesettingTools/ILL-Aegisub-Scripts/main/DependencyControl.json"
2519
}
2620
}
2721
}
28-
Clipper, ILL = depctrl\requireModules!
22+
ILL = depctrl\requireModules!
2923
else
30-
Clipper = require "clipper2.clipper2"
3124
ILL = require "ILL.ILL"
3225

3326
{:Aegi, :Ass, :Config, :Line, :Curve, :Path, :Point, :Util, :Math, :Table, :Util} = ILL
3427
clipboard = require "aegisub.clipboard"
3528

36-
checkPathClockWise = (path) ->
37-
sum = 0
38-
for i = 1, #path
39-
currPoint = path[i]
40-
nextPoint = path[(i % #path) + 1]
41-
sum += (nextPoint.x - currPoint.x) * (nextPoint.y + currPoint.y)
42-
return sum < 0
43-
4429
interfaces = {
4530
config: -> {
4631
{class: "label", label: "Expand", x: 0, y: 0}
@@ -61,7 +46,6 @@ interfaces = {
6146
offsetting: -> {
6247
{class: "label", label: "Stroke Weight", x: 0, y: 0}
6348
{class: "floatedit", x: 1, y: 0, name: "strokeWeight", value: 0}
64-
{class: "checkbox", x: 1, y: 1, name: "cut", value: false}
6549
{class: "label", label: "Corner Style", x: 0, y: 2}
6650
{class: "dropdown", items: {"Miter", "Round", "Square"}, x: 1, y: 2, name: "cornerStyle", value: "Round"}
6751
{class: "label", label: "Align Stroke", x: 0, y: 3}
@@ -197,26 +181,39 @@ OffsettingDialog = (sub, sel, activeLine) ->
197181
if button != "Cancel"
198182
cfg = getConfigElements!
199183
ass = Ass sub, sel, activeLine, not cfg.saveLines
200-
{:strokeWeight, :strokeAlign, :cornerStyle, :miterLimit, :arcPrecision, :cut} = elements
184+
{:strokeWeight, :strokeAlign, :cornerStyle, :miterLimit, :arcPrecision} = elements
201185
if strokeWeight < 0
202186
strokeAlign = "Inside"
203187
cornerStyle = cornerStyle\lower!
204-
cutsOutside = cut and strokeAlign == "Outside"
205188
for l, s, i, n in ass\iterSel!
206189
ass\progressLine s, i, n
207190
ass\removeLine l, s
208191
Line.extend ass, l
209192
Line.callBackExpand ass, l, nil, (line) ->
210-
path, clip = Path line.shape
211-
if cutsOutside
212-
clip = path\clone!
193+
path = Path line.shape
194+
clip = path\clone!
195+
196+
line.tags\insert {{"bord", 0}}
197+
198+
if strokeAlign == "Outside"
199+
line.shape = path\export!
200+
ass\insertLine line, s
201+
213202
switch strokeAlign
214203
when "Outside" then path\offset strokeWeight, cornerStyle, "polygon", miterLimit, arcPrecision
215204
when "Center" then path\offset strokeWeight, cornerStyle, "joined", miterLimit, arcPrecision
216205
when "Inside" then path\offset -math.abs(strokeWeight), cornerStyle, "polygon", miterLimit, arcPrecision
217-
if cutsOutside
218-
path\difference clip
206+
207+
if strokeAlign == "Center" or strokeAlign == "Inside"
208+
line.shape = clip\difference(path)\export!
209+
ass\insertLine line, s
210+
211+
if strokeAlign == "Outside"
212+
line.shape = path\difference(clip)\export!
213+
214+
line.tags\insert {{"bord", 0}}, {{"c", line.data.color3}}
219215
line.shape = path\export!
216+
220217
ass\insertLine line, s
221218
return ass\getNewSelection!
222219

@@ -596,13 +593,7 @@ ShaperyMacrosDialog = (macro) ->
596593
ass\warning s, "Expected a shape"
597594
when "Shape without holes"
598595
if l.isShape
599-
newShape = Path!
600-
shapePath = Path l.shape
601-
shapePathFlattened = Path(shapePath)\flatten!
602-
for j = 1, #shapePath.path
603-
if checkPathClockWise shapePathFlattened.path[j]
604-
table.insert newShape.path, shapePath.path[j]
605-
l.shape = newShape\export!
596+
l.shape = Path(l.shape)\withoutHoles!\export!
606597
ass\setLine l, s
607598
else
608599
ass\warning s, "Expected a shape"

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.7.9"
1+
module_version = "1.8.0"
22

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

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ class Curve
9696
c.y = -1 * mt * mu2 * y1 + mu * (3 * tu - t - 2 * u) * y2 + u * (-3 * tu + 2 * t + u) * y3 + t * u2 * y4
9797
d.x = -mu3 * x1 + 3 * u * mu2 * x2 - 3 * u2 * mu * x3 + u3 * x4
9898
d.y = -mu3 * y1 + 3 * u * mu2 * y2 - 3 * u2 * mu * y3 + u3 * y4
99-
return Curve a, b, c, d
99+
curve = Curve a, b, c, d
100+
tanT, pT, tT = @getNormalized t
101+
tanU, pU, tU = @getNormalized u
102+
return curve, {t: {tangent: tanT, point: pT, time: tT}, u: {tangent: tanU, point: pU, time: tU}}
100103

101104
-- gets the cubic coefficient of the bezier segment
102105
getCoefficient: =>

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ class Path
6262

6363
-- Remove holes from Path
6464
withoutHoles: =>
65+
newPath = Path!
6566
clone = @clone!
6667
clone\flatten!
6768
for j = 1, #clone.path
68-
unless checkPathClockWise clone.path[j]
69-
remove @path, j
70-
return @
69+
if checkPathClockWise clone.path[j]
70+
insert newPath.path, @path[j]
71+
@update newPath
7172

7273
-- Maps all points on the Path
7374
map: (fn) =>
@@ -416,13 +417,13 @@ class Path
416417

417418
-- Gets the normalized tangent on the Path given a time
418419
getNormalized: (t = 0.5, returnPath) =>
419-
sumLength, length, newPath, tan, p, u = 0, t * @getLength!, Path!, nil, nil, nil
420+
sumLength, length, newPath, data = 0, t * @getLength!, Path!, nil
420421
@callBackPath (id, seg, k) ->
421422
segmentLen = seg\getLength!
422423
if newPath.path[k] == nil
423424
newPath.path[k] = {seg.a}
424425
if sumLength + segmentLen > length
425-
spt = seg\splitAtInterval (length - sumLength) / segmentLen, 1
426+
spt, data = seg\splitAtInterval (length - sumLength) / segmentLen, 1
426427
if id == "l"
427428
insert newPath.path[k], spt.b
428429
else
@@ -439,7 +440,7 @@ class Path
439440
sumLength += segmentLen
440441
if returnPath
441442
return newPath
442-
return tan, p, u, newPath
443+
return data.t.tangent, data.t.point, data.t.time, newPath
443444

444445
-- Get the Path by giving a interval
445446
getNormalizedInterval: (u, v) =>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ class Segment
4545
{:a, :b} = @
4646
p1 = a\lerp b, t
4747
p2 = a\lerp b, u
48-
return Segment p1, p2
48+
segment = Segment p1, p2
49+
tanT, pT, tT = @getNormalized t
50+
tanU, pU, tU = @getNormalized u
51+
return segment, {t: {tangent: tanT, point: pT, time: tT}, u: {tangent: tanU, point: pU, time: tU}}
4952

5053
-- gets the normalized tangent given a time on a segment
5154
getNormalized: (t, inverse) =>

0 commit comments

Comments
 (0)