addPoint method

void addPoint(
  1. Offset point
)

Adds a new point to the end of the line.

Implementation

void addPoint(Offset point) {
  // Skip duplicate points
  if (points.isNotEmpty &&
      point.dx == points[points.length - 1].dx &&
      point.dy == points[points.length - 1].dy) return;

  if (simplify &&
      points.length >= 2 &&
      GameMath.distanceBetweenPoints(point, points[points.length - 2]) <
          10.0) {
    // Check if we should remove last point before adding the new one

    // Calculate the square distance from the middle point to the line of the
    // new point and the second to last point
    double dist2 = _distToSeqment2(
        points[points.length - 1], point, points[points.length - 2]);

    // If the point is on the line, remove it
    if (dist2 < 1.0) {
      _points.removeAt(_points.length - 1);
    }
  }

  // Add point and point's age
  _points.add(point);
  _pointAges.add(0.0);
}