Skip to content

Commit 207c165

Browse files
committed
change to suppor new vmath mat and rotate.
1 parent 5344d5f commit 207c165

File tree

11 files changed

+80
-35
lines changed

11 files changed

+80
-35
lines changed

src/pixie/contexts.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ proc scale*(ctx: Context, x, y: float32) {.inline, raises: [].} =
551551

552552
proc rotate*(ctx: Context, angle: float32) {.inline, raises: [].} =
553553
## Adds a rotation to the transformation matrix.
554-
ctx.mat = ctx.mat * rotate(-angle)
554+
ctx.mat = ctx.mat * rotate(angle)
555555

556556
proc resetTransform*(ctx: Context) {.inline, raises: [].} =
557557
## Resets the current transform to the identity matrix.

src/pixie/fileformats/svg.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ proc parseSvgProperties(node: XmlNode, inherited: SvgProperties): SvgProperties
261261
m[0, 1] = parseFloat(arr[1])
262262
m[1, 0] = parseFloat(arr[2])
263263
m[1, 1] = parseFloat(arr[3])
264-
m[2, 0] = parseFloat(arr[4])
265-
m[2, 1] = parseFloat(arr[5])
264+
m[0, 2] = parseFloat(arr[4])
265+
m[1, 2] = parseFloat(arr[5])
266266
result.transform = result.transform * m
267267
elif f.startsWith("translate("):
268268
let

src/pixie/fontformats/opentype.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,9 +2404,9 @@ proc parseCompositeGlyph(opentype: OpenType, offset: int): Path =
24042404

24052405
var subPath = opentype.parseGlyfGlyph(component.glyphId)
24062406
subPath.transform(mat3(
2407-
component.xScale, component.scale10, 0.0,
2408-
component.scale01, component.yScale, 0.0,
2409-
component.dx, component.dy, 1.0
2407+
component.xScale, component.scale10, component.dx,
2408+
component.scale01, component.yScale, component.dy,
2409+
0.0, 0.0, 1.0
24102410
))
24112411

24122412
result.addPath(subPath)

src/pixie/images.nim

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,18 +664,23 @@ proc draw*(
664664
transform = transform * scale(vec2(1/2, 1/2))
665665

666666
let
667+
translation = transform.pos
667668
hasRotationOrScaling = not(dx == vec2(1, 0) and dy == vec2(0, 1))
668669
smooth = not(
669670
dx.length == 1.0 and
670671
dy.length == 1.0 and
671-
transform[2, 0].fractional == 0.0 and
672-
transform[2, 1].fractional == 0.0
672+
translation.x.fractional == 0.0 and
673+
translation.y.fractional == 0.0
673674
)
674675

675676
if hasRotationOrScaling or smooth:
676677
a.drawSmooth(b, transform, blendMode)
677678
else:
678-
a.blendRect(b, ivec2(transform[2, 0].int32, transform[2, 1].int32), blendMode)
679+
a.blendRect(
680+
b,
681+
ivec2(translation.x.int32, translation.y.int32),
682+
blendMode
683+
)
679684

680685
proc drawTiled*(
681686
dst, src: Image, mat: Mat3, blendMode = NormalBlend

src/pixie/paths.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ proc commandsToShapes(
839839

840840
ArcParams(
841841
radii: radii,
842-
rotMat: rotate(-radians),
842+
rotMat: rotate(radians),
843843
center: center,
844844
theta: theta,
845845
delta: delta

tests/all.nim

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,4 @@ import
1212
test_ppm,
1313
test_qoi,
1414
test_svg,
15-
../examples/text,
16-
../examples/text_spans,
17-
../examples/square,
18-
../examples/line,
19-
../examples/rounded_rectangle,
20-
../examples/heart,
21-
../examples/masking,
22-
../examples/gradient,
23-
../examples/image_tiled,
24-
../examples/shadow,
25-
../examples/blur,
26-
../examples/tiger
15+
test_examples

tests/contexts/setTransform_2.png

1.63 KB
Loading

tests/test_contexts.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,18 @@ block:
201201
block:
202202
let ctx = newContext(newImage(300, 150))
203203

204-
ctx.setTransform(mat3(1, 0.2, 0, 0.8, 1, 0, 0, 0, 1))
204+
ctx.setTransform(mat3(1, 0.8, 0, 0.2, 1, 0, 0, 0, 1))
205205
ctx.fillRect(0, 0, 100, 100)
206206

207207
ctx.image.xray("tests/contexts/setTransform_1.png")
208208

209209
block:
210210
let ctx = newContext(newImage(300, 150))
211211

212-
ctx.setTransform(mat3(1, 0.2, 0, 0.8, 1, 0, 0, 0, 1))
212+
ctx.setTransform(mat3(1, 0.8, 0, 0.2, 1, 0, 0, 0, 1))
213213
ctx.fillRect(0, 0, 100, 100)
214214

215-
ctx.image.xray("tests/contexts/resetTransform_1.png")
215+
ctx.image.xray("tests/contexts/setTransform_2.png")
216216

217217
block:
218218
let ctx = newContext(newImage(300, 150))
@@ -225,7 +225,7 @@ block:
225225
block:
226226
let ctx = newContext(newImage(300, 150))
227227

228-
ctx.transform(mat3(1, 0, 0, 1.7, 1, 0, 0, 0, 1))
228+
ctx.transform(mat3(1, 1.7, 0, 0, 1, 0, 0, 0, 1))
229229
ctx.fillStyle = "gray"
230230
ctx.fillRect(40, 40, 50, 20)
231231
ctx.fillRect(40, 90, 50, 20)

tests/test_examples.nim

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import os, osproc, strformat, pixie
2+
3+
const examples = [
4+
"text",
5+
"text_spans",
6+
"square",
7+
"line",
8+
"rounded_rectangle",
9+
"heart",
10+
"masking",
11+
"gradient",
12+
"image_tiled",
13+
"shadow",
14+
"blur",
15+
"tiger"
16+
]
17+
18+
const updateThreshold = 1.0
19+
20+
let
21+
generatedDir = "tmp/generated/examples"
22+
xrayDir = "tmp/xray/examples"
23+
24+
createDir(generatedDir)
25+
createDir(xrayDir)
26+
27+
for example in examples:
28+
let
29+
nimFile = &"examples/{example}.nim"
30+
masterPath = &"examples/{example}.png"
31+
generatedPath = generatedDir / &"{example}.png"
32+
xrayPath = xrayDir / &"{example}.png"
33+
run = execCmdEx(
34+
&"nim r -d:release {nimFile} -- {generatedPath}",
35+
workingDir = getCurrentDir()
36+
)
37+
38+
if run.exitCode != 0:
39+
echo run.output
40+
raise newException(PixieError, &"Example {example} failed with exit code {run.exitCode}")
41+
42+
let
43+
generated = readImage(generatedPath)
44+
master = readImage(masterPath)
45+
(score, xray) = diff(generated, master)
46+
47+
xray.writeFile(xrayPath)
48+
echo &"xray {masterPath} -> {score:0.6f}"
49+
50+
if score > updateThreshold:
51+
copyFile(generatedPath, masterPath)

tests/test_images.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ block:
195195
a.draw(
196196
b,
197197
mat3(
198-
-0.5, -4.371138828673793e-008, 0.0,
199-
-4.371138828673793e-008, 0.5, 0.0,
200-
292.0, 45.0, 1.0
198+
-0.5, -4.371138828673793e-008, 292.0,
199+
-4.371138828673793e-008, 0.5, 45.0,
200+
0.0, 0.0, 1.0
201201
)
202202
)
203203

0 commit comments

Comments
 (0)