import { Deserialize } from "../util/deserialize.model";

export class Coordinate3dStringModel implements Deserialize {
  x: number;
  y: number;
  z: number;

  deserialize(input: any): this {
    const array = input.split(' ');
    if (array.length !== 3) throw Error(`Bad string [${input}] for Coordinate3d`);
    this.x = Number.parseFloat(array[0]);
    this.y = Number.parseFloat(array[1]);
    this.z = Number.parseFloat(array[2]);
    return this;
  }

  toJSON(): string {
    return `${this.x} ${this.y} ${this.z}`;
  }
}