i_overlay 6.0.0

Boolean Operations for 2D Polygons: Supports intersection, union, difference, xor, and self-intersections for all polygon varieties.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
use crate::build::sweep::{FillHandler, SweepRunner};
use crate::core::fill_rule::FillRule;
use crate::core::overlay::ShapeType;
use crate::core::predicate::{
    InteriorsIntersectHandler, IntersectsHandler, PointIntersectsHandler, TouchesHandler, WithinHandler,
};
use crate::core::solver::Solver;
use crate::segm::boolean::ShapeCountBoolean;
use crate::segm::build::BuildSegments;
use crate::segm::segment::Segment;
use crate::split::solver::SplitSolver;
use alloc::vec::Vec;
use i_float::int::point::IntPoint;
use i_shape::int::shape::{IntContour, IntShape};

/// Overlay structure optimized for spatial predicate evaluation.
///
/// `PredicateOverlay` provides efficient spatial relationship testing between
/// two polygon sets without computing full boolean operation results. It is
/// designed for cases where you only need to know *whether* shapes intersect,
/// not *what* the intersection looks like.
///
/// # Example
///
/// ```
/// use i_overlay::core::relate::PredicateOverlay;
/// use i_overlay::core::overlay::ShapeType;
///
/// let mut overlay = PredicateOverlay::new(16);
/// // Add subject and clip segments...
/// let intersects = overlay.intersects();
/// ```
///
/// For float coordinates, prefer using [`FloatPredicateOverlay`](crate::float::relate::FloatPredicateOverlay)
/// or the [`FloatRelate`](crate::float::relate::FloatRelate) trait.
pub struct PredicateOverlay {
    /// Solver configuration for segment operations.
    pub solver: Solver,
    /// Fill rule for determining polygon interiors.
    pub fill_rule: FillRule,
    pub(crate) segments: Vec<Segment<ShapeCountBoolean>>,
    pub(crate) split_solver: SplitSolver,
    sweep_runner: SweepRunner<ShapeCountBoolean>,
}

impl PredicateOverlay {
    #[inline]
    pub fn new(capacity: usize) -> Self {
        Self {
            solver: Default::default(),
            fill_rule: FillRule::EvenOdd,
            segments: Vec::with_capacity(capacity),
            split_solver: SplitSolver::new(),
            sweep_runner: SweepRunner::new(),
        }
    }

    fn evaluate<T: Default, H: FillHandler<ShapeCountBoolean, Output = T>>(&mut self, handler: H) -> T {
        if self.segments.is_empty() {
            return T::default();
        }
        self.split_solver.split_segments(&mut self.segments, &self.solver);
        if self.segments.is_empty() {
            return T::default();
        }
        self.sweep_runner
            .run_with_fill_rule(self.fill_rule, &self.solver, &self.segments, handler)
    }

    /// Returns `true` if the subject and clip shapes intersect (share any point).
    ///
    /// This includes both interior overlap and boundary contact (including single-point touches).
    #[inline]
    pub fn intersects(&mut self) -> bool {
        let capacity = self.segments.len();
        self.evaluate(IntersectsHandler::new(capacity))
    }

    /// Returns `true` if the interiors of subject and clip shapes overlap.
    ///
    /// Unlike `intersects()`, this returns `false` for shapes that only share
    /// boundary points (edges or vertices) without interior overlap.
    #[inline]
    pub fn interiors_intersect(&mut self) -> bool {
        self.evaluate(InteriorsIntersectHandler)
    }

    /// Returns `true` if subject and clip shapes touch (boundaries intersect but interiors don't).
    ///
    /// This returns `true` when shapes share boundary points (edges or vertices)
    /// but their interiors don't overlap. This includes single-point vertex touches.
    #[inline]
    pub fn touches(&mut self) -> bool {
        let capacity = self.segments.len();
        self.evaluate(TouchesHandler::new(capacity))
    }

    /// Returns `true` if subject and clip shapes intersect by point coincidence only.
    ///
    /// This returns `true` when shapes share boundary vertices but NOT edges.
    /// Unlike `touches()`, this returns `false` for shapes that share edges.
    #[inline]
    pub fn point_intersects(&mut self) -> bool {
        let capacity = self.segments.len();
        self.evaluate(PointIntersectsHandler::new(capacity))
    }

    /// Returns `true` if subject is completely within clip.
    ///
    /// Subject is within clip if everywhere the subject has fill, the clip
    /// also has fill on the same side.
    #[inline]
    pub fn within(&mut self) -> bool {
        self.evaluate(WithinHandler::new())
    }

    /// Adds a path to the overlay using an iterator, allowing for more flexible path input.
    /// This function is particularly useful when working with dynamically generated paths or
    /// when paths are not directly stored in a collection.
    /// - `iter`: An iterator over references to `IntPoint` that defines the path.
    /// - `shape_type`: Specifies the role of the added path in the overlay operation, either as `Subject` or `Clip`.
    #[inline]
    pub fn add_path_iter<I: Iterator<Item = IntPoint>>(&mut self, iter: I, shape_type: ShapeType) {
        self.segments.append_path_iter(iter, shape_type, false);
    }

    /// Adds a single path to the overlay as either subject or clip paths.
    /// - `contour`: An array of points that form a closed path.
    /// - `shape_type`: Specifies the role of the added path in the overlay operation, either as `Subject` or `Clip`.
    #[inline]
    pub fn add_contour(&mut self, contour: &[IntPoint], shape_type: ShapeType) {
        self.segments
            .append_path_iter(contour.iter().copied(), shape_type, false);
    }

    /// Adds multiple paths to the overlay as either subject or clip paths.
    /// - `contours`: An array of `IntContour` instances to be added to the overlay.
    /// - `shape_type`: Specifies the role of the added paths in the overlay operation, either as `Subject` or `Clip`.
    #[inline]
    pub fn add_contours(&mut self, contours: &[IntContour], shape_type: ShapeType) {
        for contour in contours.iter() {
            self.add_contour(contour, shape_type);
        }
    }

    /// Adds a single shape to the overlay as either a subject or clip shape.
    /// - `shape`: A reference to a `IntShape` instance to be added.
    /// - `shape_type`: Specifies the role of the added shape in the overlay operation, either as `Subject` or `Clip`.
    #[inline]
    pub fn add_shape(&mut self, shape: &IntShape, shape_type: ShapeType) {
        self.add_contours(shape, shape_type);
    }

    /// Adds multiple shapes to the overlay as either subject or clip shapes.
    /// - `shapes`: An array of `IntShape` instances to be added to the overlay.
    /// - `shape_type`: Specifies the role of the added shapes in the overlay operation, either as `Subject` or `Clip`.
    #[inline]
    pub fn add_shapes(&mut self, shapes: &[IntShape], shape_type: ShapeType) {
        for shape in shapes.iter() {
            self.add_contours(shape, shape_type);
        }
    }

    #[inline]
    pub fn clear(&mut self) {
        self.segments.clear();
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use alloc::vec;

    fn square(x: i32, y: i32, size: i32) -> Vec<IntPoint> {
        vec![
            IntPoint::new(x, y),
            IntPoint::new(x, y + size),
            IntPoint::new(x + size, y + size),
            IntPoint::new(x + size, y),
        ]
    }

    #[test]
    fn test_add_contour_intersects() {
        let mut overlay = PredicateOverlay::new(16);
        overlay.add_contour(&square(0, 0, 10), ShapeType::Subject);
        overlay.add_contour(&square(5, 5, 10), ShapeType::Clip);
        assert!(overlay.intersects());
    }

    #[test]
    fn test_add_contour_disjoint() {
        let mut overlay = PredicateOverlay::new(16);
        overlay.add_contour(&square(0, 0, 10), ShapeType::Subject);
        overlay.add_contour(&square(20, 20, 10), ShapeType::Clip);
        assert!(!overlay.intersects());
    }

    #[test]
    fn test_add_contour_touches() {
        let mut overlay = PredicateOverlay::new(16);
        overlay.add_contour(&square(0, 0, 10), ShapeType::Subject);
        overlay.add_contour(&square(10, 0, 10), ShapeType::Clip);
        assert!(overlay.touches());

        overlay.clear();
        overlay.add_contour(&square(0, 0, 10), ShapeType::Subject);
        overlay.add_contour(&square(10, 0, 10), ShapeType::Clip);
        assert!(!overlay.interiors_intersect());
    }

    #[test]
    fn test_add_contour_within() {
        let mut overlay = PredicateOverlay::new(16);
        overlay.add_contour(&square(5, 5, 10), ShapeType::Subject);
        overlay.add_contour(&square(0, 0, 20), ShapeType::Clip);
        assert!(overlay.within());
    }

    #[test]
    fn test_add_contours() {
        let mut overlay = PredicateOverlay::new(16);
        let contours = vec![square(0, 0, 5), square(10, 10, 5)];
        overlay.add_contours(&contours, ShapeType::Subject);
        overlay.add_contour(&square(2, 2, 3), ShapeType::Clip);
        assert!(overlay.intersects());
    }

    #[test]
    fn test_add_shape() {
        let mut overlay = PredicateOverlay::new(16);
        let shape = vec![square(0, 0, 10)];
        overlay.add_shape(&shape, ShapeType::Subject);
        overlay.add_contour(&square(5, 5, 10), ShapeType::Clip);
        assert!(overlay.intersects());
    }

    #[test]
    fn test_add_shapes() {
        let mut overlay = PredicateOverlay::new(16);
        let shapes = vec![vec![square(0, 0, 5)], vec![square(20, 20, 5)]];
        overlay.add_shapes(&shapes, ShapeType::Subject);
        overlay.add_contour(&square(2, 2, 3), ShapeType::Clip);
        assert!(overlay.intersects());
    }

    #[test]
    fn test_add_path_iter() {
        let mut overlay = PredicateOverlay::new(16);
        let points = square(0, 0, 10);
        overlay.add_path_iter(points.into_iter(), ShapeType::Subject);
        overlay.add_contour(&square(5, 5, 10), ShapeType::Clip);
        assert!(overlay.intersects());
    }

    #[test]
    fn test_point_touch_intersects() {
        // Two squares touching at a single corner point (10, 10)
        let mut overlay = PredicateOverlay::new(16);
        overlay.add_contour(&square(0, 0, 10), ShapeType::Subject);
        overlay.add_contour(&square(10, 10, 10), ShapeType::Clip);
        assert!(overlay.intersects(), "point-to-point should intersect");
    }

    #[test]
    fn test_point_touch_touches() {
        // Two squares touching at a single corner point (10, 10)
        let mut overlay = PredicateOverlay::new(16);
        overlay.add_contour(&square(0, 0, 10), ShapeType::Subject);
        overlay.add_contour(&square(10, 10, 10), ShapeType::Clip);
        assert!(overlay.touches(), "point-to-point should touch");
    }

    #[test]
    fn test_point_touch_no_interior_intersect() {
        // Two squares touching at a single corner point (10, 10)
        let mut overlay = PredicateOverlay::new(16);
        overlay.add_contour(&square(0, 0, 10), ShapeType::Subject);
        overlay.add_contour(&square(10, 10, 10), ShapeType::Clip);
        assert!(
            !overlay.interiors_intersect(),
            "point touch has no interior intersection"
        );
    }

    /// Test that intersects() detects when an edge passes through another polygon's interior.
    ///
    /// Shape A is a quadrilateral: (0,1), (0,0), (3,0), (3,8)
    /// Shape B is a box: (0,3) to (1,4)
    ///
    /// The edge from (0,1) to (3,8) passes through (1, 10/3 ≈ 3.33), which is inside B.
    /// Therefore intersects() should return true.
    #[test]
    fn test_intersects_edge_through_interior() {
        // Shape A: quadrilateral with edge passing through B's interior
        let shape_a = vec![
            IntPoint::new(0, 1),
            IntPoint::new(0, 0),
            IntPoint::new(3, 0),
            IntPoint::new(3, 8),
        ];

        // Shape B: box from (0,3) to (1,4)
        let shape_b = vec![
            IntPoint::new(0, 3),
            IntPoint::new(1, 3),
            IntPoint::new(1, 4),
            IntPoint::new(0, 4),
        ];

        let mut overlay = PredicateOverlay::new(16);
        overlay.add_contour(&shape_a, ShapeType::Subject);
        overlay.add_contour(&shape_b, ShapeType::Clip);

        // The edge from (0,1) to (3,8) has parametric form:
        // P(t) = (0,1) + t*(3,7) = (3t, 1+7t) for t in [0,1]
        // At x=1: t=1/3, y = 1 + 7/3 = 10/3 ≈ 3.333
        // Point (1, 3.333) is strictly inside B (x in [0,1], y in [3,4])
        assert!(
            overlay.intersects(),
            "Edge (0,1)->(3,8) passes through box interior at (1, 3.33); should intersect"
        );
    }

    #[test]
    fn test_segment_end_to_start_touch() {
        // Triangle where subject's segment endpoint touches clip's segment startpoint
        // Subject: triangle at (0,0), (10,0), (5,10)
        // Clip: triangle at (10,0), (20,0), (15,10)
        // They touch at exactly one point: (10,0)
        let subj = vec![IntPoint::new(0, 0), IntPoint::new(10, 0), IntPoint::new(5, 10)];
        let clip = vec![IntPoint::new(10, 0), IntPoint::new(20, 0), IntPoint::new(15, 10)];

        let mut overlay = PredicateOverlay::new(16);
        overlay.add_contour(&subj, ShapeType::Subject);
        overlay.add_contour(&clip, ShapeType::Clip);
        assert!(
            overlay.intersects(),
            "segment b touching segment a should intersect"
        );

        overlay.clear();
        overlay.add_contour(&subj, ShapeType::Subject);
        overlay.add_contour(&clip, ShapeType::Clip);
        assert!(overlay.touches(), "segment b touching segment a should touch");

        overlay.clear();
        overlay.add_contour(&subj, ShapeType::Subject);
        overlay.add_contour(&clip, ShapeType::Clip);
        assert!(
            !overlay.interiors_intersect(),
            "segment b touching segment a should not have interior intersection"
        );
    }

    /// Creates a square with a hole (doughnut shape).
    /// Outer: counter-clockwise, Inner hole: clockwise
    fn doughnut(
        outer_x: i32,
        outer_y: i32,
        outer_size: i32,
        hole_x: i32,
        hole_y: i32,
        hole_size: i32,
    ) -> Vec<Vec<IntPoint>> {
        vec![
            // Outer boundary (counter-clockwise)
            vec![
                IntPoint::new(outer_x, outer_y),
                IntPoint::new(outer_x, outer_y + outer_size),
                IntPoint::new(outer_x + outer_size, outer_y + outer_size),
                IntPoint::new(outer_x + outer_size, outer_y),
            ],
            // Inner hole (clockwise)
            vec![
                IntPoint::new(hole_x, hole_y),
                IntPoint::new(hole_x + hole_size, hole_y),
                IntPoint::new(hole_x + hole_size, hole_y + hole_size),
                IntPoint::new(hole_x, hole_y + hole_size),
            ],
        ]
    }

    /// Creates a diamond (rotated square) with corners at midpoints of a bounding box.
    fn diamond(cx: i32, cy: i32, radius: i32) -> Vec<IntPoint> {
        vec![
            IntPoint::new(cx, cy - radius), // top
            IntPoint::new(cx + radius, cy), // right
            IntPoint::new(cx, cy + radius), // bottom
            IntPoint::new(cx - radius, cy), // left
        ]
    }

    #[test]
    fn test_doughnut_with_diamond_touching_hole_intersects() {
        // Subject: square doughnut with outer (0,0)-(30,30) and hole (10,10)-(20,20)
        // Clip: diamond inside the hole with corners touching the hole boundary
        //       Diamond centered at (15,15) with corners at (15,10), (20,15), (15,20), (10,15)
        //
        // This tests that inner segments of the hole (which have SUBJ_BOTH fill)
        // are still correctly tracked for point coincidence detection.
        let mut overlay = PredicateOverlay::new(32);
        let doughnut_shape = doughnut(0, 0, 30, 10, 10, 10);
        overlay.add_shape(&doughnut_shape, ShapeType::Subject);
        overlay.add_contour(&diamond(15, 15, 5), ShapeType::Clip);
        assert!(
            overlay.intersects(),
            "diamond touching hole boundary should intersect"
        );
    }

    #[test]
    fn test_doughnut_with_diamond_touching_hole_touches() {
        // Same setup: diamond corners touch the hole boundary but don't overlap
        let mut overlay = PredicateOverlay::new(32);
        let doughnut_shape = doughnut(0, 0, 30, 10, 10, 10);
        overlay.add_shape(&doughnut_shape, ShapeType::Subject);
        overlay.add_contour(&diamond(15, 15, 5), ShapeType::Clip);
        assert!(overlay.touches(), "diamond touching hole boundary should touch");
    }

    #[test]
    fn test_doughnut_with_diamond_touching_hole_no_interior_intersect() {
        // Same setup: diamond only touches at boundary points, interiors don't overlap
        let mut overlay = PredicateOverlay::new(32);
        let doughnut_shape = doughnut(0, 0, 30, 10, 10, 10);
        overlay.add_shape(&doughnut_shape, ShapeType::Subject);
        overlay.add_contour(&diamond(15, 15, 5), ShapeType::Clip);
        assert!(
            !overlay.interiors_intersect(),
            "diamond touching hole boundary should not have interior intersection"
        );
    }

    #[test]
    fn test_doughnut_with_diamond_inside_hole_disjoint() {
        // Diamond fully inside the hole, not touching any boundary
        // Diamond centered at (15,15) with radius 2 (corners at 13,15,17,15 etc)
        let mut overlay = PredicateOverlay::new(32);
        let doughnut_shape = doughnut(0, 0, 30, 10, 10, 10);
        overlay.add_shape(&doughnut_shape, ShapeType::Subject);
        overlay.add_contour(&diamond(15, 15, 2), ShapeType::Clip);
        assert!(!overlay.intersects(), "diamond inside hole should not intersect");
        assert!(!overlay.touches(), "diamond inside hole should not touch");
    }

    #[test]
    fn test_doughnut_with_diamond_touching_single_corner() {
        // Diamond inside the hole, touching only one corner: (10, 10)
        // The hole is at (10,10)-(20,20), so a diamond inside it touching the
        // bottom-left corner (10,10) needs all other points inside the hole.
        // Diamond: (10,10), (12,10), (12,12), (10,12) - this is a small square
        // in the corner of the hole, with one corner touching the hole corner.
        let diamond_touching_corner = vec![
            IntPoint::new(10, 10), // touches hole corner (also doughnut boundary)
            IntPoint::new(12, 10), // on hole bottom edge
            IntPoint::new(12, 12), // inside hole
            IntPoint::new(10, 12), // on hole left edge
        ];

        let mut overlay = PredicateOverlay::new(32);
        overlay.add_shape(&doughnut(0, 0, 30, 10, 10, 10), ShapeType::Subject);
        overlay.add_contour(&diamond_touching_corner, ShapeType::Clip);

        assert!(
            overlay.intersects(),
            "diamond touching hole corner should intersect"
        );
        assert!(overlay.touches(), "diamond touching hole corner should touch");
        assert!(
            !overlay.interiors_intersect(),
            "diamond touching hole corner should not have interior intersection"
        );
    }

    #[test]
    fn test_outer_diamond_touching_doughnut_corner() {
        // Diamond outside the doughnut, touching the outer corner at (0, 0)
        // This tests point coincidence for outer boundary segments.
        let diamond_outside = vec![
            IntPoint::new(0, 0),   // touches doughnut outer corner
            IntPoint::new(-5, 3),  // outside
            IntPoint::new(-5, -3), // outside
        ];

        let mut overlay = PredicateOverlay::new(32);
        overlay.add_shape(&doughnut(0, 0, 30, 10, 10, 10), ShapeType::Subject);
        overlay.add_contour(&diamond_outside, ShapeType::Clip);

        assert!(
            overlay.intersects(),
            "triangle touching outer corner should intersect"
        );
        assert!(overlay.touches(), "triangle touching outer corner should touch");
        assert!(
            !overlay.interiors_intersect(),
            "triangle touching outer corner should not have interior intersection"
        );
    }

    #[test]
    fn test_point_intersects_corner_to_corner() {
        // Two squares touching at a single corner point (10, 10)
        let mut overlay = PredicateOverlay::new(16);
        overlay.add_contour(&square(0, 0, 10), ShapeType::Subject);
        overlay.add_contour(&square(10, 10, 10), ShapeType::Clip);
        assert!(
            overlay.point_intersects(),
            "corner-to-corner should be point-only intersection"
        );
    }

    #[test]
    fn test_point_intersects_edge_sharing() {
        // Two squares sharing an edge (not point-only)
        let mut overlay = PredicateOverlay::new(16);
        overlay.add_contour(&square(0, 0, 10), ShapeType::Subject);
        overlay.add_contour(&square(10, 0, 10), ShapeType::Clip);
        // touches() is true for edge sharing
        assert!(overlay.touches());

        overlay.clear();
        overlay.add_contour(&square(0, 0, 10), ShapeType::Subject);
        overlay.add_contour(&square(10, 0, 10), ShapeType::Clip);
        // point_intersects() is false for edge sharing
        assert!(
            !overlay.point_intersects(),
            "edge sharing is not point-only intersection"
        );
    }

    #[test]
    fn test_point_intersects_overlapping() {
        // Overlapping squares (not point-only)
        let mut overlay = PredicateOverlay::new(16);
        overlay.add_contour(&square(0, 0, 10), ShapeType::Subject);
        overlay.add_contour(&square(5, 5, 10), ShapeType::Clip);
        assert!(
            !overlay.point_intersects(),
            "overlapping shapes are not point-only intersection"
        );
    }

    #[test]
    fn test_point_intersects_disjoint() {
        // Disjoint squares (no contact at all)
        let mut overlay = PredicateOverlay::new(16);
        overlay.add_contour(&square(0, 0, 10), ShapeType::Subject);
        overlay.add_contour(&square(20, 20, 10), ShapeType::Clip);
        assert!(
            !overlay.point_intersects(),
            "disjoint shapes have no point intersection"
        );
    }

    #[test]
    fn test_point_intersects_triangle_vertex() {
        // Two triangles touching at a single vertex
        let tri1 = vec![IntPoint::new(0, 0), IntPoint::new(10, 0), IntPoint::new(5, 10)];
        let tri2 = vec![IntPoint::new(10, 0), IntPoint::new(20, 0), IntPoint::new(15, 10)];

        let mut overlay = PredicateOverlay::new(16);
        overlay.add_contour(&tri1, ShapeType::Subject);
        overlay.add_contour(&tri2, ShapeType::Clip);
        assert!(
            overlay.point_intersects(),
            "triangles touching at vertex should be point-only intersection"
        );
    }
}