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 = modulo($bottomRight.x, maxSize);
22 const qBoundary = modulo($bottomRight.y, maxSize);
24 const pWidget = widget.box.left;
25 const qWidget = widget.box.top;
27 xWidget = pWidget - pCanvas;
28 yWidget = qWidget - qCanvas;
30 if (pWidget < pCanvas &&
31 pWidget < pBoundary) {
32 xWidget = modulo(xWidget, maxSize);
35 if (qWidget < qCanvas &&
36 qWidget < qBoundary) {
37 yWidget = modulo(yWidget, maxSize);
40 console.log('Max', maxSize,
41 'Widget Actual', widget.box.left, widget.box.top,
42 'Top Left', $topLeft.x, $topLeft.y,
43 'Mod Top Left', modulo($topLeft.x, maxSize), modulo($topLeft.y, maxSize),
45 modulo(widget.box.left - modulo($topLeft.x, maxSize), maxSize),
46 modulo(widget.box.top - modulo($topLeft.y, maxSize), maxSize))
53 style:width="{width}px"
54 style:height="{height}px"
55 style:left="{xWidget}px"
56 style:top="{yWidget}px"
64 background-color: #f0f;
65 border: 1px solid black;