2 import { bottomRight, topLeft } from '$lib/stores/canvas';
3 import { modulo } from '$lib/math';
4 import { maxSize } from '$lib/config';
7 const width = widget.box.right - widget.box.left;
8 const height = widget.box.bottom - widget.box.top;
10 // Coordinates in canvas space are (p,q)
11 // Coordinates in screen space are (x,y)
18 const pCanvas = modulo($topLeft.x, maxSize);
19 const qCanvas = modulo($topLeft.y, maxSize);
21 const pBoundary = pCanvas + Math.abs($topLeft.x - $bottomRight.x);
22 const qBoundary = qCanvas + Math.abs($topLeft.y - $bottomRight.y);
24 const pWidget = widget.box.left;
25 const qWidget = widget.box.top;
27 xWidget = pWidget - pCanvas;
28 yWidget = qWidget - qCanvas;
30 // Case 1: Boundary jump happens inside the box
32 && pBoundary > maxSize
33 && pWidget < pBoundary - maxSize) {
34 xWidget = xWidget + maxSize;
36 // Case 2: Boundary jump happens to the left of the box
37 else if (pWidget > pCanvas
38 && pBoundary < maxSize
39 && pWidget > pBoundary) {
40 xWidget = xWidget - maxSize;
43 // Case 1: Boundary jump happens inside the box
45 && qBoundary > maxSize
46 && qWidget < qBoundary - maxSize) {
47 yWidget = yWidget + maxSize;
49 // Case 2: Boundary jump happens above the top of the box
50 else if (qWidget > qCanvas
51 && qBoundary < maxSize
52 && qWidget > qBoundary) {
53 yWidget = yWidget - maxSize;
57 console.log('Max', maxSize,
58 'Widget Actual', widget.box.left, widget.box.top,
59 'Canvas WH', Math.abs($topLeft.x - $bottomRight.x), Math.abs($topLeft.y - $bottomRight.y),
60 'Canvas XY', $topLeft.x, $topLeft.y,
61 'Canvas PQ', pCanvas, qCanvas,
62 'Boundary XY', $bottomRight.x, $bottomRight.y,
63 'Boundary PQ', pBoundary, qBoundary,
64 'Widget Rendered', xWidget, yWidget,
66 modulo(pWidget - pCanvas, maxSize),
67 modulo(qWidget - qCanvas, maxSize))
74 style:width="{width}px"
75 style:height="{height}px"
76 style:left="{xWidget}px"
77 style:top="{yWidget}px"
85 background-color: #f0f;
86 border: 1px solid black;