41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
|
|
import {Entity, EntityAccessor} from "../utils/entity";
|
||
|
|
import {Part} from "./part";
|
||
|
|
import {RNG} from "../utils/rng";
|
||
|
|
|
||
|
|
export type Region = Entity & {
|
||
|
|
// aligning axes of the region
|
||
|
|
axes: RegionAxis[];
|
||
|
|
|
||
|
|
// current children; expect no overlapped positions
|
||
|
|
children: EntityAccessor<Part>[];
|
||
|
|
}
|
||
|
|
|
||
|
|
export type RegionAxis = {
|
||
|
|
name: string;
|
||
|
|
min?: number;
|
||
|
|
max?: number;
|
||
|
|
align?: 'start' | 'end' | 'center';
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* for each axis, try to remove gaps in positions.
|
||
|
|
* - if min exists and align is start, and there are parts at (for example) min+2 and min+4, then move them to min and min+1
|
||
|
|
* - if max exists and align is end, and there are parts at (for example) max-2 and max-4, then move them to max-1 and max-3
|
||
|
|
* - for center, move parts to the center, possibly creating parts placed at 0.5 positions
|
||
|
|
* - sort children so that they're in ascending order on each axes.
|
||
|
|
* @param region
|
||
|
|
*/
|
||
|
|
export function applyAlign(region: Region){
|
||
|
|
for (const axis of region.axes) {
|
||
|
|
// TODO implement this
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* shuffle on each axis. for each axis, try to swap position.
|
||
|
|
* @param region
|
||
|
|
* @param rng
|
||
|
|
*/
|
||
|
|
export function shuffle(region: Region, rng: RNG){
|
||
|
|
// TODO implement this
|
||
|
|
}
|