import VectorType from '../enum/VectorType.js'
import Circle from '../Geometry/Circle.js'
import { mathUtil } from '../MathUtil.js'
import { floorplanService } from './FloorplanService'
import Constant from '../Constant'

export default class CircleService {
    constructor() {
    }
  
    createCircle(leftTopPosition,rightDownPosition,vectorId) {
        const radius = mathUtil.getDistance(leftTopPosition,rightDownPosition)/2
        const center = {
            x:(leftTopPosition.x+rightDownPosition.x)/2,
            y:(leftTopPosition.y+rightDownPosition.y)/2
        }
        const circle = new Circle(center, radius,vectorId)
        floorplanService.addCircle(circle)
        return circle
    }

    createCircle2(center,radius,vectorId,floor) {
        const circle = new Circle(center, radius,vectorId,floor)
        floorplanService.addCircle(circle)
        return circle
    }

    updateCircleVertex(vectorId,newPosition,index){
        const circle = floorplanService.getCircle(vectorId)
        circle.updatePoints(newPosition,index)
    }

    setCircleInfo(circleInfo) {
        let circle = floorplanService.getCircle(circleInfo.vectorId)
        circle.vectorId = circleInfo.vectorId
        circle.radius = circleInfo.radius
        circle.center = JSON.parse(JSON.stringify(circleInfo.center))
        circle.points = JSON.parse(JSON.stringify(circleInfo.points))
        circle.color = circleInfo.color
    }

    deleteCircle(circleId, floorNum) {
        floorplanService.deleteCircle(circleId, floorNum)
    }
}

const circleService = new CircleService()
export { circleService }