geo_math¶
Geometry and math helpers extracted from charmy.styles.shape.
This module centralizes math utilities used for shapes: angle conversions, circle-point computations, arc-to-bezier conversion, and angle coverage tests.
!! THIS IS A VIBED MODULE !!¶
This module was mostly vibed by GitHub Copilot, ChatGPT, and Google Gemini. It includes geometric knowledge that the core devs (in 2026) have not learned yet.
This module is impossible to be completed by three secondary school students without the help from third-party, and here, in this era, we chose AI. We provide no guarantee for codes this file.
- charmy.utils.geo_math.evaluate_quadratic_bezier(points: Sequence[tuple[int, int]], t: float) tuple[float, float]¶
Evaluate a quadratic Bezier at parameter t (0..1).
Returns (x, y) as floats.
- charmy.utils.geo_math.quadratic_bezier_internal_t_roots(points: Sequence[tuple[int, int]], eps: float = 1e-12) List[float]¶
Return the list of unique t roots (0<t<1) where derivative in x or y is zero.
This mirrors solving (p0 - 2*p1 + p2) * t = (p0 - p1) for each coordinate.
- charmy.utils.geo_math.evaluate_cubic_bezier(points: Sequence[tuple[int, int]], t: float) tuple[float, float]¶
Evaluate a cubic Bezier at parameter t (0..1). Returns (x, y) floats.
- charmy.utils.geo_math.cubic_bezier_derivative_roots(points: Sequence[tuple[int, int]], eps: float = 1e-12) List[float]¶
Return t roots (0<t<1) where derivative in x or y is zero.
Solves quadratic 3*a t^2 + 2*b t + c = 0 for each coordinate, where a = -p0 + 3*p1 - 3*p2 + p3 b = 3*(p0 - 2*p1 + p2) c = 3*(p1 - p0)
- charmy.utils.geo_math.gui_deg_to_math_rad(gui_deg: float) float¶
Convert GUI degrees (0=North, clockwise) to math radians (0=East, CCW).
This follows the conversion used in the original shape code.
- charmy.utils.geo_math.point_on_circle(center: tuple[int, int], radius: int, gui_deg: float) tuple[int, int]¶
Return the integer point on circle at GUI orientation degrees.
GUI coordinate system: 0 degrees is up and angles increase clockwise. The returned point uses integer rounding consistent with the original code.
- charmy.utils.geo_math.is_angle_covered(target: float, start: float, end: float) bool¶
Check whether target angle (degrees) lies within [start, end] in GUI CW system.
Angles are normalized to 0..360. The function handles wrap-around ranges.
- charmy.utils.geo_math.arc_to_cubic_beziers(center: tuple[int, int], radius: int, start_orient: int, end_orient: int) List[List[tuple[int, int]]]¶
Convert a circle arc (in GUI degrees) to a list of cubic Bezier point lists.
Returns a list where each item is [p0, p1, p2, p3] with integer points. This mirrors the logic from the original Shape module.
- charmy.utils.geo_math.flatten_circle_arc(center: tuple[int, int], radius: int, start_orient: int, end_orient: int, tolerance: float = 15.0) List[tuple[int, int]]¶
Flatten a circle arc into a polyline approximation.
The returned list includes the start and end points of the arc. :param tolerance: Maximum allowed angle step between consecutive points, in degrees.
- charmy.utils.geo_math.flatten_quadratic_bezier(points: Sequence[tuple[int, int]], tolerance: float = 15.0) List[tuple[int, int]]¶
Flatten a quadratic Bezier curve into a polyline.
- 参数:
tolerance -- Approximate maximum angle between adjacent polyline segments, in degrees.
- charmy.utils.geo_math.flatten_cubic_bezier(points: Sequence[tuple[int, int]], tolerance: float = 15.0) List[tuple[int, int]]¶
Flatten a cubic Bezier curve into a polyline.
- 参数:
tolerance -- Approximate maximum angle between adjacent polyline segments, in degrees.