mirror of
https://github.com/streamwall/streamwall.git
synced 2026-04-14 09:42:04 -04:00
Split gridCount into independent rows and cols configs
This commit is contained in:
@@ -16,8 +16,8 @@ export interface ViewContent {
|
||||
export type ViewContentMap = Map<string, ViewContent>
|
||||
|
||||
export function boxesFromViewContentMap(
|
||||
width: number,
|
||||
height: number,
|
||||
cols: number,
|
||||
rows: number,
|
||||
viewContentMap: ViewContentMap,
|
||||
) {
|
||||
const boxes = []
|
||||
@@ -28,7 +28,7 @@ export function boxesFromViewContentMap(
|
||||
y: number,
|
||||
content: ViewContent | undefined,
|
||||
) {
|
||||
const checkIdx = width * y + x
|
||||
const checkIdx = cols * y + x
|
||||
return (
|
||||
!visited.has(checkIdx) &&
|
||||
isEqual(viewContentMap.get(String(checkIdx)), content)
|
||||
@@ -36,28 +36,28 @@ export function boxesFromViewContentMap(
|
||||
}
|
||||
|
||||
function findLargestBox(x: number, y: number) {
|
||||
const idx = width * y + x
|
||||
const idx = cols * y + x
|
||||
const spaces = [idx]
|
||||
const content = viewContentMap.get(String(idx))
|
||||
|
||||
let maxY
|
||||
for (maxY = y + 1; maxY < height; maxY++) {
|
||||
for (maxY = y + 1; maxY < rows; maxY++) {
|
||||
if (!isPosContent(x, maxY, content)) {
|
||||
break
|
||||
}
|
||||
spaces.push(width * maxY + x)
|
||||
spaces.push(cols * maxY + x)
|
||||
}
|
||||
|
||||
let cx = x
|
||||
let cy = y
|
||||
scan: for (cx = x + 1; cx < width; cx++) {
|
||||
scan: for (cx = x + 1; cx < cols; cx++) {
|
||||
for (cy = y; cy < maxY; cy++) {
|
||||
if (!isPosContent(cx, cy, content)) {
|
||||
break scan
|
||||
}
|
||||
}
|
||||
for (let cy = y; cy < maxY; cy++) {
|
||||
spaces.push(width * cy + cx)
|
||||
spaces.push(cols * cy + cx)
|
||||
}
|
||||
}
|
||||
const w = cx - x
|
||||
@@ -66,9 +66,9 @@ export function boxesFromViewContentMap(
|
||||
return { content, x, y, w, h, spaces }
|
||||
}
|
||||
|
||||
for (let y = 0; y < width; y++) {
|
||||
for (let x = 0; x < height; x++) {
|
||||
const idx = width * y + x
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
const idx = cols * y + x
|
||||
if (visited.has(idx) || viewContentMap.get(String(idx)) === undefined) {
|
||||
continue
|
||||
}
|
||||
@@ -84,21 +84,21 @@ export function boxesFromViewContentMap(
|
||||
return boxes
|
||||
}
|
||||
|
||||
export function idxToCoords(gridCount: number, idx: number) {
|
||||
const x = idx % gridCount
|
||||
const y = Math.floor(idx / gridCount)
|
||||
export function idxToCoords(cols: number, idx: number) {
|
||||
const x = idx % cols
|
||||
const y = Math.floor(idx / cols)
|
||||
return { x, y }
|
||||
}
|
||||
|
||||
export function idxInBox(
|
||||
gridCount: number,
|
||||
cols: number,
|
||||
start: number,
|
||||
end: number,
|
||||
idx: number,
|
||||
) {
|
||||
const { x: startX, y: startY } = idxToCoords(gridCount, start)
|
||||
const { x: endX, y: endY } = idxToCoords(gridCount, end)
|
||||
const { x, y } = idxToCoords(gridCount, idx)
|
||||
const { x: startX, y: startY } = idxToCoords(cols, start)
|
||||
const { x: endX, y: endY } = idxToCoords(cols, end)
|
||||
const { x, y } = idxToCoords(cols, idx)
|
||||
const lowX = Math.min(startX, endX)
|
||||
const highX = Math.max(startX, endX)
|
||||
const lowY = Math.min(startY, endY)
|
||||
|
||||
Reference in New Issue
Block a user