Source code for viiapackage.strengthening.helper_functions.sort_openings_by_axis

### ===================================================================================================================
###  viia_sort_openings
### ===================================================================================================================
# Copyright ©2026 Haskoning Nederland B.V.
# For use by VIIA

### ===================================================================================================================
###  1. Import modules
### ===================================================================================================================

# References for functions and classes in the haskoning-datafusr-py-base package
from haskoning_datafusr_py_base.math import dot_product_vector, unit_vector, vector_between_points


### ===================================================================================================================
###  2. Function to sort the openings
### ===================================================================================================================

[docs]def viia_sort_openings(openings, axis): """ This function sorts a list of openings with respect to a defined axis. It returns the sorted list that contains the extreme coordinates of the openings in the direction of the provided axis. Input: - openings (list with lists with lists of 3 floats) - localAxis (list of 3 floats) Output: - Returns a list with lists of lists of 3 floats For example: >>> viia_sort_openings([[[2.0, 0.0, 0.0], [1.0, 0.0, 0.0]], [[3.8, 0.0, 0.0], [3.0, 0.0, 0.0]]], [-1.0, 0.0, 0.0]) Returns the list: [[[3.8, 0.0, 0.0], [3.0, 0.0, 0.0]], [[2.0, 0.0, 0.0], [1.0, 0.0, 0.0]]] """ # Sort openings with respect to the localXAxis if len(openings) > 1: # Create new list sorted_openings and add first opening to this list sorted_openings = [openings[0]] # Iterate through other original (not sorted) openings for i in range(1, len(openings)): opening = openings[i] # Iterate through sorted_openings for j in range(len(sorted_openings)): sorted_opening = sorted_openings[j] # Compute unit vector between first points of sorted_opening and opening if not sorted_opening[0] == opening[0]: uv = unit_vector(a=vector_between_points(point1=(sorted_opening[0]), point2=opening[0])) elif not sorted_opening[1] == opening[1]: uv = unit_vector(a=vector_between_points(point1=(sorted_opening[1]), point2=opening[1])) else: uv = [0.0, 0.0, 0.0] # If the dot product is -1, opening lies before sorted_opening on the localXAxis, # insert at current index j if dot_product_vector(a=axis, b=uv) == -1: sorted_openings.insert(j, opening) break # If last sorted_opening in list, opening lies behind all sorted_openings on the localXAxis, # append at end of the list elif j == len(sorted_openings) - 1: sorted_openings.append(opening) break else: # Only one opening, sorted_openings equal to openings sorted_openings = openings return sorted_openings
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================