import * as planck from 'planck'
import { SegmentZone } from '../data/segment'

export class Zone {
  fixture: planck.Fixture|undefined
  type: 'solid'|'fluid'|'trigger'
  points: [number, number][]
  event: string = ''
  constructor(z: SegmentZone) {
    this.type = z.type
    this.points = z.points.map(v=>[v[0], v[1]])
    this.event = z.event
  }
  get bounds(): [number, number, number, number] {
    let xs = this.points.map(v=>v[0])
    let ys = this.points.map(v=>v[1])
    let minX = Math.min(...xs)
    let minY = Math.min(...ys)
    let maxX = Math.max(...xs)
    let maxY = Math.max(...ys)
    return [
      minX,
      minY,
      maxX-minX,
      maxY-minY,
    ]
  }
}

