package com.mocircle.cidrawing.element;

import android.graphics.Matrix;
import android.graphics.Path;
import android.graphics.RectF;

/**
 * A kind of element which is surrounded by the bounds.
 */
public abstract class BoundsElement extends DrawElement {

    protected transient RectF originalBoundingBox;
    protected transient Path boundingPath;

    @Override
    public void applyMatrixForData(Matrix matrix) {
        super.applyMatrixForData(matrix);
        boundingPath.transform(matrix);
    }

    @Override
    public void updateBoundingBox() {
        if (boundingPath != null) {
            RectF box = new RectF();
            boundingPath.computeBounds(box, true);
            setBoundingBox(box);
        }
    }

    @Override
    public RectF getOuterBoundingBox() {
        if (boundingPath != null) {
            Path path = new Path(boundingPath);
            path.transform(getDisplayMatrix());
            RectF box = new RectF();
            path.computeBounds(box, true);
            return box;
        }
        return new RectF();
    }

    @Override
    protected void cloneTo(BaseElement element) {
        super.cloneTo(element);
        if (element instanceof BoundsElement) {
            BoundsElement obj = (BoundsElement) element;
            if (originalBoundingBox != null) {
                obj.originalBoundingBox = new RectF(originalBoundingBox);
            }
            if (boundingPath != null) {
                obj.boundingPath = new Path(boundingPath);
            }
        }
    }

    protected abstract void calculateBoundingBox();

}

@@ -1055,32 +1055,217 @@
 RectF();%0A    %7D%0A%0A
+    @Override%0A    public Path getTouchableArea() %7B%0A        if (boundingPath != null) %7B%0A            return boundingPath;%0A        %7D else %7B%0A            return new Path();%0A        %7D%0A    %7D%0A%0A
     @Override%0A  

Fix bounds element touch area incorrect issue.