Box constructor

Box(
  1. Point p1,
  2. Point p2
)

Construct a Box.

Reorders point coordinates as needed to store the upper right and lower left corners, in that order.

https://www.postgresql.org/docs/current/datatype-geometric.html#DATATYPE-GEOMETRIC-BOXES

Implementation

Box(Point p1, Point p2) {
  final (x1, x2) = p1.latitude >= p2.latitude
      ? (p1.latitude, p2.latitude)
      : (p2.latitude, p1.latitude);
  final (y1, y2) = p1.longitude >= p2.longitude
      ? (p1.longitude, p2.longitude)
      : (p2.longitude, p1.longitude);
  _p1 = Point(x1, y1);
  _p2 = Point(x2, y2);
}