From 161eba12bd2d6cc98178b8fc8ed23336cf33659c Mon Sep 17 00:00:00 2001 From: Fadi Shawki Date: Tue, 9 Jan 2024 23:08:26 +0100 Subject: [PATCH] 2024/02/09 - Trying some debug mode options --- .../explorer/OrbitMinesExplorer.tsx | 6 +- src/@orbitmines/explorer/Ray.spec.ts | 10 ++ src/@orbitmines/explorer/Ray.ts | 78 +++++++----- src/@orbitmines/external/chyp/Chyp.ts | 10 +- src/@orbitmines/external/chyp/ChypCanvas.tsx | 117 ++++++++++++++++-- 5 files changed, 170 insertions(+), 51 deletions(-) diff --git a/src/@orbitmines/explorer/OrbitMinesExplorer.tsx b/src/@orbitmines/explorer/OrbitMinesExplorer.tsx index 5883403..1a19153 100644 --- a/src/@orbitmines/explorer/OrbitMinesExplorer.tsx +++ b/src/@orbitmines/explorer/OrbitMinesExplorer.tsx @@ -344,13 +344,13 @@ export const AutoVertex = (ray: Omit & InterfaceOptions & { {children} } -const _Continuation = ({ color = torus.color, ...options }: InterfaceOptions) => +export const _Continuation = ({ color = torus.color, ...options }: InterfaceOptions) => -const _Vertex = ({ color = circle.color, ...options }: any) => +export const _Vertex = ({ color = circle.color, ...options }: any) => { const next = selection.continues_with( - Ray.js("A").as_reference() + Ray.vertex().as_reference() ); setSelection(next) diff --git a/src/@orbitmines/explorer/Ray.spec.ts b/src/@orbitmines/explorer/Ray.spec.ts index d1b9d94..8e3db38 100644 --- a/src/@orbitmines/explorer/Ray.spec.ts +++ b/src/@orbitmines/explorer/Ray.spec.ts @@ -17,6 +17,16 @@ describe("JS", () => { }) }); describe("Ray", () => { + test(".vertex.#.debug", () => { + const a = Ray.vertex().as_reference(); + const b = Ray.vertex().as_reference(); + a.continues_with(b); + + const debug = {}; + a.debug(debug); + + expect(debug).toEqual('') + }) test(".o", () => { const ray = Ray.vertex().o({ a: 'b', diff --git a/src/@orbitmines/explorer/Ray.ts b/src/@orbitmines/explorer/Ray.ts index 9782a23..7ab6c9f 100644 --- a/src/@orbitmines/explorer/Ray.ts +++ b/src/@orbitmines/explorer/Ray.ts @@ -31,6 +31,19 @@ export interface PossiblyHomoiconic> { export interface AbstractDirectionality { initial: Arbitrary, vertex: Arbitrary, terminal: Arbitrary } +export type DebugResult = { [label: string]: DebugRay } +export type DebugRay = { + label: string, + initial: string, + vertex: string, + terminal: string, + is_initial: boolean, + is_vertex: boolean, + is_terminal: boolean, + type: RayType, + _dirty_store: any +} + /** * JavaScript wrapper for a mutable value. It is important to realize that this is merely some simple JavaScript abstraction, and anything is assumed to be inherently mutable. * @@ -60,9 +73,6 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ?? // Array // Dict { - - js: Arbitrary - // TODO: Could make a case that setting the terminal is more of a map, defaulting/first checking the terminal before additional functionality is mapped over that. protected _initial: Arbitrary; get initial(): Ray { return this._initial(); } set initial(initial: Arbitrary) { this._initial = initial; } @@ -84,13 +94,10 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ?? [index: number]: Ray; - constructor({ initial, vertex, terminal, - js, - }: { js?: Arbitrary } & Partial> = {}) { + constructor({ initial, vertex, terminal, }: Partial> = {}) { this._initial = initial ?? Ray.None; this._vertex = vertex ?? this.self_reference; // TODO: None, could also self-reference the ray on which it's defining to be None. Now it's just an ignorant loop. this._terminal = terminal ?? Ray.None; - this.js = js ?? Ray.None; } /** [ |-?] */ is_initial = (): boolean => this.is_some() && this.self.initial.is_none(); @@ -134,18 +141,17 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ?? // new Ray({ initial: this.as_arbitrary(), vertex: () => this.terminal, js: () => 'terminal ref' }); // TODO: These fields as DEBUG /** [ ] */ const vertex = Ray.None(); - /** [-- ] */ vertex.initial = new Ray({ vertex: Ray.None, terminal: vertex.as_arbitrary(), js: () => 'initial ref' }).as_arbitrary(); + /** [-- ] */ vertex.initial = new Ray({ vertex: Ray.None, terminal: vertex.as_arbitrary() }).o({ debug: 'initial ref'}).as_arbitrary(); /** [ ? ] */ vertex.vertex = value; - /** [ --] */ vertex.terminal = new Ray({ vertex: Ray.None, initial: vertex.as_arbitrary(), js: () => 'terminal ref' }).as_arbitrary() + /** [ --] */ vertex.terminal = new Ray({ vertex: Ray.None, initial: vertex.as_arbitrary() }).o({ debug: 'terminal ref'}).as_arbitrary() /** [--?--] */ return vertex; } - static js = (value: any) => { const vertex = Ray.vertex(); vertex.js = () => value; return vertex; } static size = (of: number, value: any = undefined): Ray => { let current = Ray.vertex().as_reference(); // TODO; This sort of thing should be lazy for (let i = 0; i < of; i++) { - current = current.continues_with(Ray.js(value).as_reference()); + current = current.continues_with(Ray.vertex(JS.Any(value).as_arbitrary()).as_reference()); } return current; @@ -183,18 +189,17 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ?? return next_vertex.as_reference(); // TODO: Generally, return something which knows where all continuations are. } - // this.self.terminal = next_vertex.initial; equivalence# - - // switch (b.type) { - // case RayType.REFERENCE: - // break; - // case RayType.INITIAL: - // break; - // case RayType.TERMINAL: - // break; - // case RayType.VERTEX: - // break; - // } + switch (b.type) { + case RayType.REFERENCE: + case RayType.INITIAL: + case RayType.TERMINAL: { + throw new PreventsImplementationBug(); + } + case RayType.VERTEX: { + this.self.terminal.equivalent(b.self.initial); + break; + } + } return next_vertex.as_reference(); } @@ -203,7 +208,10 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ?? // TODO NEEDS TO CHECK IF THERE'S SOME INITIAL DEFIEND ; for defining if it has halted - equivalent = (other: Ray) => { throw new NotImplementedError(); } + protected equivalent = (b: Ray) => { // TODO: Generic, now just ignorantly sets the vertices to eachother + this.self = b.as_arbitrary(); + b.self = this.as_arbitrary(); + } // TODO: Perhaps locally cache count?? - no way to ensure globally coherenct get count(): Ray { throw new NotImplementedError() } @@ -333,12 +341,12 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ?? }) as T; } - debug = (c: { [label: string]: object | undefined }): object => { + debug = (c: DebugResult): DebugRay => { if (c[this.label] !== undefined) return c[this.label]!; const of = (ray: Ray): string => { - if (ray.is_none()) return 'None'; + if (ray.as_reference().is_none()) return 'None'; ray.debug(c); return ray.label; @@ -347,10 +355,15 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ?? const obj: any = { label: this.label }; c[this.label] = obj; + obj.label = this.label; obj.initial = of(this.initial); obj.vertex = of(this.vertex); obj.terminal = of(this.terminal); obj.type = this.as_reference().type; + obj.is_initial = this.as_reference().is_initial(); + obj.is_vertex = this.as_reference().is_vertex(); + obj.is_terminal = this.as_reference().is_terminal(); + obj._dirty_store = this._dirty_store; return obj; } @@ -422,7 +435,7 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ?? if (this.__label !== undefined) return this.__label; - return this.__label = `"${Ray._label++} (${this.js()?.toString() ?? '?'})})"`; + return this.__label = `"${Ray._label++} (${this.any.debug?.toString() ?? '?'})})"`; } // length: number; @@ -616,8 +629,8 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ?? export namespace JS { export const Boolean = (boolean: boolean): Ray => { // |-false->-true-| (could of course also be reversed) - const _false = Ray.js(false); - const _true = Ray.js(true); + const _false = Ray.vertex().o({ js: false }); + const _true = Ray.vertex().o({ js: true }); _false.continues_with(_true); return (boolean ? _true : _false).as_reference(); @@ -650,12 +663,11 @@ export namespace JS { } const current: Ray = new Ray({ - js: () => iterator_result.value, // initial: () => new Ray(), initial: () => initial, vertex: () => JS.Any(iterator_result.value), terminal: () => next(current) - }); + }).o({js: iterator_result.value}); // initial.continues_with(() => current.as_reference()); if (initial.is_some()) @@ -664,7 +676,7 @@ export namespace JS { return current; } - const ray_iterator = new Ray({ js: () => iterator}); + const ray_iterator = Ray.None().o({ js: iterator }); ray_iterator.terminal = () => next(ray_iterator); // This indicates we're passing a reference, since traversal logic will be defined at its vertex - what it's defining. @@ -698,7 +710,7 @@ export namespace JS { // TODO // return JS.Any(any); - return Ray.js(any); + return Ray.vertex().o({js: any}); } export const is_boolean = (_object: any): _object is boolean => _.isBoolean(_object); diff --git a/src/@orbitmines/external/chyp/Chyp.ts b/src/@orbitmines/external/chyp/Chyp.ts index 2575e39..07f147d 100644 --- a/src/@orbitmines/external/chyp/Chyp.ts +++ b/src/@orbitmines/external/chyp/Chyp.ts @@ -264,26 +264,20 @@ // vertices = this.property('vertices'); // edges = this.property('edges'); // -// // TODO: Shouldn't be here, this should either be implemented on Ray if it's general enough, of just remain here as an artifact -// protected ___domain = (ray: Ray) => ray.map(_ => { -// const vertex: VData = _.cast(); -// return [vertex.vtype, vertex.size]; -// }); -// // /** // * Return the domain of the graph. // * // * This consists of a list of pairs (vertex type, register size) corresponding to each input vertex. // */ // // TODO: Domain/Codmain is just the initial/terminal side (possibly typed) where the direction which is what defines what it itself is connected to, is ignored. -// get domain(): Ray { return this.___domain(this.inputs) }; +// get domain(): Ray { return this.inputs.cast().domain; }; // // /** // * Return the domain of the graph. // * // * This consists of a list of pairs (vertex type, register size) corresponding to each output vertex. // */ -// get codomain(): Ray { return this.___domain(this.outputs) }; +// get codomain(): Ray { return this.outputs.cast().domain; }; // // vertex_data = (v = int): VData => this.vertices().at(v).cast(); // edge_data = (e = int): EData => this.edges().at(e).cast(); diff --git a/src/@orbitmines/external/chyp/ChypCanvas.tsx b/src/@orbitmines/external/chyp/ChypCanvas.tsx index 47c92b9..cfefe77 100644 --- a/src/@orbitmines/external/chyp/ChypCanvas.tsx +++ b/src/@orbitmines/external/chyp/ChypCanvas.tsx @@ -1,12 +1,13 @@ import React, {useRef, useState} from "react"; import IEventListener from "../../js/react/IEventListener"; import {VisualizationCanvas} from "../../explorer/Visualization"; -import {add, AutoRay, AutoVertex, InterfaceOptions} from "../../explorer/OrbitMinesExplorer"; +import {_Continuation, add, AutoVertex, InterfaceOptions, SimpleRenderedRay} from "../../explorer/OrbitMinesExplorer"; import {Center} from "@react-three/drei"; import {useHotkeys} from "../../js/react/hooks/useHotkeys"; -import {Ray} from "../../explorer/Ray"; +import {DebugRay, DebugResult, Ray, RayType} from "../../explorer/Ray"; import {HotkeyConfig} from "@blueprintjs/core/src/hooks/hotkeys/hotkeyConfig"; -import {keys} from "lodash"; +import _ from "lodash"; +import {Children} from "../../../lib/typescript/React"; // TODO: Put the graphs setc at the top, invis lines, then draw them on hover, and maybe make surrounding stuff less visiable. // TODO: make some function which uses a custom input like position of the interface as the thing which breaks equivalences - ignorances. Basically a custom "equivalency function" @@ -41,10 +42,12 @@ const Interface = () => { combo: "arrowright", global: true, label: "", onKeyDown: () => { const { selection, rays } = Chyp.any; - const next = Ray.js("A").as_reference().o({ + const next = Ray.vertex().as_reference().o({ position: add(selection.any.position ?? [0, 0, 0], [i * 2, 0, 0]), scale }); + selection.continues_with(next); + // const next2 = Ray.js("A").as_reference().o({ // position: add(selection.any.position ?? [0, 0, 0], [i * 2, -30, 0]), // scale @@ -53,9 +56,6 @@ const Interface = () => { Chyp.any.selection = next; Chyp.any.rays = [...rays, next] - // selection.continues_with( - - // ); } }, { @@ -124,6 +124,109 @@ const Interface = () => { return ; } + const render = () => { + + } + + const DEBUG = true; + + const debug: DebugResult = {}; + selection.debug(debug); + + if (DEBUG) { + _.values(debug).forEach(ray => { + + }); + + return <> +
+ {_.values(debug).map(((_ray, index) => { + const scale = 1.5; + + const options = (ray: DebugRay, expected: InterfaceOptions): DebugRay & Required => { + const color = { + [RayType.VERTEX]: 'orange', + [RayType.TERMINAL]: '#FF5555', + [RayType.INITIAL]: '#5555FF', + [RayType.REFERENCE]: '#555555', + }[ray.type]; + + console.log('-') + console.log('expected', expected) + console.log('ray', ray) + return { + position: [0, 0, 0], + rotation: [0, 0, 0], + color, + scale, + + ...ray, // If set elsewhere, prefer that one instead + ...expected, // Expected based on current perspective + } + } + + const expected = (ref: string): InterfaceOptions => ref === 'None' ? {} : _.pick(debug[ref] as InterfaceOptions, 'position', 'rotation', 'color', 'scale'); + const interface_options = (ray: InterfaceOptions): InterfaceOptions => _.pick(ray, 'position', 'rotation', 'color', 'scale'); + + let ray = debug[_ray.label] = options(debug[_ray.label], { + position: [100, index * 20, 0], + // ...expected(debug[_ray.label].vertex) + }); + let vertex: InterfaceOptions = ray.vertex !== 'None' ? (debug[ray.vertex] = options(debug[ray.vertex], { + position: [100, index * 20, 0], + // ...expected(ray.label) + })) : {}; + let initial: InterfaceOptions = ray.initial !== 'None' ? (debug[ray.initial] = options(debug[ray.initial], { + position: add(ray.position, [-20 * scale, 0, 0]), + // ...expected(ray.label) + })) : {}; + let terminal: InterfaceOptions = ray.terminal !== 'None' ? (debug[ray.terminal] = options(debug[ray.terminal], { + position: add(ray.position, [20 * scale, 0, 0]), + // ...expected(ray.label) + })) : {}; + + const Group = ({ children }: Children) => { /// position={_default.position} rotation={vertex.rotation}> + return + {children} + + } + + const None = (options: InterfaceOptions) => (<_Continuation {...options} color="#AA0000" scale={1} />) + + const Extreme = ({type}: { type: RayType.INITIAL | RayType.TERMINAL }) => { + const options = interface_options(type === RayType.INITIAL ? initial : terminal); + + switch (ray.type) { + case RayType.REFERENCE: + case RayType.VERTEX: { + const vertex_options = interface_options(vertex); + + const a = type === RayType.INITIAL ? { terminal: vertex_options } : { initial: vertex_options }; + return ; + } + case type: { + return ; + } + case (type === RayType.INITIAL ? RayType.TERMINAL : RayType.INITIAL): { + return <> + } + } + } + + return + + + + + }))} +
+ + } return <>