Skip to content

Commit

Permalink
Added Graph.ConnectedComponents. Many bug fixes. Bumped to v0.7.88
Browse files Browse the repository at this point in the history
  • Loading branch information
wassimj committed Dec 19, 2024
1 parent 46d20bf commit d11f603
Show file tree
Hide file tree
Showing 7 changed files with 497 additions and 151 deletions.
299 changes: 233 additions & 66 deletions notebooks/GraphByIFCPath.ipynb

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions notebooks/Isovist_Metrics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -395,7 +395,6 @@
" for edge in edges:\n",
" d = Topology.Dictionary(edge)\n",
" d = Dictionary.SetValueAtKey(d, \"edgeWidth\", 0.001)\n",
"\n",
" edge = Topology.SetDictionary(edge, d)\n",
"Topology.Show(r, r1, r2, triangles,v, vertexSizeKey=\"vertexSize\", edgeColor=\"black\",\n",
" edgeColorKey=\"edgeColor\", edgeWidth=1, edgeWidthKey=\"edgeWidth\",\n",
Expand Down
10 changes: 7 additions & 3 deletions src/topologicpy/Cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ def InternalBoundaries(cell) -> list:
return shells

@staticmethod
def InternalVertex(cell, tolerance: float = 0.0001):
def InternalVertex(cell, tolerance: float = 0.0001, silent: bool = False):
"""
Creates a vertex that is guaranteed to be inside the input cell.
Expand All @@ -1481,6 +1481,8 @@ def InternalVertex(cell, tolerance: float = 0.0001):
The input cell.
tolerance : float , optional
The desired tolerance. The default is 0.0001.
silent : bool , optional
If set to True, no error and warning messages are printed. Otherwise, they are. The default is False.
Returns
-------
Expand All @@ -1491,12 +1493,14 @@ def InternalVertex(cell, tolerance: float = 0.0001):
from topologicpy.Topology import Topology

if not Topology.IsInstance(cell, "Cell"):
print("Cell.InternalVertex - Error: The input cell parameter is not a valid topologic cell. Returning None.")
if not silent:
print("Cell.InternalVertex - Error: The input cell parameter is not a valid topologic cell. Returning None.")
return None
try:
return topologic.CellUtility.InternalVertex(cell, tolerance) # Hook to Core
except:
print("Cell.InternalVertex - Error: Could not create an internal vertex. Returning None.")
if not silent:
print("Cell.InternalVertex - Error: Could not create an internal vertex. Returning None.")
return None

@staticmethod
Expand Down
59 changes: 47 additions & 12 deletions src/topologicpy/Face.py
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ def InternalBoundaries(face) -> list:
return list(wires)

@staticmethod
def InternalVertex(face, tolerance: float = 0.0001):
def InternalVertex(face, tolerance: float = 0.0001, silent: bool = False):
"""
Creates a vertex guaranteed to be inside the input face.
Expand All @@ -1528,29 +1528,62 @@ def InternalVertex(face, tolerance: float = 0.0001):
The input face.
tolerance : float , optional
The desired tolerance. The default is 0.0001.
silent : bool , optional
If set to True, no error and warning messages are printed. Otherwise, they are. The default is False.
Returns
-------
topologic_core.Vertex
The created vertex.
"""
def get_uv_radially():
"""
Generate the points of a grid with a given size n, sorted radially from the center to the periphery.
n should be an odd number, ensuring that there's a center point (0, 0).
Args:
n (int): The size of the grid. It should be odd for a clear center point.
Returns:
list: A list of tuples (x, y) sorted by radial distance from the center (0, 0).
"""
import math

points = []
n = 100
# Iterate over the grid, ranging from -n//2 to n//2
for x in range(-n//2, n//2 + 1):
for y in range(-n//2, n//2 + 1):
points.append((x, y))

# Sort points by their Euclidean distance from the center (0, 0)
points.sort(key=lambda point: math.sqrt(point[0]**2 + point[1]**2))
return_points = []
for p in points:
new_p = ((p[0]+50)*0.01, (p[1]+50)*0.01)
return_points.append(new_p)
return return_points

from topologicpy.Vertex import Vertex
from topologicpy.Topology import Topology

if not Topology.IsInstance(face, "Face"):
return None
v = Topology.Centroid(face)
if Vertex.IsInternal(v, face, tolerance=tolerance):
return v
l = [0.4,0.6,0.3,0.7,0.2,0.8,0.1,0.9]
for u in l:
for v in l:
v = Face.VertexByParameters(face, u, v)
if Vertex.IsInternal(v, face, tolerance=tolerance):
return v
v = topologic.FaceUtility.InternalVertex(face, tolerance) # Hook to Core
return v
vert = Topology.Centroid(face)
if Vertex.IsInternal(vert, face, tolerance=tolerance):
return vert
uv_list = get_uv_radially()
for uv in uv_list:
u, v = uv
vert = Face.VertexByParameters(face, u, v)
if Vertex.IsInternal(vert, face, tolerance=tolerance):
return vert
if not silent:
print("Face.InternalVertex - Warning: Could not find an internal vertex. Returning the first vertex of the face.")
vert = Topology.Vertices(face)[0]
#v = topologic.FaceUtility.InternalVertex(face, tolerance) # Hook to Core
return vert

@staticmethod
def Invert(face, tolerance: float = 0.0001):
Expand Down Expand Up @@ -2365,6 +2398,8 @@ def NormalEdge(face, length: float = 1.0, tolerance: float = 0.0001, silent: boo
The desired length of the normal edge. The default is 1.
tolerance : float , optional
The desired tolerance. The default is 0.0001.
silent : bool , optional
If set to True, no error and warning messages are printed. Otherwise, they are. The default is False.
Returns
-------
Expand Down
Loading

0 comments on commit d11f603

Please sign in to comment.