topologicpy 0.4.95__py3-none-any.whl → 0.4.97__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
topologicpy/Graph.py CHANGED
@@ -359,7 +359,11 @@ class Graph:
359
359
  new_vertices.append(nv)
360
360
  new_edge = Edge.ByVertices([new_vertices[0], new_vertices[1]], tolerance=tolerance)
361
361
  if transferEdgeDictionaries == True:
362
- _ = Topology.SetDictionary(new_edge, Topology.Dictionary(edge))
362
+ d = Topology.Dictionary(edge)
363
+ keys = Dictionary.Keys(d)
364
+ if isinstance(keys, list):
365
+ if len(keys) > 0:
366
+ _ = Topology.SetDictionary(new_edge, d)
363
367
  graph_edges.append(new_edge)
364
368
  new_graph = Graph.ByVerticesEdges(graph_vertices, graph_edges)
365
369
  return new_graph
@@ -2303,7 +2307,7 @@ class Graph:
2303
2307
  return [vertices, edges]
2304
2308
 
2305
2309
  def processFace(item):
2306
- from topologic.Face import Face
2310
+ from topologicpy.Face import Face
2307
2311
  topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBRep, tolerance = item
2308
2312
  graph = None
2309
2313
  vertices = []
@@ -3003,27 +3007,91 @@ class Graph:
3003
3007
  return topologic.Graph.ByVerticesEdges(vertices, edges)
3004
3008
 
3005
3009
  @staticmethod
3006
- def Color(graph, vertices=None, key="color", delta=1, tolerance=0.0001):
3010
+ def ChromaticNumber(graph: topologic.Graph, maxColors: int = 3, silent: bool = False):
3007
3011
  """
3008
- Colors the input vertices within the input graph. The saved value is an integer rather than an actual color. See Color.ByValueInRange to convert to an actual color. Any vertices that have been pre-colored will not be affected. See https://en.wikipedia.org/wiki/Graph_coloring.
3012
+ Returns the chromatic number of the input graph. See https://en.wikipedia.org/wiki/Graph_coloring.
3009
3013
 
3010
3014
  Parameters
3011
3015
  ----------
3012
3016
  graph : topologic.Graph
3013
3017
  The input graph.
3014
- vertices : list , optional
3015
- The input list of graph vertices. If no vertices are specified, all vertices in the input graph are colored. The default is None.
3016
- key : str , optional
3017
- The dictionary key to use to save the color information.
3018
- delta : int , optional
3019
- The desired minimum delta value between the assigned colors.
3018
+ maxColors : int , optional
3019
+ The desired maximum number of colors to test against. The default is 3.
3020
+ silent : bool , optional
3021
+ If set to False, error and warning messages are printed. Otherwise, they are not. The default is False.
3022
+
3023
+ Returns
3024
+ -------
3025
+ int
3026
+ The chromatic number of the input graph.
3027
+
3028
+ """
3029
+ # This is based on code from https://www.geeksforgeeks.org/graph-coloring-applications/
3030
+
3031
+ def is_safe(graph, v, color, c):
3032
+ for i in range(len(graph)):
3033
+ if graph[v][i] == 1 and color[i] == c:
3034
+ return False
3035
+ return True
3036
+
3037
+ def graph_coloring(graph, m, color, v):
3038
+ V = len(graph)
3039
+ if v == V:
3040
+ return True
3041
+
3042
+ for c in range(1, m + 1):
3043
+ if is_safe(graph, v, color, c):
3044
+ color[v] = c
3045
+ if graph_coloring(graph, m, color, v + 1):
3046
+ return True
3047
+ color[v] = 0
3048
+
3049
+ return False
3050
+
3051
+ def chromatic_number(graph):
3052
+ V = len(graph)
3053
+ color = [0] * V
3054
+ m = 1
3055
+
3056
+ while True:
3057
+ if graph_coloring(graph, m, color, 0):
3058
+ return m
3059
+ m += 1
3060
+
3061
+ if not isinstance(graph, topologic.Graph):
3062
+ if not silent:
3063
+ print("Graph.ChromaticNumber - Error: The input graph parameter is not a valid graph. Returning None.")
3064
+ return None
3065
+ if maxColors < 1:
3066
+ if not silent:
3067
+ print("Graph.ChromaticNumber - Error: The input maxColors parameter is not a valid positive number. Returning None.")
3068
+ return None
3069
+ adj_matrix = Graph.AdjacencyMatrix(graph)
3070
+ return chromatic_number(adj_matrix)
3071
+
3072
+ @staticmethod
3073
+ def Color(graph, oldKey: str = "color", newKey: str = "color", maxColors: int = None, tolerance: float = 0.0001):
3074
+ """
3075
+ Colors the input vertices within the input graph. The saved value is an integer rather than an actual color. See Color.ByValueInRange to convert to an actual color.
3076
+ Any vertices that have been pre-colored will not be affected. See https://en.wikipedia.org/wiki/Graph_coloring.
3077
+
3078
+ Parameters
3079
+ ----------
3080
+ graph : topologic.Graph
3081
+ The input graph.
3082
+ oldKey : str , optional
3083
+ The existing dictionary key to use to read any pre-existing color information. The default is "color".
3084
+ newKey : str , optional
3085
+ The new dictionary key to use to write out new color information. The default is "color".
3086
+ maxColors : int , optional
3087
+ The desired maximum number of colors to use. If set to None, the chromatic number of the graph is used. The default is None.
3020
3088
  tolerance : float , optional
3021
3089
  The desired tolerance. The default is 0.0001.
3022
3090
 
3023
3091
  Returns
3024
3092
  -------
3025
- list
3026
- The colored list of vertices.
3093
+ topologic.Graph
3094
+ The input graph, but with its vertices colored.
3027
3095
 
3028
3096
  """
3029
3097
  from topologicpy.Vertex import Vertex
@@ -3032,76 +3100,171 @@ class Graph:
3032
3100
  from topologicpy.Topology import Topology
3033
3101
  import math
3034
3102
 
3035
- delta = max(abs(delta), 1) # Ensure that delta is never less than 1
3103
+ def is_safe(v, graph, colors, c):
3104
+ # Check if the color 'c' is safe for the vertex 'v'
3105
+ for i in range(len(graph)):
3106
+ if graph[v][i] and c == colors[i]:
3107
+ return False
3108
+ return True
3036
3109
 
3037
- def satisfiesCondition(i, used_colors, delta):
3038
- if delta == 1:
3039
- return i not in used_colors
3040
- else:
3041
- for j in used_colors:
3042
- if abs(j-i) < delta:
3043
- return False
3110
+ def graph_coloring_util(graph, m, colors, v):
3111
+ # Base case: If all vertices are assigned a color, return true
3112
+ if v == len(graph):
3044
3113
  return True
3045
- def color_graph(graph, vertices, key, delta):
3046
- # Create a dictionary to store the colors of each vertex
3047
- colors = {}
3048
- # Iterate over each vertex in the graph
3049
- for j, vertex in enumerate(vertices):
3050
- d = Topology.Dictionary(vertex)
3051
- color_value = Dictionary.ValueAtKey(d, key)
3052
- if color_value != None:
3053
- colors[j] = color_value
3054
- # Initialize an empty set of used colors
3055
- used_colors = set()
3056
-
3057
- # Iterate over each neighbor of the vertex
3058
- for neighbor in Graph.AdjacentVertices(graph, vertex):
3059
- # If the neighbor has already been colored, add its color to the used colors set
3060
- index = Vertex.Index(neighbor, vertices)
3061
- if index in colors:
3062
- used_colors.add(colors[index])
3063
-
3064
- if color_value == None:
3065
- # Choose the smallest unused color for the vertex
3066
- for i in range(0,int(math.ceil(len(vertices)*int(math.ceil(delta)))), int(math.ceil(delta))):
3067
- #if i not in used_colors:
3068
- if satisfiesCondition(i, used_colors, int(math.ceil(delta))):
3069
- v_d = Topology.Dictionary(vertex)
3070
- if not v_d == None:
3071
- keys = Dictionary.Keys(v_d)
3072
- values = Dictionary.Values(v_d)
3073
- else:
3074
- keys = []
3075
- values = []
3076
- if len(keys) > 0:
3077
- keys.append(key)
3078
- values.append(i)
3079
- else:
3080
- keys = [key]
3081
- values = [i]
3082
- d = Dictionary.ByKeysValues(keys, values)
3083
- vertex = Topology.SetDictionary(vertex, d)
3084
- colors[j] = i
3085
- break
3086
3114
 
3087
- return colors
3115
+ # Try different colors for the current vertex 'v'
3116
+ for c in range(1, m + 1):
3117
+ # Check if assignment of color 'c' to 'v' is fine
3118
+ if is_safe(v, graph, colors, c):
3119
+ colors[v] = c
3120
+
3121
+ # Recur to assign colors to the rest of the vertices
3122
+ if graph_coloring_util(graph, m, colors, v + 1):
3123
+ return True
3124
+
3125
+ # If assigning color 'c' doesn't lead to a solution, remove it
3126
+ colors[v] = 0
3127
+
3128
+ # If no color can be assigned to this vertex, return false
3129
+ return False
3130
+
3131
+ def graph_coloring(graph, m, colors):
3132
+
3133
+ # Call graph_coloring_util() for vertex 0
3134
+ if not graph_coloring_util(graph, m, colors, 0):
3135
+ return None
3136
+ return [x-1 for x in colors]
3088
3137
 
3089
3138
  if not isinstance(graph, topologic.Graph):
3090
3139
  print("Graph.Color - Error: The input graph is not a valid graph. Returning None.")
3091
3140
  return None
3092
- if vertices == None:
3093
- vertices = Graph.Vertices(graph)
3094
- vertices = [v for v in vertices if isinstance(v, topologic.Vertex)]
3095
- if len(vertices) == 0:
3096
- print("Graph.Color - Error: The input list of vertices does not contain any valid vertices. Returning None.")
3097
- return None
3098
- graph_vertices = [Graph.NearestVertex(graph,v) for v in vertices]
3099
- degrees = [Graph.VertexDegree(graph, v) for v in graph_vertices]
3100
- graph_vertices = Helper.Sort(graph_vertices, degrees)
3101
- graph_vertices.reverse()
3102
- _ = color_graph(graph, graph_vertices, key, delta)
3103
- return graph_vertices
3141
+
3142
+ vertices = Graph.Vertices(graph)
3143
+ adj_mat = Graph.AdjacencyMatrix(graph)
3144
+ # Isolate vertices that have pre-existing colors as they shouldn't affect graph coloring.
3145
+ for i, v in enumerate(vertices):
3146
+ d = Topology.Dictionary(v)
3147
+ c = Dictionary.ValueAtKey(d, oldKey)
3148
+ if not c == None:
3149
+ adj_mat[i] = [0] * len(vertices)
3150
+ for j in range(len(adj_mat)):
3151
+ row = adj_mat[j]
3152
+ row[i] = 0
3153
+ temp_graph = Graph.ByAdjacencyMatrix(adj_mat)
3154
+ # If the maximum number of colors are not provided, compute it using the graph's chromatic number.
3155
+ if maxColors == None:
3156
+ maxColors = Graph.ChromaticNumber(temp_graph)
3157
+ print("MaxColors:", maxColors)
3158
+ colors = [0] * len(vertices)
3159
+ colors = graph_coloring(adj_mat, maxColors, colors)
3160
+ print("Colors:", colors)
3161
+ for i, v in enumerate(vertices):
3162
+ d = Topology.Dictionary(v)
3163
+ d = Dictionary.SetValueAtKey(d, newKey, colors[i])
3164
+ v = Topology.SetDictionary(v,d)
3165
+ return graph
3166
+
3167
+ @staticmethod
3168
+ def ContractEdge(graph, edge, vertex=None, tolerance=0.0001):
3169
+ """
3170
+ Contracts the input edge in the input graph into a single vertex. Please note that the dictionary of the edge is transferred to the
3171
+ vertex that replaces it. See https://en.wikipedia.org/wiki/Edge_contraction
3104
3172
 
3173
+ Parameters
3174
+ ----------
3175
+ graph : topologic.Graph
3176
+ The input graph.
3177
+ edge : topologic.Edge
3178
+ The input graph edge that needs to be contracted.
3179
+ vertex : topollogic.Vertex , optional
3180
+ The vertex to replace the contracted edge. If set to None, the centroid of the edge is chosen. The default is None.
3181
+ tolerance : float , optional
3182
+ The desired tolerance. The default is 0.0001.
3183
+
3184
+ Returns
3185
+ -------
3186
+ topologic.Graph
3187
+ The input graph, but with input edge contracted into a single vertex.
3188
+
3189
+ """
3190
+ from topologicpy.Edge import Edge
3191
+ from topologicpy.Topology import Topology
3192
+ from topologicpy.Dictionary import Dictionary
3193
+
3194
+ def OppositeVertex(edge, vertex, tolerance=0.0001):
3195
+ sv = Edge.StartVertex(edge)
3196
+ ev = Edge.EndVertex(edge)
3197
+ d1 = Vertex.Distance(vertex, sv)
3198
+ d2 = Vertex.Distance(vertex, ev)
3199
+ if d1 < d2:
3200
+ return [ev,1]
3201
+ return [sv,0]
3202
+ if not isinstance(graph, topologic.Graph):
3203
+ print("Graph.ContractEdge - Error: The input graph parameter is not a valid graph. Returning None.")
3204
+ return None
3205
+ if not isinstance(edge, topologic.Edge):
3206
+ print("Graph.ContractEdge - Error: The input edge parameter is not a valid edge. Returning None.")
3207
+ return None
3208
+ if vertex == None:
3209
+ vertex = Topology.Centroid(edge)
3210
+ sv = Edge.StartVertex(edge)
3211
+ ev = Edge.EndVertex(edge)
3212
+ vd = Topology.Dictionary(vertex)
3213
+ sd = Topology.Dictionary(sv)
3214
+ dictionaries = []
3215
+ keys = Dictionary.Keys(vd)
3216
+ if isinstance(keys, list):
3217
+ if len(keys) > 0:
3218
+ dictionaries.append(vd)
3219
+ keys = Dictionary.Keys(sd)
3220
+ if isinstance(keys, list):
3221
+ if len(keys) > 0:
3222
+ dictionaries.append(sd)
3223
+ ed = Topology.Dictionary(ev)
3224
+ keys = Dictionary.Keys(ed)
3225
+ if isinstance(keys, list):
3226
+ if len(keys) > 0:
3227
+ dictionaries.append(ed)
3228
+ if len(dictionaries) == 1:
3229
+ vertex = Topology.SetDictionary(vertex, dictionaries[0])
3230
+ elif len(dictionaries) > 1:
3231
+ cd = Dictionary.ByMergedDictionaries(dictionaries)
3232
+ vertex = Topology.SetDictionary(vertex, cd)
3233
+ graph = Graph.RemoveEdge(graph, edge, tolerance=tolerance)
3234
+ graph = Graph.AddVertex(graph, vertex, tolerance=tolerance)
3235
+ adj_edges_sv = Graph.Edges(graph, [sv])
3236
+ adj_edges_ev = Graph.Edges(graph, [ev])
3237
+ new_edges = []
3238
+ for adj_edge_sv in adj_edges_sv:
3239
+ ov, flag = OppositeVertex(adj_edge_sv, sv)
3240
+ if flag == 0:
3241
+ new_edge = Edge.ByVertices([ov, vertex])
3242
+ else:
3243
+ new_edge = Edge.ByVertices([vertex, ov])
3244
+ d = Topology.Dictionary(adj_edge_sv)
3245
+ keys = Dictionary.Keys(d)
3246
+ if isinstance(keys, list):
3247
+ if len(keys) > 0:
3248
+ new_edge = Topology.SetDictionary(new_edge, d)
3249
+ new_edges.append(new_edge)
3250
+ for adj_edge_ev in adj_edges_ev:
3251
+ ov, flag = OppositeVertex(adj_edge_ev, ev)
3252
+ if flag == 0:
3253
+ new_edge = Edge.ByVertices([ov, vertex])
3254
+ else:
3255
+ new_edge = Edge.ByVertices([vertex, ov])
3256
+ d = Topology.Dictionary(adj_edge_ev)
3257
+ keys = Dictionary.Keys(d)
3258
+ if isinstance(keys, list):
3259
+ if len(keys) > 0:
3260
+ new_edge = Topology.SetDictionary(new_edge, d)
3261
+ new_edges.append(new_edge)
3262
+ for new_edge in new_edges:
3263
+ graph = Graph.AddEdge(graph, new_edge, transferVertexDictionaries=True, transferEdgeDictionaries=True, tolerance=tolerance)
3264
+ graph = Graph.RemoveVertex(graph,sv, tolerance=tolerance)
3265
+ graph = Graph.RemoveVertex(graph,ev, tolerance=tolerance)
3266
+ return graph
3267
+
3105
3268
  @staticmethod
3106
3269
  def ClosenessCentrality(graph, vertices=None, tolerance = 0.0001):
3107
3270
  """
topologicpy/Shell.py CHANGED
@@ -146,7 +146,7 @@ class Shell(Topology):
146
146
  iv = Topology.InternalVertex(w1, tolerance=tolerance)
147
147
  flag = False
148
148
  for w2 in faces:
149
- if Face.IsInternal(w2, iv):
149
+ if Vertex.IsInternal(iv, w2):
150
150
  flag = True
151
151
  break;
152
152
  if flag == False:
@@ -285,7 +285,7 @@ class Shell(Topology):
285
285
  return None
286
286
  shell = topologic.Shell.ByFaces(faceList, tolerance)
287
287
  if not isinstance(shell, topologic.Shell):
288
- shell = Topology.SelfMerge(shell)
288
+ shell = Topology.SelfMerge(shell, tolerance=tolerance)
289
289
  if isinstance(shell, topologic.Shell):
290
290
  return shell
291
291
  else:
@@ -520,29 +520,17 @@ class Shell(Topology):
520
520
  flatFace = Topology.Flatten(face, origin=origin, direction=normal)
521
521
  faceVertices = Face.Vertices(face)
522
522
  vertices += faceVertices
523
- # Retrieve the needed transformations
524
- dictionary = Topology.Dictionary(flatFace)
525
- xTran = Dictionary.ValueAtKey(dictionary,"x")
526
- yTran = Dictionary.ValueAtKey(dictionary,"y")
527
- zTran = Dictionary.ValueAtKey(dictionary,"z")
528
- phi = Dictionary.ValueAtKey(dictionary,"phi")
529
- theta = Dictionary.ValueAtKey(dictionary,"theta")
530
523
 
531
524
  # Create a cluster of the input vertices
532
525
  verticesCluster = Cluster.ByTopologies(vertices)
533
526
 
534
527
  # Flatten the cluster using the same transformations
535
- verticesCluster = Topology.Translate(verticesCluster, -xTran, -yTran, -zTran)
536
- verticesCluster = Topology.Rotate(verticesCluster, origin=world_origin, x=0, y=0, z=1, degree=-phi)
537
- verticesCluster = Topology.Rotate(verticesCluster, origin=world_origin, x=0, y=1, z=0, degree=-theta)
528
+ verticesCluster = Topology.Flatten(verticesCluster, origin=origin, direction=normal)
538
529
 
539
530
  vertices = Cluster.Vertices(verticesCluster)
540
- tempFlatVertices = []
541
531
  points = []
542
532
  for v in vertices:
543
- tempFlatVertices.append(Vertex.ByCoordinates(Vertex.X(v), Vertex.Y(v), 0))
544
533
  points.append([Vertex.X(v), Vertex.Y(v)])
545
- #flatVertices = tempFlatVertices
546
534
  delaunay = SCIDelaunay(points)
547
535
  simplices = delaunay.simplices
548
536
 
@@ -569,9 +557,7 @@ class Shell(Topology):
569
557
  ibList = [Face.ByWire(w) for w in wires]
570
558
  cluster = Cluster.ByTopologies(ibList)
571
559
  shell = Topology.Difference(shell, cluster)
572
- shell = Topology.Rotate(shell, origin=world_origin, x=0, y=1, z=0, degree=theta)
573
- shell = Topology.Rotate(shell, origin=world_origin, x=0, y=0, z=1, degree=phi)
574
- shell = Topology.Translate(shell, xTran, yTran, zTran)
560
+ shell = Topology.Unflatten(shell, origin=origin, direction=normal)
575
561
  return shell
576
562
 
577
563
  @staticmethod
@@ -652,47 +638,6 @@ class Shell(Topology):
652
638
  _ = shell.Faces(None, faces)
653
639
  return faces
654
640
 
655
- @staticmethod
656
- def IsInside(shell: topologic.Shell, vertex: topologic.Vertex, tolerance: float = 0.0001) -> bool:
657
- """
658
- DEPRECATED METHOD. DO NOT USE. INSTEAD USE Shell.IsInternal.
659
- """
660
- print("Shell.IsInside - Warning: Deprecated method. This method will be removed in the future. Instead, use Cell.IsInternal.")
661
- return Shell.IsInternal(shell=shell, vertex=vertex, tolerance=tolerance)
662
-
663
- @staticmethod
664
-
665
- def IsInternal(shell: topologic.Shell, vertex: topologic.Vertex, tolerance: float = 0.0001) -> bool:
666
- """
667
- Returns True if the input vertex is an internal vertex of the input shell. Returns False otherwise. Intenral is defined as being inside one of the shell's faces.
668
-
669
- Parameters
670
- ----------
671
- shell : topologic.Shell
672
- The input shell.
673
- vertex : topologic.Vertex
674
- The input vertex.
675
- tolerance : float , optional
676
- The desired tolerance. The default is 0.0001.
677
-
678
- Returns
679
- -------
680
- bool
681
- Returns True if the input vertex is inside the input shell. Returns False otherwise.
682
-
683
- """
684
-
685
- from topologicpy.Face import Face
686
- if not isinstance(shell, topologic.Shell):
687
- return None
688
- if not isinstance(vertex, topologic.Vertex):
689
- return None
690
- faces = Shell.Faces(shell)
691
- for f in faces:
692
- if Face.IsInternal(face=f, vertex=vertex, tolerance=tolerance):
693
- return True
694
- return False
695
-
696
641
  @staticmethod
697
642
  def IsOnBoundary(shell: topologic.Shell, vertex: topologic.Vertex, tolerance: float = 0.0001) -> bool:
698
643
  """
@@ -714,47 +659,21 @@ class Shell(Topology):
714
659
 
715
660
  """
716
661
 
717
- from topologicpy.Wire import Wire
662
+ from topologicpy.Vertex import Vertex
718
663
 
719
664
  if not isinstance(shell, topologic.Shell):
720
665
  return None
721
666
  if not isinstance(vertex, topologic.Vertex):
722
667
  return None
723
668
  boundary = Shell.ExternalBoundary(shell, tolerance=tolerance)
724
- if Wire.IsInternal(wire=boundary, vertex=vertex, tolerance=tolerance):
669
+ if Vertex.IsInternal(vertex, boundary, tolerance=tolerance):
725
670
  return True
726
671
  internal_boundaries = Shell.InternalBoundaries(shell, tolerance=tolerance)
727
672
  for ib in internal_boundaries:
728
- if Wire.IsInternal(wire=ib, vertex=vertex, tolerance=tolerance):
673
+ if Vertex.IsInternal(vertex, ib, tolerance=tolerance):
729
674
  return True
730
675
  return False
731
676
 
732
- @staticmethod
733
- def IsOutside(shell: topologic.Shell, vertex: topologic.Vertex, tolerance: float = 0.0001) -> bool:
734
- """
735
- Returns True if the input vertex is outside the input shell. Returns False otherwise. Outside is defined as being outside all of the shell's faces
736
-
737
- Parameters
738
- ----------
739
- shell : topologic.Shell
740
- The input shell.
741
- vertex : topologic.Vertex
742
- The input vertex.
743
- tolerance : float , optional
744
- The desired tolerance. The default is 0.0001.
745
-
746
- Returns
747
- -------
748
- bool
749
- Returns True if the input vertex is inside the input shell. Returns False otherwise.
750
-
751
- """
752
- if not isinstance(shell, topologic.Shell):
753
- return None
754
- if not isinstance(vertex, topologic.Vertex):
755
- return None
756
- return not Shell.IsInternal(shell=shell, vertex=vertex, tolerance=tolerance)
757
-
758
677
  @staticmethod
759
678
  def HyperbolicParaboloidRectangularDomain(origin: topologic.Vertex = None, llVertex: topologic.Vertex = None, lrVertex: topologic.Vertex =None, ulVertex: topologic.Vertex =None, urVertex: topologic.Vertex = None,
760
679
  uSides: int = 10, vSides: int = 10, direction: list = [0,0,1], placement: str = "center", tolerance: float = 0.0001) -> topologic.Shell:
@@ -1372,13 +1291,13 @@ class Shell(Topology):
1372
1291
  origin = Topology.Centroid(face)
1373
1292
  normal = Face.Normal(face)
1374
1293
  flat_face = Topology.Flatten(face, origin=origin, direction=normal)
1375
- d = Topology.Dictionary(flat_face)
1376
1294
  roof = Wire.Roof(flat_face, degree=degree, tolerance=tolerance)
1377
1295
  if not roof:
1378
1296
  return None
1379
1297
  shell = Shell.Skeleton(flat_face, tolerance=tolerance)
1298
+ print(shell)
1380
1299
  faces = Shell.Faces(shell)
1381
-
1300
+ Topology.Show(shell)
1382
1301
  if not faces:
1383
1302
  return None
1384
1303
  triangles = []
@@ -1423,14 +1342,7 @@ class Shell(Topology):
1423
1342
  shell = Topology.RemoveCoplanarFaces(shell, epsilon=epsilon, tolerance=tolerance)
1424
1343
  except:
1425
1344
  pass
1426
- xTran = Dictionary.ValueAtKey(d,"x")
1427
- yTran = Dictionary.ValueAtKey(d,"y")
1428
- zTran = Dictionary.ValueAtKey(d,"z")
1429
- phi = Dictionary.ValueAtKey(d,"phi")
1430
- theta = Dictionary.ValueAtKey(d,"theta")
1431
- shell = Topology.Rotate(shell, origin=Vertex.Origin(), x=0, y=1, z=0, degree=theta)
1432
- shell = Topology.Rotate(shell, origin=Vertex.Origin(), x=0, y=0, z=1, degree=phi)
1433
- shell = Topology.Translate(shell, xTran, yTran, zTran)
1345
+ #shell = Topology.Unflatten(shell, origin=origin, direction=normal)
1434
1346
  return shell
1435
1347
 
1436
1348
  @staticmethod
@@ -1689,7 +1601,7 @@ class Shell(Topology):
1689
1601
  faces = Topology.Faces(result)
1690
1602
  final_faces = []
1691
1603
  for face in faces:
1692
- if not Face.IsInternal(face, v, tolerance=0.01):
1604
+ if not Vertex.IsInternal(v, face, tolerance=0.01):
1693
1605
  final_faces.append(face)
1694
1606
  final_result = Shell.ByFaces(final_faces, tolerance=tolerance)
1695
1607
  return final_result
@@ -1759,26 +1671,25 @@ class Shell(Topology):
1759
1671
  origin = Topology.Centroid(face)
1760
1672
  normal = Face.Normal(face)
1761
1673
  flatFace = Topology.Flatten(face, origin=origin, direction=normal)
1762
- # Retrieve the needed transformations
1763
- dictionary = Topology.Dictionary(flatFace)
1764
- xTran = Dictionary.ValueAtKey(dictionary,"x")
1765
- yTran = Dictionary.ValueAtKey(dictionary,"y")
1766
- zTran = Dictionary.ValueAtKey(dictionary,"z")
1767
- phi = Dictionary.ValueAtKey(dictionary,"phi")
1768
- theta = Dictionary.ValueAtKey(dictionary,"theta")
1769
-
1770
- # Create a Vertex at the world's origin (0,0,0)
1771
- world_origin = Vertex.ByCoordinates(0,0,0)
1674
+ eb = Face.ExternalBoundary(flatFace)
1675
+ ibList = Face.InternalBoundaries(flatFace)
1676
+ temp_verts = Topology.Vertices(eb)
1677
+ new_verts = [Vertex.ByCoordinates(Vertex.X(v), Vertex.Y(v), 0) for v in temp_verts]
1678
+ eb = Wire.ByVertices(new_verts, close=True)
1679
+ new_ibList = []
1680
+ for ib in ibList:
1681
+ temp_verts = Topology.Vertices(ib)
1682
+ new_verts = [Vertex.ByCoordinates(Vertex.X(v), Vertex.Y(v), 0) for v in temp_verts]
1683
+ new_ibList.append(Wire.ByVertices(new_verts, close=True))
1684
+ flatFace = Face.ByWires(eb, new_ibList)
1772
1685
 
1773
1686
  # Create a cluster of the input vertices
1774
1687
  verticesCluster = Cluster.ByTopologies(vertices)
1775
1688
 
1776
1689
  # Flatten the cluster using the same transformations
1777
- verticesCluster = Topology.Translate(verticesCluster, -xTran, -yTran, -zTran)
1778
- verticesCluster = Topology.Rotate(verticesCluster, origin=world_origin, x=0, y=0, z=1, degree=-phi)
1779
- verticesCluster = Topology.Rotate(verticesCluster, origin=world_origin, x=0, y=1, z=0, degree=-theta)
1780
-
1781
- flatVertices = Cluster.Vertices(verticesCluster)
1690
+ verticesCluster = Topology.Flatten(verticesCluster, origin=origin, direction=normal)
1691
+ flatVertices = Topology.Vertices(verticesCluster)
1692
+ flatVertices = [Vertex.ByCoordinates(Vertex.X(v), Vertex.Y(v), 0) for v in flatVertices]
1782
1693
  points = []
1783
1694
  for flatVertex in flatVertices:
1784
1695
  points.append([flatVertex.X(), flatVertex.Y()])
@@ -1814,14 +1725,20 @@ class Shell(Topology):
1814
1725
  if len(region) > 1 and not -1 in region:
1815
1726
  for v in region:
1816
1727
  tempWire.append(Vertex.ByCoordinates(voronoiVertices[v].X(), voronoiVertices[v].Y(),0))
1728
+ temp_verts = []
1729
+ for v in tempWire:
1730
+ if len(temp_verts) == 0:
1731
+ temp_verts.append(v)
1732
+ elif Vertex.Index(v, temp_verts) == None:
1733
+ temp_verts.append(v)
1734
+ tempWire = temp_verts
1735
+ temp_w = Wire.ByVertices(tempWire, close=True)
1817
1736
  faces.append(Face.ByWire(Wire.ByVertices(tempWire, close=True), tolerance=tolerance))
1818
1737
  shell = Shell.ByFaces(faces, tolerance=tolerance)
1819
1738
  edges = Shell.Edges(shell)
1820
1739
  edgesCluster = Cluster.ByTopologies(edges)
1821
- shell = Topology.Boolean(flatFace,edgesCluster, operation="slice", tolerance=tolerance)
1822
- shell = Topology.Rotate(shell, origin=world_origin, x=0, y=1, z=0, degree=theta)
1823
- shell = Topology.Rotate(shell, origin=world_origin, x=0, y=0, z=1, degree=phi)
1824
- shell = Topology.Translate(shell, xTran, yTran, zTran)
1740
+ shell = Topology.Slice(flatFace,edgesCluster, tolerance=tolerance)
1741
+ shell = Topology.Unflatten(shell, origin=origin, direction=normal)
1825
1742
  return shell
1826
1743
 
1827
1744
  @staticmethod