2021-11-27 21:30:20 +00:00
|
|
|
/// <reference path="../vector.ts" />
|
|
|
|
|
2021-11-27 19:54:04 +00:00
|
|
|
enum InstructionType
|
|
|
|
{
|
|
|
|
Point,
|
|
|
|
Line,
|
|
|
|
Circle
|
|
|
|
}
|
|
|
|
|
2021-11-27 21:30:20 +00:00
|
|
|
abstract class Instruction
|
2021-11-27 19:54:04 +00:00
|
|
|
{
|
|
|
|
public fn: InstructionType;
|
|
|
|
public params :Parameter[];
|
|
|
|
|
|
|
|
constructor(type: InstructionType)
|
|
|
|
{
|
|
|
|
this.fn = type;
|
|
|
|
this.params = [];
|
|
|
|
}
|
2021-11-27 21:30:20 +00:00
|
|
|
|
|
|
|
abstract eval();
|
|
|
|
}
|
|
|
|
|
|
|
|
class PointInstruction extends Instruction
|
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super(InstructionType.Point);
|
|
|
|
}
|
|
|
|
|
|
|
|
eval()
|
|
|
|
{
|
|
|
|
return new Vector2D(this.params[0].eval(), this.params[1].eval());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LineInstruction extends Instruction
|
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super(InstructionType.Line);
|
|
|
|
}
|
|
|
|
|
|
|
|
eval()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
this.params[0].eval(),
|
|
|
|
this.params[1].eval()
|
|
|
|
];
|
|
|
|
}
|
2021-11-27 19:54:04 +00:00
|
|
|
}
|