How can you know at what time an intersection of two paths takes place with Canvas?

Viewed 67

I am trying to get a boolean every time a path intersects, with the code :

final intersection = Path.combine(
   pathOperation.intersect,
   path,
   path2,
);

final pathsAreIntersecting = intersection.getBounds().isEmpty;

It works very well, however the problem comes when it depends on the strokeWidth of Paint, since it is too thick, I do not know when it really intersects, I give an example of a square and an eraser.

// * ERASE PAINT
final erasePaint = Paint()
      ..blendMode = BlendMode.clear
      ..color = Colors.transparent
      ..strokeCap = StrokeCap.round
      ..strokeWidth = 5.0
      ..style = PaintingStyle.stroke;

// * PENCIL PAINT
final pencilPaint = Paint()
      ..strokeCap = StrokeCap.round
      ..isAntiAlias = true
      ..color = state.currentColor
      ..strokeWidth = 25.0
      ..style = PaintingStyle.stroke;

enter image description here

I only want to know at what point is it taken into account the intersect operation.

I don't know if it's because of the strokeWidth, or the length, the only thing I want is that if you touch it with the other paint at the slightest edge, it becomes [false]

CODE :

final last = _drawsList.last;

    if (last.type == ActionType.erase) {
      final Path path = Path();

      // * ONLY THIS FOR THE ERASE
      path.moveTo(
        last.pointList[0].dx,
        last.pointList[0].dy,
      );

      for (int f = 1; f < last.pointList.length; f++) {
        path.lineTo(last.pointList[f].dx, last.pointList[f].dy);
      }

      if (_drawsList.isNotEmpty) {
        for (var currentShape in _drawsList.sublist(0, _drawsList.length - 1)) { /// I do not take into account the last drawing
          final Path path2 = Path();

          switch (currentShape.type) {
            case ActionType.rectangle:

              path2.addRect(Rect.fromPoints(
                currentShape.pointList[0],
                currentShape.pointList[1],
              ));

              break;
            default:
              break;

          }

          final intersection = Path.combine(
            PathOperation.intersect,
            path,
            path2,
          );

          final pathsAreIntersecting = intersection.getBounds().isEmpty;
          print(pathsAreIntersecting); // [true] : not intersecting, [false] : intersecting
          print("====");
        }
      }
    }
0 Answers
Related