package org.hogel.android.simplepainting.model;

import android.graphics.Path;
import android.graphics.Point;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor(suppressConstructorProperties = true)
public class Line implements Serializable {
    private int color;

    @NonNull
    private List<Point> points;

    public Line(int color) {
        this(color, new ArrayList<Point>());
    }

    public void addPoint(Point point) {
        if (!points.isEmpty() && points.get(points.size() - 1).equals(point)) {
            return;
        }
        points.add(point);
    }

    public Path toPath() {
        final Path path = new Path();
        if (points.isEmpty()) {
            return path;
        }

        final Point point1 = points.get(0);
        path.moveTo(point1.x, point1.y);
        for (int i = 1; i < points.size(); ++i) {
            final Point point = points.get(i);
            path.lineTo(point.x, point.y);
        }
        return path;
    }
}

@@ -698,16 +698,44 @@
 point);%0A
+        supplementPoints();%0A
     %7D%0A%0A 
@@ -1127,11 +1127,418 @@
 h;%0A    %7D
+%0A%0A    private void supplementPoints() %7B%0A        final int size = points.size();%0A        if (size %3C 3) %7B%0A            return;%0A        %7D%0A        final Point point1 = points.get(size - 3);%0A        final Point point2 = points.get(size - 2);%0A        final Point point3 = points.get(size - 1);%0A%0A        point2.x = (point1.x + point2.x + point3.x) / 3;%0A        point2.y = (point1.y + point2.y + point3.y) / 3;%0A    %7D
 %0A%7D%0A

Add line supplement