working trigger editor
This commit is contained in:
1 parent
3cfb8151eb
commit
24f7c3c3af
14 files changed
+250
-66
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { Point } from "types/graphs";
|
||||
|
||||
export const offsetPoint = (
|
||||
[x, y]: Point,
|
||||
[ox, oy]: Point = [0, 0],
|
||||
): Point => [x + ox, y + oy];
|
||||
|
||||
export const avgPoints = (
|
||||
[x1, y1]: Point,
|
||||
[x2, y2]: Point,
|
||||
): Point => [(x1 + x2)/2, (y1 + y2)/2];
|
||||
|
||||
export const makeOffsetMaintainer = (startPoint: Point) => {
|
||||
let offset: Point = [0, 0];
|
||||
let i = 0;
|
||||
return {
|
||||
setI(newI: number) {
|
||||
i = newI;
|
||||
},
|
||||
resetY() {
|
||||
offset[1] = 0;
|
||||
},
|
||||
update(p: Point, innerStartLoc: Point) {
|
||||
offset[0] = Math.max(offset[0], p[0] - i - 0.5 - startPoint[0])
|
||||
offset[1] = Math.max(offset[1], p[1] - innerStartLoc[1] + 1)
|
||||
},
|
||||
get x() {
|
||||
return offset[0]
|
||||
},
|
||||
get y() {
|
||||
return offset[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IteratorWrap } from "./iter"
|
||||
import { chain, IteratorWrap } from "./iter"
|
||||
|
||||
|
||||
test('it wraps a simple iter', () => {
|
||||
@@ -23,3 +23,14 @@ test('it wraps a simple iter while being nested', () => {
|
||||
expect(data).toEqual(['2'])
|
||||
expect(wit.returnValue).toEqual(true)
|
||||
})
|
||||
|
||||
test('chain multiple iterators', () => {
|
||||
function* makeIt1() {
|
||||
yield "one"
|
||||
}
|
||||
function* makeIt2() {
|
||||
yield "two"
|
||||
}
|
||||
const data = Array.from(chain([makeIt1(), makeIt2()]));
|
||||
expect(data).toEqual(['one', 'two']);
|
||||
})
|
||||
@@ -17,3 +17,9 @@ export class IteratorWrap<T, TReturn, TNext> {
|
||||
return Array.from(this.iter())
|
||||
}
|
||||
}
|
||||
|
||||
export function* chain<T>(genArray: Generator<T>[]): Generator<T> {
|
||||
for (const gen of genArray) {
|
||||
yield * gen
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user