Skip to content

Commit

Permalink
2024/01/13 - Naive equivalence between vertices
Browse files Browse the repository at this point in the history
  • Loading branch information
FadiShawki committed Jan 13, 2024
1 parent e2f447e commit d3cf474
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 17 deletions.
31 changes: 30 additions & 1 deletion src/@orbitmines/explorer/Ray.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,35 @@ describe("Ray", () => {
expect(method(a)(b).terminal.self.any.js).toBe('B');
expect(method(a)(b).type).toBe(RayType.VERTEX);
});
test(".vertex.#.equivalent(.vertex.#)", () => {
let A = Ray.vertex().o({js: 'A'})
.as_reference().o({js: 'A.#'});
let B = Ray.vertex().o({js: 'B'})
.as_reference().o({js: 'B.#'});

expect(A.any.js).toBe('A.#');
expect(B.any.js).toBe('B.#');

let ref = A.equivalent(B);

expect(ref.self.initial).toBe(A);
expect(ref.self.terminal).toBe(B);
expect(ref.self.initial.any.js).toBe('A.#');
expect(ref.self.terminal.any.js).toBe('B.#');

expect(A.self.any.js).toBe('A');
expect(B.self.any.js).toBe('B');

expect(A.self.self).toBe(B.self);
expect(B.self.self).toBe(A.self);
expect(A.self.self.any.js).toBe('B');
expect(B.self.self.any.js).toBe('A');

expect(B.self.self.self).toBe(B.self);
expect(B.self.self.self.self).toBe(A.self);
expect(B.self.self.self.any.js).toBe('B');
expect(B.self.self.self.self.any.js).toBe('A');
});
test(".vertex.#.continues_with(.vertex.#)", () => {
let A = Ray.vertex().o({ js: 'A' }).as_reference();
let B = Ray.vertex().o({ js: 'B'}).as_reference();
Expand All @@ -40,7 +69,7 @@ describe("Ray", () => {
});
test("[.vertex.#, .vertex.#].#.continues_with", () => {
let A = Ray.vertex().o({ js: 'A' }).as_reference();
let B = Ray.vertex().o({ js: 'B'}).as_reference();
let B = Ray.vertex().o({ js: 'B' }).as_reference();

B = new Ray({
initial: A.as_arbitrary(),
Expand Down
61 changes: 45 additions & 16 deletions src/@orbitmines/explorer/Ray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ??
const _case = cases[this.type];

if (_case === undefined || _.isString(_case))
throw new PreventsImplementationBug(_case ?? '??');
throw new PreventsImplementationBug(_case ?? `?? ${this.type}`);

return _case();
}
Expand Down Expand Up @@ -251,6 +251,50 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ??
}
}

static equivalent= Ray.___func(ref => {
const { initial, terminal } = ref.self;

return initial.switch({
[RayType.REFERENCE]: () => terminal.switch({
[RayType.REFERENCE]: () => {
// TODO: IS THIS EVEN HOW THIS SHOULD WORK??
initial.self = terminal.as_arbitrary();
terminal.self = initial.as_arbitrary();

return ref;
}
}),
[RayType.VERTEX]: () => terminal.switch({
[RayType.VERTEX]: () => {
// TODO: COULD ADD?? - probably the case for all these equivalences.
initial.self.self = terminal.self.as_arbitrary();
terminal.self.self = initial.self.as_arbitrary();

return ref;
}
})
});

// TODO: Returns the ref, since it still holds the information on how they're not the same??? - Need some intuitive way of doing this?
// TODO a.equivalent(b).equivalent(c), in this case would be [[a, b]].equivalent(c) not [a, b, c].equivalent ???
});
equivalent = Ray.equivalent(this);
// protected equivalent = (b: Ray) => { // TODO: Generic, now just ignorantly sets the vertices to eachother
// switch (this.type) {
// case RayType.REFERENCE:
// break;
// case RayType.INITIAL:
// break;
// case RayType.TERMINAL:
// break;
// case RayType.VERTEX:
// break;
// }
//
// this.self = b.as_arbitrary();
// b.self = this.as_arbitrary();
// }

// TODO AS += through property
static continues_with = Ray.___func(ref => {
// TODO: contiues_with is just composing vertices..
Expand Down Expand Up @@ -407,21 +451,6 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ??
get first(): Ray { throw new NotImplementedError(); }
get last(): Ray { throw new NotImplementedError(); }

protected equivalent = (b: Ray) => { // TODO: Generic, now just ignorantly sets the vertices to eachother
switch (this.type) {
case RayType.REFERENCE:
break;
case RayType.INITIAL:
break;
case RayType.TERMINAL:
break;
case RayType.VERTEX:
break;
}

this.self = b.as_arbitrary();
b.self = this.as_arbitrary();
}
// TODO: I Don't like this name, but it needs to get across that any equivalency, or any equivalency check for that necessarily, is local. And I want more equivalences, I run more of this method.
// TODO: For chyp used to compare [vtype, size] as domains, just type matching on the vertex.
is_vertex_equivalent = (b: Ray) => {
Expand Down

0 comments on commit d3cf474

Please sign in to comment.