Added brush grid snapping

This commit is contained in:
Mitchell McCaffrey
2020-04-20 15:17:56 +10:00
parent 6fb2e9f113
commit d4f8433bb1
6 changed files with 103 additions and 4 deletions

View File

@@ -23,3 +23,14 @@ export function fromEntries(iterable) {
export function isStreamStopped(stream) {
return stream.getTracks().reduce((a, b) => a && b, { mute: true });
}
export function roundTo(x, to) {
return Math.round(x / to) * to;
}
export function snapPositionToGrid(position, gridSize) {
return {
x: roundTo(position.x, gridSize.x),
y: roundTo(position.y, gridSize.y),
};
}