package com.cf.imes.module.executor.util;

import com.cf.imes.module.executor.dal.dataobject.remainplaten.PointDTO;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

/**
 * @author Beal
 */
public class RectangleChecker {
    /**
     * 获取两个点之间直线距离
     * @param x1 点1的x
     * @param y1 点1的y
     * @param x2 点2的x
     * @param y2 点2的y
     * @return 距离
     */
    public static double getDistance(int x1,int y1, int x2, int y2){
        return Math.sqrt(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    }


    /**
     * 检查4个点的形状是否为长方形
     * @param x1
     * @param y1
     * @param x2
     * @param y2
     * @param x3
     * @param y3
     * @param x4
     * @param y4
     * @return
     */
    public static boolean checkRectangle(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4 ) {
        return (x1 == x2 || y1==y2 ) && (x2 == x3 || y2==y3 ) && (x3 == x4 || y3==y4 ) && (x4 == x1 || y4==y1 );
    }


    public static boolean checkRectangle(List<PointDTO> list) {
        if(list.size()!=4) {
            return false;
        }
        PointDTO p1 = list.get(0);
        PointDTO p2 = list.get(1);
        PointDTO p3 = list.get(2);
        PointDTO p4 = list.get(3);
        return (p1.getX() == p2.getX() || p1.getY()==p1.getY() ) && (p2.getX() == p3.getX() || p2.getY()==p3.getY() )
                && (p3.getX() == p4.getX() || p3.getY()==p4.getY() ) && (p4.getX() == p1.getX() || p4.getY()==p1.getY() );
    }

    public static void main(String[] args) {
        //System.out.println(checkRectangle(new Point(6, 5), new Point(10, 5), new Point(10, 15), new Point(5, 15)));
        System.out.println(checkRectangle(5,5,10,5,11,15,5,15));
    }

}