From eef767bf3ebb1c6d11d4cce3bae6728e80eb336e Mon Sep 17 00:00:00 2001 From: Yuxiang Date: Thu, 15 Aug 2024 18:42:18 +0200 Subject: [PATCH] Update the dependencies and try setup on github page --- .github/workflows/build_docs.yml | 56 ++++++++++++++++++ amworkflow/geometry/builtinCAD.py | 98 ++++++++++++++++++++++--------- docs/conf.py | 44 -------------- docs/index.md | 14 ----- environment.yml | 9 +++ 5 files changed, 135 insertions(+), 86 deletions(-) create mode 100644 .github/workflows/build_docs.yml delete mode 100644 docs/conf.py delete mode 100644 docs/index.md diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml new file mode 100644 index 0000000..140a39b --- /dev/null +++ b/.github/workflows/build_docs.yml @@ -0,0 +1,56 @@ +on: + push: + branches-ignore: + pull_request: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +env: + CACHE_NUMBER: 1 # increase to reset cache manually + +jobs: + tests: + runs-on: ubuntu-latest + + steps: + - name: checkout repo content + uses: actions/checkout@v2 + - name: Setup Mambaforge + uses: conda-incubator/setup-miniconda@v2 + with: + miniforge-variant: Mambaforge + miniforge-version: latest + activate-environment: amworkflow + use-mamba: true + + - name: Set cache date + run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV + + - uses: actions/cache@v2 + with: + path: "/usr/share/miniconda3/envs/amworkflow" + key: conda-${{ hashFiles('environment.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }} + id: cache + + - name: Update environment + run: mamba env update -n amworkflow -f environment.yml + if: steps.cache.outputs.cache-hit != 'true' + + - name: Install package + run: git clone https://github.com/tpaviot/pythonocc-utils.git && pip install ./pythonocc-utils + + - name: Install amworkflow + run: python -m pip install . + + - name: Build documentation + run: | + cd docs + make html + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs/_build/html \ No newline at end of file diff --git a/amworkflow/geometry/builtinCAD.py b/amworkflow/geometry/builtinCAD.py index 4090c5f..f3451e6 100644 --- a/amworkflow/geometry/builtinCAD.py +++ b/amworkflow/geometry/builtinCAD.py @@ -1214,6 +1214,16 @@ def project_array(array: np.ndarray, direct: np.ndarray) -> np.ndarray: def shortest_distance_point_line( line: Union[list, Segment, np.ndarray], p: Union[list, Segment, np.ndarray] ): + """ + Calculate the shortest distance between a point and a line (segment). + + :param line: The line (segment) to be examined. + :type line: Union[list, Segment, np.ndarray] + :param p: The point to be examined. + :type p: Union[list, Segment, np.ndarray] + :return: The relative coordinate of the point on the line (segment) and The shortest distance between the point and the line (segment). + :rtype: Tuple[Union[int, float], float] + """ if isinstance(line, Segment): pt1, pt2 = line.raw_value p = p.value @@ -1807,10 +1817,11 @@ def __init__(self, coords: list, th: float, height: float, is_close: bool = True def init_points(self, points: list, prop: dict = None) -> None: """ Initialize the points of the wall. The property of the points can be enriched by the prop parameter. - :points: list of coordinates - :type: list - :prop: dict of properties - :type: dict + + :param points: list of coordinates + :type points: list + :param prop: dict of properties + :type prop: dict """ for i, p in enumerate(points): if not isinstance(p, Pnt): @@ -1851,10 +1862,11 @@ def update_index_component(self) -> None: def enrich_component(self, component: TopoObj, prop: dict = None) -> TopoObj: """ Enrich the property of the component - :component: The component to be enriched - :type: TopoObj - :prop: The property to be enriched - :type: dict""" + + :param component: The component to be enriched + :type component: TopoObj + :param prop: The property to be enriched + :type prop: dict""" if not isinstance(component, TopoObj): raise ValueError("Component must be a TopoObj") component.enrich_property({"CWBP": prop}) @@ -1863,20 +1875,22 @@ def enrich_component(self, component: TopoObj, prop: dict = None) -> TopoObj: def compute_index(self, ind, length) -> int: """ Compute the index of the component. The index will be periodic if it is out of the range. - :ind: The index - :type: int - :length: The length of the component - :type: int + + :param ind: The index + :type ind: int + :param length: The length of the component + :type length: int """ return ind % length if ind > 0 else -(-ind % length) def compute_support_vector(self, seg1: Segment, seg2: Segment = None) -> tuple: """ Compute the support vector of the wall. The support vector is the vector perpendicular to the wall. Specifically in this case it will always on the left side of the wall. - :seg1: The first segment - :type: Segment - :seg2: The second segment - :type: Segment + + :param seg1: The first segment + :type seg1: Segment + :param seg2: The second segment + :type seg2: Segment """ lit_vector = get_literal_vector(seg1.vector, True) if seg2 is None: @@ -1981,14 +1995,15 @@ def update_digraph( ) -> None: """ Update the directed graph - :start_node: The start node - :type: int - :end_node: The end node - :type: int - :insert_node: The inserting node - :type: int - :build_new_edge: Whether to build a new edge - :type: bool + + :param start_node: The start node + :type start_node: int + :param end_node: The end node + :type end_node: int + :param insert_node: The inserting node + :type insert_node: int + :param build_new_edge: Whether to build a new edge + :type build_new_edge: bool """ self.update_index_component() points = { @@ -2040,10 +2055,11 @@ def update_digraph( def delete_digraph(self, start_node: int, end_node: int) -> None: """ Delete the directed graph - :start_node: The start node - :type: int - :end_node: The end node - :type: int + + :param start_node: The start node + :type start_node: int + :param end_node: The end node + :type end_node: int """ if start_node in self.digraph_points: if end_node in self.digraph_points[start_node]: @@ -2106,6 +2122,9 @@ def find_overlap_node_on_edge(self) -> None: self.edges_to_be_modified[pair[0]].append(pair[1]) def modify_edge(self): + """ + Modify the edge based on the overlap nodes. + """ self.update_index_component() edges = {} for i in self.index_components["segment"]: @@ -2142,6 +2161,8 @@ def modify_edge(self): # self.imaginary_segments.update({seg.id: seg}) def check_pnt_in_wall(self): + """ + Check if the points are in the wall.""" self.update_index_component() edges = {} in_wall_points = [] @@ -2184,6 +2205,8 @@ def check_pnt_in_wall(self): logger.debug(f"digraph:{self.digraph_points}") def check_segment_intersect_wall(self): + """ + Check if the segments intersect with the wall.""" self.update_index_component() edges = {} for i, seg in self.digraph_points.items(): @@ -2224,6 +2247,11 @@ def check_segment_intersect_wall(self): break def postprocessing(self): + """ + Postprocessing the wall. + Update the digraph of the wall. + Find the proper loops of the wall. + """ self.update_index_component() self.check_pnt_in_wall() self.check_segment_intersect_wall() @@ -2249,6 +2277,7 @@ def postprocessing(self): logger.debug(f"result loops:{self.result_loops}") def rank_result_loops(self): + """Rank the result loops based on the area of the loops.""" points = {} for i in get_from_source(obj_type="point"): points.update({i.id: i}) @@ -2268,6 +2297,7 @@ def rank_result_loops(self): return self.result_loops def Shape(self): + """Create the shape of the wall.""" loop_r = self.rank_result_loops() if not ENABLE_OCC: raise Exception("OpenCASCADE is not enabled.") @@ -2301,6 +2331,7 @@ def Shape(self): return poly def visualize_graph(self): + """Visualize the graph of the wall.""" layout = nx.spring_layout(self.G) # Draw the nodes and edges nx.draw( @@ -2320,6 +2351,17 @@ def visualize( display_central_path: bool = False, all_polygons: bool = False, ): + """ + Visualize the wall. + + :param display_polygon: Whether to display the polygons, defaults to True + :type display_polygon: bool, optional + :param display_central_path: Whether to display the central path, defaults to False + :type display_central_path: bool, optional + :param all_polygons: Whether to display all polygons, defaults to False + :type all_polygons: bool, optional + + """ # Extract the x and y coordinates and IDs a = self.index_components["point"] components = {} diff --git a/docs/conf.py b/docs/conf.py deleted file mode 100644 index 701b29a..0000000 --- a/docs/conf.py +++ /dev/null @@ -1,44 +0,0 @@ -# Configuration file for the Sphinx documentation builder. -# -# For the full list of built-in configuration values, see the documentation: -# https://www.sphinx-doc.org/en/master/usage/configuration.html - -# -- Project information ----------------------------------------------------- -# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information -import os -import sys - -sys.path.insert(0, os.path.abspath("../amworkflow")) - -project = "amworkflow" -copyright = "2024, Yuxiang He, Annika Robens-Radermacher" -author = "Yuxiang He, Annika Robens-Radermacher" -release = "1.0" - -# -- General configuration --------------------------------------------------- -# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration - -extensions = [ - "myst_parser", - "sphinx.ext.autodoc", - "sphinx.ext.napoleon", - "sphinx.ext.mathjax", - "sphinx.ext.viewcode", -] - -templates_path = ["_templates"] -exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] - - -# -- Options for HTML output ------------------------------------------------- -# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output - -# html_theme = 'alabaster' -html_static_path = ["_static"] - -html_theme = "sphinx_rtd_theme" - -source_suffix = { - ".rst": "restructuredtext", - ".md": "markdown", -} diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index 7585988..0000000 --- a/docs/index.md +++ /dev/null @@ -1,14 +0,0 @@ -# 项目文档 - -## 模块介绍 - -这里是项目模块的详细介绍。 - -```{math} -e^{i\pi} + 1 = 0 -``` - -```{eval-rst} -.. automodule:: amworkflow.geometry.builtinCAD - :members: -``` diff --git a/environment.yml b/environment.yml index 763881a..2efae0c 100644 --- a/environment.yml +++ b/environment.yml @@ -24,3 +24,12 @@ dependencies: - sphinx - sqlalchemy - stl-to-voxel + - sphinx-autobuild + - sphinx-rtd-theme + - sphinxcontrib-applehelp + - sphinxcontrib-devhelp + - sphinxcontrib-htmlhelp + - sphinxcontrib-jquery + - sphinxcontrib-jsmath + - sphinxcontrib-qthelp + - sphinxcontrib-serializinghtml \ No newline at end of file