Skip to content

Commit

Permalink
Merge branch 'feature/256-enum-refactor' into develop
Browse files Browse the repository at this point in the history
* feature/256-enum-refactor:
  docs(color): update gradient preview gen
  docs: update readmes
  refactor(hdom-canvas): update DiffMode handling
  refactor(hdom): update DiffMode handling
  refactor(hdiff): update DiffMode handling
  refactor(diff): fix #256 replace DiffMode enum
  refactor(transducers-patch): fix #256 replace enum
  refactor(geom): fix #256 replace Type enum w/ alias
  refactor(geom-api): fix #256 remove Type enum
  refactor(examples): update GestureType usage
  refactor(geom): fix #256 replace enum w/ type alias
  refactor(geom-api): fix #256 replace enum w/ type alias
  refactor(transducers-binary): fix #256 replace enum w/ type alias
  refactor(rstream-gestures): fix #256 replace GestureType enum
  refactor(pointfree-lang): fix #256 replace enum w/ type alias
  fix(math): fix #256 replace enum w/ type alias
  refactor(gp): fix #256 replace enum w/ type alias
  refactor(adjacency): fix #256 replace enums w/ type aliases
  refactor(color): fix #256 replace enum w/ type alias
  refactor(adjacency): fix #256 replace enum w/ type alias
  • Loading branch information
postspectacular committed Dec 22, 2020
2 parents c541afc + 3866563 commit bda4f75
Show file tree
Hide file tree
Showing 121 changed files with 1,054 additions and 1,262 deletions.
11 changes: 2 additions & 9 deletions examples/canvas-dial/src/dial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { isString } from "@thi.ng/checks";
import { canvas2D } from "@thi.ng/hdom-components";
import { fitClamped } from "@thi.ng/math";
import type { Subscription } from "@thi.ng/rstream";
import {
GestureEvent,
gestureStream,
GestureType,
} from "@thi.ng/rstream-gestures";
import { GestureEvent, gestureStream } from "@thi.ng/rstream-gestures";
import { heading, sub2 } from "@thi.ng/vectors";

/**
Expand Down Expand Up @@ -190,10 +186,7 @@ export const dial = (_opts: Partial<DialOpts>) => {
// configure stream to return scaled coords (devicePixelRatio)
events = gestureStream(el, { scale: true }).subscribe({
next: (e) => {
if (
e.type === GestureType.START ||
e.type === GestureType.DRAG
) {
if (e.type === "start" || e.type === "drag") {
let theta =
heading(sub2([], e.pos, [cx, cy])) - startTheta;
if (theta < 0) theta += TAU;
Expand Down
14 changes: 4 additions & 10 deletions examples/gesture-analysis/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { identity } from "@thi.ng/compose";
import { polyline as gPolyline, resample, vertices } from "@thi.ng/geom";
import { circle, group, polyline, svg } from "@thi.ng/hiccup-svg";
import { fromIterable, merge, sync } from "@thi.ng/rstream";
import {
GestureEvent,
gestureStream,
GestureType,
} from "@thi.ng/rstream-gestures";
import { GestureEvent, gestureStream } from "@thi.ng/rstream-gestures";
import {
comp,
filter,
Expand Down Expand Up @@ -116,10 +112,10 @@ const collectPath = () => {
return (g: GestureEvent) => {
console.log(g);
switch (g.type) {
case GestureType.START:
case "start":
pts = [g.pos];
break;
case GestureType.DRAG:
case "drag":
pts.push(g.pos);
break;
}
Expand All @@ -138,9 +134,7 @@ const gesture = merge<any, any>({
// mouse & touch event stream attached to document.body
// we're filtering out move & zoom events to avoid extraneous work
gestureStream(document.body).transform(
filter(
(g) => g.type != GestureType.MOVE && g.type != GestureType.ZOOM
),
filter((g) => !(g.type === "move" || g.type === "zoom")),
map(collectPath())
),
],
Expand Down
9 changes: 2 additions & 7 deletions examples/hdom-canvas-draw/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { canvas } from "@thi.ng/hdom-canvas";
import { HALF_PI, PI } from "@thi.ng/math";
import { CloseMode, StreamSync, sync, trigger } from "@thi.ng/rstream";
import {
GestureEvent,
gestureStream,
GestureType,
} from "@thi.ng/rstream-gestures";
import { GestureEvent, gestureStream } from "@thi.ng/rstream-gestures";
import {
filter,
map,
Expand Down Expand Up @@ -49,8 +45,7 @@ const app = (main: StreamSync<any, any>) => {
// only interested in some gesture types
filter(
(e: GestureEvent) =>
e.type === GestureType.START ||
e.type === GestureType.DRAG
e.type === "start" || e.type === "drag"
),
// get current mouse / touch position
map((e) => e.pos),
Expand Down
10 changes: 5 additions & 5 deletions examples/mandelbrot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { equiv } from "@thi.ng/equiv";
import { canvas2D } from "@thi.ng/hdom-components";
import { fit, mix } from "@thi.ng/math";
import { stream, Stream, sync, tunnel } from "@thi.ng/rstream";
import { gestureStream, GestureType } from "@thi.ng/rstream-gestures";
import { gestureStream } from "@thi.ng/rstream-gestures";
import { padLeft } from "@thi.ng/strings";
import { map } from "@thi.ng/transducers";
import { updateDOM } from "@thi.ng/transducers-hdom";
Expand Down Expand Up @@ -132,13 +132,13 @@ const app = () => {
const _x2 = x2.deref()!;
const _y2 = y2.deref()!;
switch (e.type) {
case GestureType.START:
case "start":
sel1.next(e.pos);
break;
case GestureType.DRAG:
case "drag":
sel2.next(e.pos);
break;
case GestureType.END: {
case "end": {
const p = sel1.deref();
if (!p || equiv(p, e.pos)) return;
// compute target coord based on current zoom region
Expand Down Expand Up @@ -166,7 +166,7 @@ const app = () => {
newRender(ax, ay, bx, by);
break;
}
case GestureType.ZOOM:
case "zoom":
updateZoom(e.zoom);
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions examples/shader-ast-evo/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AST, ASTNode, ASTOpts, GeneType } from "@thi.ng/gp";
import { AST, ASTNode, ASTOpts } from "@thi.ng/gp";
import { roundTo } from "@thi.ng/math";
import { IRandom, SYSTEM } from "@thi.ng/random";
import {
Expand Down Expand Up @@ -115,7 +115,7 @@ const AST_OPTS: ASTOpts<Function, Vec3Term> = {
};

const transpile = (node: ASTNode<Function, Vec3Term>): Term<any> =>
node.type === GeneType.OP
node.type === "op"
? node.op.apply(null, node.args.map(transpile))
: node.value;

Expand Down
8 changes: 4 additions & 4 deletions examples/shader-graph/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { exposeGlobal, Nullable } from "@thi.ng/api";
import { ortho } from "@thi.ng/matrices";
import { fromRAF } from "@thi.ng/rstream";
import { gestureStream, GestureType } from "@thi.ng/rstream-gestures";
import { gestureStream } from "@thi.ng/rstream-gestures";
import { Node2D } from "@thi.ng/scenegraph";
import {
$x,
Expand Down Expand Up @@ -273,7 +273,7 @@ gestureStream(CTX.canvas, { minZoom: 0.1, maxZoom: 4, smooth: 0.05 }).subscribe(
{
next(e) {
switch (e.type) {
case GestureType.START:
case "start":
const info = ROOT.childForPoint(e.pos);
this.sel = info ? info.node : CONTENT;
this.startTheta = this.sel.rotate;
Expand All @@ -282,7 +282,7 @@ gestureStream(CTX.canvas, { minZoom: 0.1, maxZoom: 4, smooth: 0.05 }).subscribe(
copy(this.sel.translate)
);
break;
case GestureType.DRAG:
case "drag":
if (e.buttons == 2) {
this.sel.rotate =
this.startTheta + e.active[0].delta![0] * 0.01;
Expand All @@ -294,7 +294,7 @@ gestureStream(CTX.canvas, { minZoom: 0.1, maxZoom: 4, smooth: 0.05 }).subscribe(
}
CONTENT.update();
break;
case GestureType.ZOOM:
case "zoom":
CONTENT.scale = e.zoom;
CONTENT.update();
}
Expand Down
6 changes: 1 addition & 5 deletions packages/adjacency/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { Fn2, Pair } from "@thi.ng/api";

export enum DegreeType {
IN,
OUT,
BOTH,
}
export type DegreeType = "in" | "out" | "both";

export interface IGraph {
numEdges(): number;
Expand Down
10 changes: 5 additions & 5 deletions packages/adjacency/src/sparse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Pair } from "@thi.ng/api";
import { CSR } from "@thi.ng/sparse";
import { DegreeType, IGraph } from "./api";
import type { DegreeType, IGraph } from "./api";

export class AdjacencyMatrix extends CSR implements IGraph {
static newEmpty(n: number, undirected = false) {
Expand Down Expand Up @@ -96,21 +96,21 @@ export class AdjacencyMatrix extends CSR implements IGraph {
*
* @param deg - degree type
*/
degreeMat(deg: DegreeType = DegreeType.OUT) {
degreeMat(deg: DegreeType = "out") {
const res = CSR.empty(this.m);
switch (deg) {
case DegreeType.OUT:
case "out":
default:
for (let i = this.m; --i >= 0; ) {
res.setAt(i, i, this.nnzRow(i));
}
break;
case DegreeType.IN:
case "in":
for (let i = this.m; --i >= 0; ) {
res.setAt(i, i, this.nnzCol(i));
}
break;
case DegreeType.BOTH:
case "both":
for (let i = this.m; --i >= 0; ) {
res.setAt(i, i, this.nnzRow(i) + this.nnzCol(i));
}
Expand Down
12 changes: 11 additions & 1 deletion packages/color/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import type { Tuple } from "@thi.ng/api";
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
import type { ColorMode } from "./constants";

export type ColorMode =
| "rgb"
| "hcy"
| "hsv"
| "hsl"
| "hsi"
| "int"
| "css"
| "xyz"
| "ycbcr";

export type Color = Vec;
export type ReadonlyColor = ReadonlyVec;
Expand Down
12 changes: 0 additions & 12 deletions packages/color/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import { float, percent } from "@thi.ng/strings";

export enum ColorMode {
RGBA,
HCYA,
HSVA,
HSLA,
HSIA,
INT32,
CSS,
XYZA,
YCBCRA,
}

// RGBA constants

export const BLACK = Object.freeze([0, 0, 0, 1]);
Expand Down
Loading

0 comments on commit bda4f75

Please sign in to comment.