Box.create constructor
Box.create({})
A bounding box from parameters compatible with CreateBox
function type.
The Box.view constructor is used to create a bounding box from a double
array filled by given minX
, minY
, maxX
and maxY
coordinate values
(and optionally by minZ
, minM
, maxZ
and maxM
too).
Examples:
// a 2D box
Box.create(minX: 10.0, minY: 20.0, maxX: 15.0, maxY: 25.0);
// a 3D box
Box.create(
minX: 10.0, minY: 20.0, minZ: 30.0,
maxX: 15.0, maxY: 25.0, maxZ: 35.0,
);
// a measured 2D box
Box.create(
minX: 10.0, minY: 20.0, minM: 40.0,
maxX: 15.0, maxY: 25.0, maxM: 45.0,
);
// a measured 3D box
Box.create(
minX: 10.0, minY: 20.0, minZ: 30.0, minM: 40.0,
maxX: 15.0, maxY: 25.0, maxZ: 35.0, maxM: 45.0,
);
Implementation
factory Box.create({
required double minX,
required double minY,
double? minZ,
double? minM,
required double maxX,
required double maxY,
double? maxZ,
double? maxM,
}) {
final is3D = minZ != null && maxZ != null;
final isMeasured = minM != null && maxM != null;
final type = Coords.select(is3D: is3D, isMeasured: isMeasured);
final list = Float64List(2 * type.coordinateDimension);
var i = 0;
list[i++] = minX;
list[i++] = minY;
if (is3D) {
list[i++] = minZ;
}
if (isMeasured) {
list[i++] = minM;
}
list[i++] = maxX;
list[i++] = maxY;
if (is3D) {
list[i++] = maxZ;
}
if (isMeasured) {
list[i++] = maxM;
}
return Box.view(list, type: type);
}