import { IPoint } from "pixi.js"
import { Vector } from "./vector"
import { lerp } from "./math"

// my own point I can extend however I want to, compatible with pixijs points
export class Point implements IPoint{
  static lerp(from:Point, to:Point, at:number): Point {
    return new Point(lerp(from.x, to.x, at), lerp(from.y, to.y, at))
  }

  x: number
  y: number

  constructor(x: number, y?: number){
    if(y === undefined)
      y = x
    this.x = x
    this.y = y
  }

  to(other: Point): Vector{
    return new Vector(other.x - this.x, other.y - this.y)
  }

  add(vec: Vector): Point{
    return new Point(this.x + vec.x, this.y + vec.y)
  }

  gt(other: Point):boolean{
    return this.x > other.x && this.y > other.y
  }

  lt(other: Point):boolean{
    return this.x < other.x && this.y < other.y
  }

  set(x?: number, y?: number): this {
    if (x !== undefined)
      this.x = x
    if (y !== undefined)
      this.y = y
    return this
  }
  copyFrom(p: IPoint): this {
    return this.set(p.x, p.y)
  }
  copyTo(p: IPoint): IPoint {
    p.set(this.x, this.y)
    return p
  }
  equals(p: IPoint): boolean {
    return this.x === p.x && this.y === p.y
  }
}