Skip to content

Commit

Permalink
Update the dependencies and try setup on github page
Browse files Browse the repository at this point in the history
  • Loading branch information
YuXHe15 committed Aug 15, 2024
1 parent eaccf8a commit eef767b
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 86 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
@@ -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
98 changes: 70 additions & 28 deletions amworkflow/geometry/builtinCAD.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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})
Expand All @@ -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:
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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"]:
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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()
Expand All @@ -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})
Expand All @@ -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.")
Expand Down Expand Up @@ -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(
Expand All @@ -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 = {}
Expand Down
44 changes: 0 additions & 44 deletions docs/conf.py

This file was deleted.

14 changes: 0 additions & 14 deletions docs/index.md

This file was deleted.

9 changes: 9 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit eef767b

Please sign in to comment.