topologicpy 0.7.2__py3-none-any.whl → 0.7.3__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/Edge.py CHANGED
@@ -635,25 +635,45 @@ class Edge():
635
635
  if Edge.Length(edgeB) < tolerance:
636
636
  print("Edge.IsCollinear - Error: The length of edgeB is less than the tolerance. Returning None")
637
637
  return None
638
- # Calculate coefficients A, B, C from edgeA
638
+
639
+ # Get start and end points of the first edge
639
640
  start_a = Edge.StartVertex(edgeA)
640
641
  end_a = Edge.EndVertex(edgeA)
641
- A = Vertex.Y(end_a, mantissa=mantissa) - Vertex.Y(start_a, mantissa=mantissa)
642
- B = -(Vertex.X(end_a, mantissa=mantissa) - Vertex.X(start_a, mantissa=mantissa))
643
- norm = np.sqrt(A ** 2 + B ** 2)
644
- A /= norm
645
- B /= norm
646
- C = -(A * Vertex.X(start_a, mantissa=mantissa) + B * Vertex.Y(start_a, mantissa=mantissa))
647
-
648
- # Calculate perpendicular distance for start vertex of edgeB
649
- start_b = Edge.StartVertex(edgeB)
650
- x0, y0 = Vertex.X(start_b, mantissa=mantissa), Vertex.Y(start_b, mantissa=mantissa)
651
- distance_start = abs(A * x0 + B * y0 + C)
642
+ start_a_coords = np.array([Vertex.X(start_a), Vertex.Y(start_a), Vertex.Z(start_a)])
643
+ end_a_coords = np.array(
644
+ [Vertex.X(end_a, mantissa=mantissa), Vertex.Y(end_a, mantissa=mantissa), Vertex.Z(end_a, mantissa=mantissa)])
645
+
646
+ # Calculate the direction vector of the first edge
647
+ direction_a = end_a_coords - start_a_coords
648
+
649
+ # Normalize the direction vector
650
+ norm_a = np.linalg.norm(direction_a)
651
+ if norm_a == 0:
652
+ print("Edge.IsCollinear - Error: Division by zero. Returning None.")
653
+ return None
654
+ direction_a /= norm_a
655
+
656
+ # Function to calculate perpendicular distance from a point to the line defined by a point and direction vector
657
+ def distance_from_line(point, line_point, line_dir):
658
+ point = np.array([Vertex.X(point, mantissa=mantissa), Vertex.Y(point, mantissa=mantissa),
659
+ Vertex.Z(point, mantissa=mantissa)])
660
+ line_point = np.array(line_point)
661
+ diff = point - line_point
662
+ cross_product = np.cross(diff, line_dir)
663
+ line_dir_norm = np.linalg.norm(line_dir)
664
+ if line_dir_norm == 0:
665
+ print("Edge.IsCollinear - Error: Division by zero. Returning None.")
666
+ return None
667
+ distance = np.linalg.norm(cross_product) / np.linalg.norm(line_dir)
668
+ return distance
652
669
 
653
- # Calculate perpendicular distance for end vertex of edgeB
670
+ # Get start and end points of the second edge
671
+ start_b = Edge.StartVertex(edgeB)
654
672
  end_b = Edge.EndVertex(edgeB)
655
- x0, y0 = Vertex.X(end_b, mantissa=mantissa), Vertex.Y(end_b, mantissa=mantissa)
656
- distance_end = abs(A * x0 + B * y0 + C)
673
+
674
+ # Calculate distances for start and end vertices of the second edge to the line defined by the first edge
675
+ distance_start = distance_from_line(start_b, start_a_coords, direction_a)
676
+ distance_end = distance_from_line(end_b, start_a_coords, direction_a)
657
677
 
658
678
  # Check if both distances are within tolerance
659
679
  return bool(distance_start < tolerance) and bool(distance_end < tolerance)
topologicpy/Topology.py CHANGED
@@ -3199,6 +3199,146 @@ class Topology():
3199
3199
  return True
3200
3200
  return False
3201
3201
 
3202
+
3203
+ def ExportToDXF(topologies, path, overwrite=False):
3204
+ """
3205
+ Exports the input topology to a DXF file. See https://en.wikipedia.org/wiki/AutoCAD_DXF.
3206
+ THe DXF version is 'R2010'
3207
+ This is experimental and only geometry is exported.
3208
+
3209
+ Parameters
3210
+ ----------
3211
+ topologies : list or topologic_core.Topology
3212
+ The input list of topologies. This can also be a single topologic_core.Topology.
3213
+ path : str
3214
+ The input file path.
3215
+ overwrite : bool , optional
3216
+ If set to True the ouptut file will overwrite any pre-existing file. Otherwise, it won't. The default is False.
3217
+
3218
+ Returns
3219
+ -------
3220
+ bool
3221
+ True if the export operation is successful. False otherwise.
3222
+
3223
+ """
3224
+ import os
3225
+ import warnings
3226
+
3227
+ try:
3228
+ import ezdxf
3229
+ except:
3230
+ print("Topology.ExportToDXF - Information: Installing required ezdxf library.")
3231
+ try:
3232
+ os.system("pip install ezdxf")
3233
+ except:
3234
+ os.system("pip install ezdxf --user")
3235
+ try:
3236
+ import ezdxf
3237
+ print("Topology.ExportToDXF - Information: ezdxf library installed successfully.")
3238
+ except:
3239
+ warnings.warn("Topology.ExportToDXF - Error: Could not import ezdxf library. Please install it manually. Returning None.")
3240
+ return None
3241
+
3242
+ from topologicpy.Vertex import Vertex
3243
+ from topologicpy.Edge import Edge
3244
+ from topologicpy.Cluster import Cluster
3245
+ from topologicpy.Topology import Topology
3246
+
3247
+ from os.path import exists
3248
+ if not isinstance(topologies, list):
3249
+ topologies = [topologies]
3250
+ topologies = [topology for topology in topologies if Topology.IsInstance(topology, "Topology")]
3251
+ if len(topologies) < 1:
3252
+ print("Topology.ExportToDXF - Error: The inupt list parameter topologies does not contain any valid topologies. Returning None.")
3253
+ # Make sure the file extension is .brep
3254
+ ext = path[len(path)-4:len(path)]
3255
+ if ext.lower() != ".dxf":
3256
+ path = path+".dxf"
3257
+ if not overwrite and exists(path):
3258
+ print("Topology.ExportToDXF - Error: a file already exists at the specified path and overwrite is set to False. Returning None.")
3259
+ return None
3260
+
3261
+ def add_vertices(vertices, msp):
3262
+ for v in vertices:
3263
+ if Topology.IsInstance(v, "Vertex"):
3264
+ msp.add_point((Vertex.X(v), Vertex.Y(v), Vertex.Z(v)))
3265
+ def add_edges(edges, msp):
3266
+ for e in edges:
3267
+ if Topology.IsInstance(e, "Edge"):
3268
+ sv = Edge.StartVertex(e)
3269
+ ev = Edge.EndVertex(e)
3270
+ start = (Vertex.X(sv), Vertex.Y(sv), Vertex.Z(sv))
3271
+ end = (Vertex.X(ev), Vertex.Y(ev), Vertex.Z(ev))
3272
+ msp.add_line(start, end)
3273
+ def add_wires(wires, msp):
3274
+ for i, w in enumerate(wires):
3275
+ if Topology.IsInstance(w, "Wire"):
3276
+ block_name = "Wire_"+str(i+1).zfill(3)
3277
+ block = doc.blocks.new(name=block_name)
3278
+ # Add edges to the block
3279
+ edges = Topology.Edges(w)
3280
+ for edge in edges:
3281
+ sv = Edge.StartVertex(edge)
3282
+ ev = Edge.EndVertex(edge)
3283
+ start = (Vertex.X(sv), Vertex.Y(sv), Vertex.Z(sv))
3284
+ end = (Vertex.X(ev), Vertex.Y(ev), Vertex.Z(ev))
3285
+ block.add_line(start, end)
3286
+ # Insert the block into the model space
3287
+ msp.add_blockref(block_name, insert=(0, 0, 0))
3288
+ def add_meshes(meshes, msp):
3289
+ for m in meshes:
3290
+ data = Topology.Geometry(m)
3291
+ vertices = data['vertices']
3292
+ faces = data['faces']
3293
+ mesh = msp.add_mesh()
3294
+ mesh.dxf.subdivision_levels = 0
3295
+ with mesh.edit_data() as mesh_data:
3296
+ mesh_data.vertices = vertices
3297
+ mesh_data.faces = faces
3298
+ # Create a new DXF document
3299
+ doc = ezdxf.new(dxfversion='R2010')
3300
+ msp = doc.modelspace()
3301
+ i = 1
3302
+ for topology in topologies:
3303
+ if Topology.IsInstance(topology, "Vertex"):
3304
+ add_vertices([topology], msp)
3305
+ elif Topology.IsInstance(topology, "Edge"):
3306
+ add_edges([topology], msp)
3307
+ elif Topology.IsInstance(topology, "Wire"):
3308
+ add_wires([topology], msp)
3309
+ elif Topology.IsInstance(topology, "Face"):
3310
+ add_meshes([topology], msp)
3311
+ elif Topology.IsInstance(topology, "Shell"):
3312
+ add_meshes([topology], msp)
3313
+ elif Topology.IsInstance(topology, "Cell"):
3314
+ add_meshes([topology], msp)
3315
+ elif Topology.IsInstance(topology, "CellComplex"):
3316
+ add_meshes([topology], msp)
3317
+ elif Topology.IsInstance(topology, "Cluster"):
3318
+ cellComplexes = Topology.CellComplexes(topology)
3319
+ add_meshes(cellComplexes, msp)
3320
+ cells = Cluster.FreeCells(topology)
3321
+ add_meshes(cells, msp)
3322
+ shells = Cluster.FreeShells(topology)
3323
+ add_meshes(shells, msp)
3324
+ faces = Cluster.FreeFaces(topology)
3325
+ add_meshes(faces, msp)
3326
+ wires = Cluster.FreeWires(topology)
3327
+ add_wires(wires, msp)
3328
+ edges = Cluster.FreeEdges(topology)
3329
+ add_edges(edges, msp)
3330
+ vertices = Cluster.FreeVertices(topology)
3331
+ add_vertices(vertices, msp)
3332
+
3333
+ # Save the DXF document
3334
+ status = False
3335
+ try:
3336
+ doc.saveas(path)
3337
+ status = True
3338
+ except:
3339
+ status = False
3340
+ return status
3341
+
3202
3342
  '''
3203
3343
  @staticmethod
3204
3344
  def ExportToIPFS(topology, url, port, user, password):
topologicpy/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = '0.7.2'
1
+ __version__ = '0.7.3'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: topologicpy
3
- Version: 0.7.2
3
+ Version: 0.7.3
4
4
  Summary: An Advanced Spatial Modelling and Analysis Software Library for Architecture, Engineering, and Construction.
5
5
  Author-email: Wassim Jabi <wassim.jabi@gmail.com>
6
6
  License: GNU AFFERO GENERAL PUBLIC LICENSE
@@ -6,7 +6,7 @@ topologicpy/Color.py,sha256=UlmRcCSOhqcM_OyMWz4t3Kr75KcgXDhz3uctAJ2n7Ic,18031
6
6
  topologicpy/Context.py,sha256=ppApYKngZZCQBFWaxIMi2z2dokY23c935IDCBosxDAE,3055
7
7
  topologicpy/DGL.py,sha256=RpkLnAzjg6arY7cEMs2pDFYzRdkerVg1Wbm9hcE3QaM,138991
8
8
  topologicpy/Dictionary.py,sha256=pMbfE2RYGCNpVr2x58qiHRc-aBWnp1jLlyzwS9nz6-w,25891
9
- topologicpy/Edge.py,sha256=ktCp2VgBj-QvrUQ0oagTZG2QErth9cilzaBhhHeYNB8,50321
9
+ topologicpy/Edge.py,sha256=jbJHyPHlLF94RkUKL479B4dPC202K0Xd7bQsPcFwoHc,51296
10
10
  topologicpy/EnergyModel.py,sha256=UBLim01lZLikVQmJAHEeja-KvF4tgzTxsSxwNDaezz4,52500
11
11
  topologicpy/Face.py,sha256=BOU6hN-4uCaXW_lbvuOlntrz_Q0jEiL5tIHAFuqWw_U,97195
12
12
  topologicpy/Graph.py,sha256=GsWySXL-cTd7bl-QWpl3Aw9Hr0KyACzIa4iRenTB63s,368030
@@ -20,14 +20,14 @@ topologicpy/Polyskel.py,sha256=MYHKFOQBlUNqoUhAdOcKRIHpSk0dWWVrZgXK34NkvFM,15936
20
20
  topologicpy/Shell.py,sha256=6hidTQ6MW5q_es-WbTeI_yt7Sd7BMxWU_qfoherVZhE,74343
21
21
  topologicpy/Speckle.py,sha256=rUS6PCaxIjEF5_fUruxvMH47FMKg-ohcoU0qAUb-yNM,14267
22
22
  topologicpy/Sun.py,sha256=3tYb8kssU882lE1gEWg2mxDvCCY_LAVElkyUT6wa-ZU,36935
23
- topologicpy/Topology.py,sha256=oXZZGGklFeVMIcKorVXM5RFMbCnoYcjdrScTIodSQng,292911
23
+ topologicpy/Topology.py,sha256=limcBROvZgD5xanXLi57WgOvR9e93-MkYZcFtFgctu0,298938
24
24
  topologicpy/Vector.py,sha256=FHbrCb9GVLOUV_kqcplh4D88CVxlID6qX_wEQOw4rD0,29565
25
25
  topologicpy/Vertex.py,sha256=YgbbCcqABvb97z2-yEytpp5T3yoZPlQplR_vMQkQ9OA,65180
26
26
  topologicpy/Wire.py,sha256=MUEboxo11kMgwnZySSkwiyzBG2wv0wPiinf2cW4UVv8,138424
27
27
  topologicpy/__init__.py,sha256=D7ky87CAQMiS2KE6YLvcTLkTgA2PY7rASe6Z23pjp9k,872
28
- topologicpy/version.py,sha256=0eAFjnFVSWI6_301EfFzaXJIiwNScF9GpeINoCLd-XM,22
29
- topologicpy-0.7.2.dist-info/LICENSE,sha256=TfPDBt3ar0uv_f9cqCDMZ5rIzW3CY8anRRd4PkL6ejs,34522
30
- topologicpy-0.7.2.dist-info/METADATA,sha256=mUXBHGbD8IpLymaCvTw5wyJmhssEstUU57P6bXuYFkk,46950
31
- topologicpy-0.7.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
32
- topologicpy-0.7.2.dist-info/top_level.txt,sha256=J30bDzW92Ob7hw3zA8V34Jlp-vvsfIkGzkr8sqvb4Uw,12
33
- topologicpy-0.7.2.dist-info/RECORD,,
28
+ topologicpy/version.py,sha256=i5zhgfscuWC8vabp6pP1S6z_O5355x2aIv0so00_cmo,22
29
+ topologicpy-0.7.3.dist-info/LICENSE,sha256=TfPDBt3ar0uv_f9cqCDMZ5rIzW3CY8anRRd4PkL6ejs,34522
30
+ topologicpy-0.7.3.dist-info/METADATA,sha256=TdJMT-64j4LX5i_DSX8qg-5jNgUSETUla-Mi9AMjkic,46950
31
+ topologicpy-0.7.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
32
+ topologicpy-0.7.3.dist-info/top_level.txt,sha256=J30bDzW92Ob7hw3zA8V34Jlp-vvsfIkGzkr8sqvb4Uw,12
33
+ topologicpy-0.7.3.dist-info/RECORD,,