Coordinate.from constructor

Coordinate.from(
  1. dynamic value
)

Implementation

factory Coordinate.from(dynamic value) {
  assert(value is Coordinate ||
      value is UPoint ||
      (value is List<num> && (value.length == 2 || value.length == 3)));

  if (value is UPoint) {
    return Coordinate(value.x, value.y, 0);
  }

  if (value is List<num>) {
    if (value.length == 2) {
      final point = UPoint.from(value);
      return Coordinate(point.x, point.y, 0);
    }

    if (value.length == 3) {
      return Coordinate(
        value[0].toDouble(),
        value[1].toDouble(),
        value[2].toDouble(),
      );
    }
  }

  return value;
}