# sec_interp.gui.preview_optimizer module

Geometry optimization utilities for SecInterp preview.

Handles simplification and sampling of geometric data to improve rendering performance.

class sec_interp.gui.preview_optimizer.PreviewOptimizer

  Bases: `object`

  Provides geometric optimization and sampling logic for preview rendering.

  static decimate(data: List[Tuple[float, float]], tolerance: float | None = None, max_points: int = 1000) → List[Tuple[float, float]]

    Decimate line data using Douglas-Peucker algorithm.

    Parameters:

      - data – List of (x, y) tuples

      - tolerance – Simplification tolerance (if provided, overrides max_points heuristic)

      - max_points – Maximum points to keep (approximate target if tolerance is None)

    Returns:

      Decimated list of (x, y) tuples

  static calculate_curvature(data: List[Tuple[float, float]]) → List[float]

    Calculate a simple curvature metric for each point in a line.

    This approximates curvature by the angle deviation between successive segments. High values indicate sharper turns.

    Parameters:

      data – List of (x, y) tuples.

    Returns:

      List of curvature values (angles in degrees), same length as data.

  classmethod adaptive_sample(data: List[Tuple[float, float]], min_tolerance: float = 0.1, max_tolerance: float = 10.0, max_points: int = 1000) → List[Tuple[float, float]]

    Adaptively sample data based on local curvature.

    Parameters:

      - data – List of (x, y) tuples

      - min_tolerance – Minimum tolerance for high-detail areas

      - max_tolerance – Maximum tolerance for low-detail areas

      - max_points – Maximum points to keep (approximate target)

    Returns:

      Adaptively sampled data