geometor.model.utils¶
Provides utility functions for the Model class.
This module collects general-purpose utility functions used throughout the package. It includes tools for symbolic expression simplification (cleaning), point comparison and sorting, and logging setup.
Functions¶
|
Simplify and denest SymPy expressions. |
|
Calculate the spread of two lines. |
|
Compare two points for sorting. |
|
Get the numerical coordinates of a point. |
|
Sort a list of points. |
|
Initialize logging for a session. |
|
Print text to stdout and log it to the file. |
|
Calculate and format the elapsed time since start. |
Module Contents¶
- geometor.model.utils.clean_expr(expr: sympy.Expr) sympy.Expr¶
Simplify and denest SymPy expressions.
This function applies a standard set of simplification routines to symbolic expressions, specifically targeting the simplification of square roots and nested radicals which are common in constructive geometry.
- Parameters:
expr – The SymPy expression to clean.
- Returns:
The simplified expression.
- geometor.model.utils.spread(l1: sympy.geometry.Line, l2: sympy.geometry.Line) sympy.Expr¶
Calculate the spread of two lines.
The spread is a rational invariant of two lines, equivalent to the square of the sine of the angle between them. It is a fundamental concept in rational trigonometry.
- Parameters:
l1 – The first line.
l2 – The second line.
- Returns:
The spread as a symbolic expression.
- geometor.model.utils.compare_points(pt1: sympy.geometry.Point, pt2: sympy.geometry.Point) int¶
Compare two points for sorting.
This comparison function orders points primarily by their x-coordinates and secondarily by their y-coordinates. It returns 1 if pt1 > pt2, -1 if pt1 < pt2, and 0 if they are equal.
- Parameters:
pt1 – The first point.
pt2 – The second point.
- Returns:
An integer indicating the relative order (-1, 0, 1).
- geometor.model.utils.point_value(pt: sympy.geometry.Point) tuple[float, float]¶
Get the numerical coordinates of a point.
This helper extracts the floating-point values of a point’s x and y coordinates, suitable for use in sorting keys or numerical comparisons.
- Parameters:
pt – The point to evaluate.
- Returns:
A tuple of (x, y) floats.
- geometor.model.utils.sort_points(pts: list[sympy.geometry.Point]) list[sympy.geometry.Point]¶
Sort a list of points.
This function sorts a list of points using the point_value helper as the key.
- Parameters:
pts – The list of points to sort.
- Returns:
The sorted list of points.
- geometor.model.utils.log_init(name: str) None¶
Initialize logging for a session.
Sets up a log directory in the user’s home Sessions folder and configures basic logging to a ‘build.log’ file.
- Parameters:
name – The name of the session/subdirectory to create.