I have a class called Shape
abstract class Shape {
transform: Matrix = identity();
material: Material = material();
setTransform(t: Matrix) {
this.transform = t;
}
intersect(ray: Ray): Intersections {
return this.localIntersect(ray.transform(this.transform.inverse()));
}
normalAt(point: Tuple): Tuple {
const localNormal = this.localNormalAt(this.transform.inverse().multiplyTuple(point));
const worldNormal = this.transform.inverse().transpose().multiplyTuple(localNormal);
return makeVector(worldNormal.x, worldNormal.y, worldNormal.z).normalize();
}
protected abstract localIntersect(localRay: Ray): Intersections;
protected abstract localNormalAt(localPoint: Tuple): Tuple;
}
export default Shape;
and another class called group:
export default class Group extends Shape {
items: Shape[];
constructor(...shapes: Shape[]) {
super();
this.items = shapes;
}
protected localIntersect(localRay: Ray): Intersections {
return undefined;
}
protected localNormalAt(localPoint: Tuple): Tuple {
return undefined;
}
}
export const makeGroup = (...shapes: Shape[]) => {
return new Group(...shapes);
};
I'm currently creating an items to store a list of shapes, however, I'd rather I have the class itself behave like an array, however I am unable to use both Array<Shape> and <Shape> (js only lets you extend a single class). I was wondering if it is possible to do this an alternative way?