Skip to content

Commit

Permalink
2024/02/09 - Reverse some debug options
Browse files Browse the repository at this point in the history
  • Loading branch information
FadiShawki committed Jan 9, 2024
1 parent 161eba1 commit df83100
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 66 deletions.
20 changes: 10 additions & 10 deletions src/@orbitmines/explorer/Ray.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +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(".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',
Expand Down
97 changes: 41 additions & 56 deletions src/@orbitmines/external/chyp/ChypCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {VisualizationCanvas} from "../../explorer/Visualization";
import {_Continuation, add, AutoVertex, InterfaceOptions, SimpleRenderedRay} from "../../explorer/OrbitMinesExplorer";
import {Center} from "@react-three/drei";
import {useHotkeys} from "../../js/react/hooks/useHotkeys";
import {DebugRay, DebugResult, Ray, RayType} from "../../explorer/Ray";
import {DebugResult, Ray, RayType} from "../../explorer/Ray";
import {HotkeyConfig} from "@blueprintjs/core/src/hooks/hotkeys/hotkeyConfig";
import _ from "lodash";
import {Children} from "../../../lib/typescript/React";
Expand Down Expand Up @@ -134,75 +134,65 @@ const Interface = () => {
selection.debug(debug);

if (DEBUG) {
_.values(debug).forEach(ray => {

});
// _.groupBy(_.values(debug), ray => ray.vertex);

return <>
<Center>
{_.values(debug).map(((_ray, index) => {
const scale = 1.5;

const options = (ray: DebugRay, expected: InterfaceOptions): DebugRay & Required<InterfaceOptions> => {
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],
let ray = {
...debug[_ray.label]
}

const color = {
[RayType.VERTEX]: 'orange',
[RayType.TERMINAL]: '#FF5555',
[RayType.INITIAL]: '#5555FF',
[RayType.REFERENCE]: '#555555',
}[ray.type];

ray = {
...ray,
...({
color,
scale,
scale: 1.5,
position: [0, index * 20, 0]
} as InterfaceOptions)
}

...ray, // If set elsewhere, prefer that one instead
...expected, // Expected based on current perspective
}
debug[_ray.label] = ray;

const _default: Required<InterfaceOptions> = {
position: [0, 0, 0],
rotation: [0, 0, 0],
scale: 1,
color: 'orange',
..._.pick(ray, 'position', 'rotation', 'scale', 'color'),
}

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');
console.log(ray.label, [ray.initial, ray.vertex, ray.terminal].toString())

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 <group>
const initial: Required<InterfaceOptions> = { ..._default, position: [-20 * _default.scale, 0, 0] };

// Vertex as the origin for rotation
const vertex: Required<InterfaceOptions> = { ..._default, position: [0, 0, 0] } //, ...ray.vertex };
const terminal: Required<InterfaceOptions> = { ..._default, position: [20 * _default.scale, 0, 0] };

const Group = ({ children }: Children) => {
return <group position={_default.position} rotation={vertex.rotation}>
{children}
</group>
}

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);
const 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 <SimpleRenderedRay {...options} {...a} type={type} />;
const a = type === RayType.INITIAL ? { terminal: vertex } : { initial: vertex };
return <SimpleRenderedRay type={type} {...options} {...a} />;
}
case type: {
return <None {...options} />;
Expand All @@ -215,12 +205,7 @@ const Interface = () => {

return <Group key={index}>
<Extreme type={RayType.INITIAL} />
<SimpleRenderedRay
{...interface_options(vertex)}
initial={interface_options(initial)}
terminal={interface_options(terminal)}
type={ray.type === RayType.REFERENCE ? RayType.VERTEX : ray.type}
/>
<SimpleRenderedRay type={ray.type === RayType.REFERENCE ? RayType.VERTEX : ray.type} {...vertex} initial={initial} terminal={terminal} />
<Extreme type={RayType.TERMINAL} />
</Group>
}))}
Expand Down

0 comments on commit df83100

Please sign in to comment.