isRightPolygon method

bool isRightPolygon(
  1. PolygonBean polygonBean
)

This method can be used to determine whether the formed shape is a polygon or an irregular shape with intersecting line segments

Implementation

bool isRightPolygon(PolygonBean polygonBean) {
  bool isTriangle = _isTriangle(polygonBean.polygonPoint[0], polygonBean.polygonPoint[1], polygonBean.polygonPoint[2]);
  if (polygonBean.polygonPoint.length == 3 && isTriangle) {
    return true;
  }
  for (int i = 0; i < polygonBean.polygonPoint.length; i++) {
    if (i == polygonBean.polygonPoint.length - 1) {
      continue;
    }
    int j = i + 1;
    for (int k = 0; k < polygonBean.polygonPoint.length - 3; k++) {
      j++;
      Point p1 = Point(X: polygonBean.polygonPoint[i].X,
          Y: polygonBean.polygonPoint[i].Y);
      Point p2;
      if (i + 1 >= polygonBean.polygonPoint.length) {
        p2 = Point(X: polygonBean.polygonPoint[0].X,
            Y: polygonBean.polygonPoint[0].Y);
      } else {
        p2 = Point(X: polygonBean.polygonPoint[i + 1].X,
            Y: polygonBean.polygonPoint[i + 1].Y);
      }
      if (j >= polygonBean.polygonPoint.length) {
        j = 0;
      }
      Point p3 = Point(X: polygonBean.polygonPoint[j].X,
          Y: polygonBean.polygonPoint[j].Y);
      Point p4;
      if (j + 1 >= polygonBean.polygonPoint.length) {
        p4 = Point(X: polygonBean.polygonPoint[0].X,
            Y: polygonBean.polygonPoint[0].Y);
      } else {
        p4 = Point(X: polygonBean.polygonPoint[j + 1].X,
            Y: polygonBean.polygonPoint[j + 1].Y);
      }
      bool isIntersecting = _checkIntersectingLines(p1, p2, p3, p4);
      if (isIntersecting) {
        return true;
      }
    }
  }
  return false;
}