aboutsummaryrefslogtreecommitdiff
path: root/src/lib/components/widget.svelte
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2023-01-24 13:07:20 +0100
committerRuben Beltran del Rio <ruben@unlimited.pizza>2023-01-24 13:07:50 +0100
commite4e4b5202bf0039127f591941fddc1ff5ca09897 (patch)
tree0c6ad5b8784002ab2d05a14ece3d0b56fee1383f /src/lib/components/widget.svelte
parentc55cffecda48be785d89721dc8c8f04c99270b2d (diff)
Update project, improve sensor/render logic
Diffstat (limited to 'src/lib/components/widget.svelte')
-rw-r--r--src/lib/components/widget.svelte45
1 files changed, 33 insertions, 12 deletions
diff --git a/src/lib/components/widget.svelte b/src/lib/components/widget.svelte
index fd9401d..907a016 100644
--- a/src/lib/components/widget.svelte
+++ b/src/lib/components/widget.svelte
@@ -18,8 +18,8 @@
const pCanvas = modulo($topLeft.x, maxSize);
const qCanvas = modulo($topLeft.y, maxSize);
- const pBoundary = modulo($bottomRight.x, maxSize);
- const qBoundary = modulo($bottomRight.y, maxSize);
+ const pBoundary = pCanvas + Math.abs($topLeft.x - $bottomRight.x);
+ const qBoundary = qCanvas + Math.abs($topLeft.y - $bottomRight.y);
const pWidget = widget.box.left;
const qWidget = widget.box.top;
@@ -27,23 +27,44 @@
xWidget = pWidget - pCanvas;
yWidget = qWidget - qCanvas;
- if (pWidget < pCanvas &&
- pWidget < pBoundary) {
- xWidget = modulo(xWidget, maxSize);
+ // Case 1: Boundary jump happens inside the box
+ if (pWidget < pCanvas
+ && pBoundary > maxSize
+ && pWidget < pBoundary - maxSize) {
+ xWidget = xWidget + maxSize;
+ }
+ // Case 2: Boundary jump happens to the left of the box
+ else if (pWidget > pCanvas
+ && pBoundary < maxSize
+ && pWidget > pBoundary) {
+ xWidget = xWidget - maxSize;
}
- if (qWidget < qCanvas &&
- qWidget < qBoundary) {
- yWidget = modulo(yWidget, maxSize);
+ // Case 1: Boundary jump happens inside the box
+ if (qWidget < qCanvas
+ && qBoundary > maxSize
+ && qWidget < qBoundary - maxSize) {
+ yWidget = yWidget + maxSize;
+ }
+ // Case 2: Boundary jump happens above the top of the box
+ else if (qWidget > qCanvas
+ && qBoundary < maxSize
+ && qWidget > qBoundary) {
+ yWidget = yWidget - maxSize;
}
+
console.log('Max', maxSize,
'Widget Actual', widget.box.left, widget.box.top,
- 'Top Left', $topLeft.x, $topLeft.y,
- 'Mod Top Left', modulo($topLeft.x, maxSize), modulo($topLeft.y, maxSize),
+ 'Canvas WH', Math.abs($topLeft.x - $bottomRight.x), Math.abs($topLeft.y - $bottomRight.y),
+ 'Canvas XY', $topLeft.x, $topLeft.y,
+ 'Canvas PQ', pCanvas, qCanvas,
+ 'Boundary XY', $bottomRight.x, $bottomRight.y,
+ 'Boundary PQ', pBoundary, qBoundary,
+ 'Widget Rendered', xWidget, yWidget,
'Calculated',
- modulo(widget.box.left - modulo($topLeft.x, maxSize), maxSize),
- modulo(widget.box.top - modulo($topLeft.y, maxSize), maxSize))
+ modulo(pWidget - pCanvas, maxSize),
+ modulo(qWidget - qCanvas, maxSize))
}