Box.parse constructor

Box.parse(
  1. String text, {
  2. Pattern delimiter = ',',
  3. Coords? type,
  4. bool swapXY = false,
  5. bool singlePrecision = false,
})

Parses a bounding box from text.

Coordinate values in text are separated by delimiter.

The Box.view constructor is used to create a bounding box from a double array filled by coordinate values parsed.

Use an optional type to explicitely set the coordinate type. If not provided and text has 6 items, then xyz coordinates are assumed.

If swapXY is true, then swaps x and y for the result.

If singlePrecision is true, then coordinate values of a position are stored in Float32List instead of the Float64List (default).

Throws FormatException if coordinates are invalid.

Examples:

// a 2D box (x: 10.0 .. 15.0, y: 20.0 .. 25.0)
Box.parse('10.0,20.0,15.0,25.0');

// a 3D box (x: 10.0 .. 15.0, y: 20.0 .. 25.0, z: 30.0 .. 35.0)
Box.parse('10.0,20.0,30.0,15.0,25.0,35.0');

// a measured 2D box (x: 10.0 .. 15.0, y: 20.0 .. 25.0, m: 40.0 .. 45.0)
// (need to specify the coordinate type XYM)
Box.parse('10.0,20.0,40.0,15.0,25.0,45.0', type: Coords.xym);

// a measured 3D box
// (x: 10.0 .. 15.0, y: 20.0 .. 25.0, z: 30.0 .. 35.0, m: 40.0 .. 45.0)
Box.parse('10.0,20.0,30.0,40.0,15.0,25.0,35.0,45.0');

// a 2D box (x: 10.0..15.0, y: 20.0..25.0) using an alternative delimiter
Box.parse('10.0;20.0;15.0;25.0', delimiter: ';');

// a 2D box (x: 10.0..15.0, y: 20.0..25.0) from an array with y before x
Box.parse('20.0,10.0,25.0,15.0', swapXY: true);

// a 2D box (x: 10.0..15.0, y: 20.0..25.0) with the internal storage using
// single precision floating point numbers (`Float32List` in this case)
Box.parse('10.0,20.0,15.0,25.0', singlePrecision: true);

Implementation

factory Box.parse(
  String text, {
  Pattern delimiter = ',',
  Coords? type,
  bool swapXY = false,
  bool singlePrecision = false,
}) =>
    parseBoxFromText(
      text,
      delimiter: delimiter,
      type: type,
      swapXY: swapXY,
      singlePrecision: singlePrecision,
    );