
import { rectangleService } from '../Service/RectangleService'
import { coordinate } from '../Coordinate'
import { floorplanService } from '../Service/FloorplanService'

//独立的，不会和线条以及其他构件融合
export default class AddRectangle {
    constructor() {
        this.start = null
        this.end = null;
        this.currentVectorId = null
    }

    execute(position){
        if(this.start == null){
            this.start = coordinate.getXYFromScreen(position)
        }
        else if(this.currentVectorId == null){
            this.end = {
                x:position.x,
                y:position.y
            };
            const rectangle = rectangleService.createRectangle(this.start,position)
            this.currentVectorId = rectangle.vectorId
        }
        else {
            this.end = {
                x:position.x,
                y:position.y
            };
            const rectangle = floorplanService.getRectangle(this.currentVectorId)
            rectangle.setPoints(this.start,position);
            //rectangleService.updateRectangleVertex(this.currentVectorId,position,2)    //右下角的点
        }
    }

    clear(){
        this.start = null
        this.end = null;
        this.currentVectorId = null
    }
}

const addRectangle = new AddRectangle()
export { addRectangle }