in progress: implementing some rules of tonal harmony as graph

This commit is contained in:
Mikayla Dobson
2022-12-19 18:49:57 -06:00
parent b377cefa78
commit 5c0128c3ff
6 changed files with 101 additions and 27 deletions

View File

@@ -1,10 +1,10 @@
import GraphNode from "./GraphNode";
export default class Graph<T> {
private isWeighted: boolean;
private isDirected: boolean;
private points: GraphNode<T>[];
private count = 0;
protected isWeighted: boolean;
protected isDirected: boolean;
protected points: GraphNode<T>[];
protected count = 0;
constructor(isWeighted: boolean, isDirected: boolean, points?: GraphNode<T>[]) {
this.isWeighted = isWeighted;
@@ -12,14 +12,21 @@ export default class Graph<T> {
this.points = points || new Array<GraphNode<T>>();
}
createPoint(data: T) {
const newPoint = new GraphNode<T>(data, this.count);
createPoint(data: T | GraphNode<T>) {
let newPoint: GraphNode<T>;
if (data instanceof GraphNode<T>) {
data.setID(this.count);
newPoint = data;
} else {
newPoint = new GraphNode<T>(data, this.count);
}
this.points.push(newPoint);
this.count++;
return newPoint;
}
addPoints(...points: T[]) {
addPoints(...points: T[] | GraphNode<T>[]) {
for (let point of points) {
this.createPoint(point);
}