fabex.utilities.compare_utils#

Fabex ‘compare_utils.py’ © 2012 Vilem Novak

Functions#

compare_z_level(x)

overlaps(bb1, bb2)

Determine if one bounding box is a child of another.

get_vector_right(lastv, verts)

Get the index of the vector that is most to the right based on angle.

unique(L)

Return a list of unhashable elements in L, but without duplicates.

check_equal(lst)

Checks if First and Last List items are Equal

angle(a, b)

Returns angle of a vector

angle_difference(a, b, c)

Returns the difference between two lines with three points

point_on_line(a, b, c, tolerance)

Determine if the angle between two vectors is within a specified

Module Contents#

compare_z_level(x)[source]#
overlaps(bb1, bb2)[source]#

Determine if one bounding box is a child of another.

This function checks if the first bounding box (bb1) is completely contained within the second bounding box (bb2). It does this by comparing the coordinates of both bounding boxes to see if all corners of bb1 are within the bounds of bb2.

Parameters:
  • bb1 (tuple) – A tuple representing the coordinates of the first bounding box in the format (x_min, y_min, x_max, y_max).

  • bb2 (tuple) – A tuple representing the coordinates of the second bounding box in the format (x_min, y_min, x_max, y_max).

Returns:

True if bb1 is a child of bb2, otherwise False.

Return type:

bool

get_vector_right(lastv, verts)[source]#

Get the index of the vector that is most to the right based on angle.

This function calculates the angle between a reference vector (formed by the last two vectors in lastv) and each vector in the verts list. It identifies the vector that has the smallest angle with respect to the reference vector, indicating that it is the most rightward vector in relation to the specified direction.

Parameters:
  • lastv (list) – A list containing two vectors, where each vector is represented as a tuple or list of coordinates.

  • verts (list) – A list of vectors represented as tuples or lists of coordinates.

Returns:

The index of the vector in verts that is most to the right

based on the calculated angle.

Return type:

int

unique(L)[source]#

Return a list of unhashable elements in L, but without duplicates.

This function processes a list of lists, specifically designed to handle unhashable elements. It sorts the input list and removes duplicates by comparing the elements based on their coordinates. The function counts the number of duplicate vertices and the number of collinear points along the Z-axis.

Parameters:

L (list) – A list of lists, where each inner list represents a point

Returns:

A tuple containing two integers:
  • The first integer represents the count of duplicate vertices.

  • The second integer represents the count of Z-collinear points.

Return type:

tuple

check_equal(lst)[source]#

Checks if First and Last List items are Equal

Parameters:

lst (list) – list of points to check

angle(a, b)[source]#

Returns angle of a vector

Parameters:
  • a (tuple) – point a x,y coordinates

  • b (tuple) – point b x,y coordinates

angle_difference(a, b, c)[source]#

Returns the difference between two lines with three points

Parameters:
  • a (tuple) – point a x,y coordinates

  • b (tuple) – point b x,y coordinates

  • c (tuple) – point c x,y coordinates

point_on_line(a, b, c, tolerance)[source]#

Determine if the angle between two vectors is within a specified tolerance.

This function checks if the angle formed by two vectors, defined by points b and c relative to point a, is less than or equal to a given tolerance. It converts the points into vectors, calculates the dot product, and then computes the angle between them using the arccosine function. If the angle exceeds the specified tolerance, the function returns False; otherwise, it returns True.

Parameters:
  • a (np.ndarray) – The origin point as a vector.

  • b (np.ndarray) – The first point as a vector.

  • c (np.ndarray) – The second point as a vector.

  • tolerance (float) – The maximum allowable angle (in degrees) between the vectors.

Returns:

True if the angle between vectors b and c is within the specified

tolerance, False otherwise.

Return type:

bool