Skip to content

Commit 8efc548

Browse files
authored
feat: Resize and rotation (#14)
* add ui to transform an asset * trying to make transofrmation work wtiout matricies * introduce matricies * update tests * mainy fixed typos and update test to use new parameters
1 parent ac0d8e4 commit 8efc548

33 files changed

+884
-134
lines changed

ADRs/points vs matrix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
I have two options how assets(positon/scale/rotation) can stored.
2+
a) four points, each represents one corner
3+
b) width, height + 3x3 matrix
4+
5+
Seems like matrix could simplify a lot of transformations but at the same time
6+
I need to store points wit UV coordinates anyway.
7+
8+
Thats why for now I are going to stick with storing assets in a from of four points, each point is x,y,u,v.
9+
For transformations like scaling, rotations I are going to use matricies.
10+
For transition is not useful since it's super easy to just add cursor position to points.

ADRs/y-axis coords

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
I've decided to stay with mathematically correct y axis(growing up).
2+
3+
Using popular method of coordinates for screens is y axis growing down. It introduces a lot of noise and
4+
missunderstanding into calculating, especially those angle related.
5+
6+
Also we do flip the textures while loading to be sure that
7+
(0,0) is bottom left corner, (1,1) is top right corner so we operate in correct cartesian space.

integration-tests/index.ts

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,49 @@
11
import initCreator from '../src/index'
2-
// import SampleImg from './image-sample.png'
2+
import SampleImg from './image-sample.png'
33

4-
let new_asset_id = 1000
4+
let new_asset_id = 1001
5+
6+
const params = new URLSearchParams(document.location.search)
7+
const isSampleParam = params.has('sample') // is the string "Jonathan"
58

69
async function test() {
710
const canvas = document.querySelector<HTMLCanvasElement>('canvas')!
811
const creator = await initCreator(
912
canvas,
10-
[
11-
// {
12-
// id: 1000,
13-
// points: [
14-
// { x: 84.5, y: 71.5, u: 0, v: 0 },
15-
// { x: 688.5, y: 71.5, u: 1, v: 0 },
16-
// { x: 688.5, y: 675.5, u: 1, v: 1 },
17-
// { x: 84.5, y: 675.5, u: 0, v: 1 },
18-
// ],
19-
// url: SampleImg,
20-
// },
21-
],
13+
isSampleParam
14+
? [
15+
{
16+
id: 1000,
17+
points: [
18+
{
19+
u: 0,
20+
v: 1,
21+
x: 106.5999984741211,
22+
y: 693.9000244140625,
23+
},
24+
{
25+
u: 1,
26+
v: 1,
27+
x: 723.4000244140625,
28+
y: 693.9000244140625,
29+
},
30+
{
31+
u: 1,
32+
v: 0,
33+
x: 723.4000244140625,
34+
y: 77.0999984741211,
35+
},
36+
{
37+
u: 0,
38+
v: 0,
39+
x: 106.5999984741211,
40+
y: 77.0999984741211,
41+
},
42+
],
43+
url: SampleImg,
44+
},
45+
]
46+
: [],
2247
console.log
2348
)
2449

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
21
import { test, expect } from '@playwright/test'
32
import path from 'path'
4-
import { fileURLToPath } from "url"
3+
import { fileURLToPath } from 'url'
54

65
const __dirname = path.dirname(fileURLToPath(import.meta.url))
76
const PAGE_WIDTH = 1000
87
const PAGE_HEIGHT = 700
8+
const center = { x: PAGE_WIDTH / 2, y: PAGE_HEIGHT / 2 }
99

1010
test('visible image after upload', async ({ page }, testinfo) => {
1111
if (process.env.CI) {
@@ -24,30 +24,61 @@ test('visible image after upload', async ({ page }, testinfo) => {
2424

2525
await page.setViewportSize({ width: PAGE_WIDTH, height: PAGE_HEIGHT })
2626
await page.goto('/')
27-
await page.waitForLoadState("networkidle")
27+
await page.waitForLoadState('networkidle')
28+
await page.evaluate(() =>
29+
window.addEventListener('mousemove', (e) => console.log(e.clientX, e.clientY))
30+
) // to display cursor position during debugging
31+
// helps to copy position here
2832

2933
/** =========PNG IMAGE UPLOAD============ */
3034
const fileInput = page.locator('input[type="file"]')
3135
const testImagePath = path.join(__dirname, '../image-sample.png')
3236
await fileInput.setInputFiles(testImagePath)
3337

3438
const canvas = page.locator('canvas')
35-
await expect(canvas).toHaveScreenshot('after-upload.png')
39+
await expect(canvas).toHaveScreenshot('upload-image.png')
3640

3741
/** =========DISPLAYS BORDER AROUND HOVERED ASSET============ */
38-
const center = { x: PAGE_WIDTH / 2, y: PAGE_HEIGHT / 2 }
3942
await page.mouse.move(center.x, center.y)
40-
await expect(canvas).toHaveScreenshot('after-hover.png')
43+
await expect(canvas).toHaveScreenshot('hover-image.png')
4144

4245
/** =========IMAGE SELECTED============ */
4346
await page.mouse.click(center.x, center.y)
44-
await expect(canvas).toHaveScreenshot('after-selection.png')
47+
await expect(canvas).toHaveScreenshot('select-image.png')
4548

46-
/** =========IMAGES POSITION UPDATES============ */
49+
/** =========IMAGE POSITION UPDATES============ */
4750
await page.mouse.down()
48-
await page.mouse.move(300, 200)
51+
await page.mouse.move(300, 300)
4952
await page.mouse.up()
50-
await expect(canvas).toHaveScreenshot('after-move.png')
51-
})
53+
await expect(canvas).toHaveScreenshot('move-image.png')
5254

55+
/** =========ROTATION UI HOVER============ */
56+
await page.mouse.move(340, 640)
57+
await expect(canvas).toHaveScreenshot('hover-rotation-ui.png')
5358

59+
/** =========IMAGE ROTATION UPDATES============ */
60+
await page.mouse.down()
61+
await page.mouse.move(573, 533)
62+
await page.mouse.up()
63+
await expect(canvas).toHaveScreenshot('rotate-image.png')
64+
65+
/** =========TOP SCALE HOVER============ */
66+
await page.mouse.move(156, 95)
67+
await expect(canvas).toHaveScreenshot('hover-top-scale-ui.png')
68+
69+
/** =========TOP SCALE USAGE============ */
70+
await page.mouse.down()
71+
await page.mouse.move(320, 264)
72+
await page.mouse.up()
73+
await expect(canvas).toHaveScreenshot('use-top-scale-ui.png')
74+
75+
/** =========TOP LEFT SCALE HOVER============ */
76+
await page.mouse.move(168, 410)
77+
await expect(canvas).toHaveScreenshot('hover-top-left-scale-ui.png')
78+
79+
/** =========TOP LEFT SCALE USAGE============ */
80+
await page.mouse.down()
81+
await page.mouse.move(950, 400)
82+
await page.mouse.up()
83+
await expect(canvas).toHaveScreenshot('use-top-left-scale-ui.png')
84+
})
Binary file not shown.
Binary file not shown.
Binary file not shown.
310 KB
Loading
310 KB
Loading
220 KB
Loading

0 commit comments

Comments
 (0)