Skip to main content

tess2_rust/
sweep.rs

1// Copyright 2025 Lars Brubaker
2// License: SGI Free Software License B (MIT-compatible)
3//
4// Port of libtess2 sweep.c/h
5//
6// The Bentley-Ottmann sweep line algorithm for polygon tessellation.
7// This module contains the ActiveRegion struct and the sweep computation.
8// All logic is driven through the Tessellator in tess.rs.
9
10use crate::dict::NodeIdx;
11use crate::mesh::{EdgeIdx, INVALID};
12
13/// An active region: the area between two adjacent edges crossing the sweep line.
14#[derive(Clone, Debug, Default)]
15pub struct ActiveRegion {
16    /// Upper edge (directed right to left).
17    pub e_up: EdgeIdx,
18    /// Node in the edge dictionary for this region.
19    pub node_up: NodeIdx,
20    /// Running winding number for the region.
21    pub winding_number: i32,
22    /// Is this region inside the polygon?
23    pub inside: bool,
24    /// Sentinel: marks fake edges at t = ±infinity.
25    pub sentinel: bool,
26    /// Dirty: upper or lower edge changed, need to check for intersection.
27    pub dirty: bool,
28    /// Temporary edge introduced for a right vertex (will be fixed later).
29    pub fix_upper_edge: bool,
30}
31
32pub const INVALID_REGION: u32 = INVALID;