geometor.model

The Model module provides a set of tools for constructing geometric models. It relies heavily on sympy for providing the algebraic infrastructure the functions here are for creating the abstract model, not the rendering see the Render module for plotting with matplotlib

This module provides the Model class, which is used to represent a geometric model in 2D space. The Model class is based on the list data structure, and can contain points, lines, circles, polygons, and segments.

class geometor.model.Model(name: str = '', logger=None)[source]

Bases: dict

A collection of geometric elements, including points, lines, circles, and polygons, represented using the sympy.geometry library.

log(message)[source]
set_analysis_hook(hook_function)[source]
property new_points: list[Point]

The new_points of the model

clear_new_points()[source]
property name: str

The name of the model

set_point(x_val: Expr, y_val: Expr, parents: list | None = None, classes: list | None = None, ID: str = '', guide: bool = False) Point

Adds a point to the model, finds duplicates, cleans values, and sets parents and classes.

parameters

  • x_val : sympy.core.expr.Expr: The x-value of the point.

  • y_val : sympy.core.expr.Expr: The y-value of the point.

  • parents : list, optional: A list of parent elements or references. Defaults to None.

  • classes list, optional: A list of string names for classes defining a set of styles. Defaults to None.

  • ID str, optional: A text ID for use in plotting and reporting. Defaults to an empty string.

returns

example

>>> from geometor.model import *
>>> model = Model("demo")
>>> model.set_point(0, 0, classes=["given"])
<spg.Point object ...>

notes

The function simplifies the x and y values before adding, and it updates the attributes if the point is already in the model.

construct_line(pt_1: Point, pt_2: Point, classes: list | None = None, ID: str = '', guide: bool = False) Line
construct_line_by_IDs(pt_1_ID: str, pt_2_ID: str, classes: list | None = None, ID: str = '') Line

find points by ID and use them with Model.construct_line()

construct_circle(pt_center: Point, pt_radius: Point, classes: list | None = None, ID: str = '', guide: bool = False) Circle
construct_circle_by_IDs(pt_1_ID: str, pt_2_ID: str, classes: list | None = None, ID: str = '') Line

find points by ID and use them with Model.construct_line()

set_segment(pt_1: Point, pt_2: Point, classes=[], ID='') Segment

set segment (list of points) for demonstration in the model

set_segment_by_IDs(pt_1_ID: str, pt_2_ID: str, classes: list | None = None, ID: str = '') Line

find points by ID and use them with Model.construct_line()

set_section(points: list[Point], classes=[], ID='') Section

set section (list of 3 points on a line)

set_section_by_IDs(points_IDs: list[str], classes: list | None = None, ID: str = '') Section

find points by ID and use them with Model.set_section()

set_polygon(poly_pts: list[Point], classes=[], ID='') Polygon

set polygon (list of 3 or more points)

set_polygon_by_IDs(poly_pts_IDs: list[str], classes: list | None = None, ID: str = '') Line

find points by ID and use them with Model.construct_line()

set_wedge(pt_center: Point, pt_radius: Point, pt_sweep_start: Point, pt_sweep_end: Point, direction='clockwise', classes: list | None = None, ID: str = '') Wedge

sets a Wedge from 3 points and adds it to the model.

operations

  • create an instance of geometor.model.Wedge

  • create a details object from Element

  • add parents to details

    initial parents are the two starting points

  • check for duplicates in in the model

  • find intersection points for new element with all precedng elements

  • Add circle to the model.

parameters

returns

  • Wedge

    The portion of a circle

example

>>> from geometor.elements import *
>>> model = Model("demo")
>>> A = model.set_point(0, 0, classes=["given"], ID="A")
>>> B = model.set_point(1, 0, classes=["given"], ID="B")
>>> model.construct_circle(A, B)
>>> model.construct_circle(B, A)
>>> model._set_wedge_by_IDs('A', 'B', 'C')
<Wedge object ...>

notes

SymPy defines a circle as a center point and a radius length, so the radius length is calculated for the spg.Circle.

delete_element(element_or_ID)

Deletes an element and performs a cascading delete of all its dependents.

This method removes the specified element and any other elements that were constructed from it, directly or indirectly.

Args:
element_or_ID (spg.GeometryEntity or str): The element object or its

ID to be deleted.

get_dependents(element_or_ID)

Finds and returns a set of all elements that depend on the given element.

This method is for checking dependencies without performing any deletion.

Args:
element_or_ID (spg.GeometryEntity or str): The element object or its

ID to check for dependents.

Returns:
set: A set of dependent elements. Returns an empty set if the element

is not found or has no dependents.

remove_by_ID(ID: str) None[source]
property points: list[Point]

returns point elements from model as list

property structs: list[Line | Circle]

returns struct elements (line or circle) from model as list

property lines: list[Line]

returns line elements from model as list

property circles: list[Circle]

returns circle elements from model as list

limits() tuple[tuple[float, float], tuple[float, float]][source]

Find x, y limits from points and circles of the model

get_ancestors(element)

Retrieves the ancestors for the given element.

The method recursively traverses the parent elements of the given element and constructs a nested dictionary representing the ancestor tree.

parameters

  • elementsympy.geometry object

    The element for which the ancestors are to be retrieved.

returns

  • dict : A nested dictionary representing the ancestors.

example

If element A has parents B and C, and B has parent D, the method returns: {A: {B: {D: {}}, C: {}}}

get_ancestors_IDs(element) dict[str, dict]

Retrieves the IDs of the ancestors for the given element.

The method recursively traverses the parent elements of the given element and constructs a nested dictionary with IDs representing the ancestor tree.

parameters

  • elementsympy.geometry object

    The element for which the ancestors’ IDs are to be retrieved.

returns - dict : A nested dictionary representing the IDs of the ancestors.

example

If element A has parents B and C, and B has parent D, the method returns: {‘A’: {‘B’: {‘D’: {}}, ‘C’: {}}}

get_element_by_ID(ID: str)

Finds and returns the element with the given ID.

parameters

  • ID : str: The ID of the desired element.

returns

Element or None: The element with the matching ID, or None if no match is found.

point_ID_generator() Iterator[str][source]