1- # Copyright (c) 2020, Manfred Moitzi
1+ # Copyright (c) 2020-2022 , Manfred Moitzi
22# License: MIT License
33import time
4- from pathlib import Path
54from ezdxf .math import Vec3 , closest_point
65from ezdxf .math .rtree import RTree
76
109except ImportError :
1110 plt = None
1211
13- DIR = Path ("~/Desktop/Outbox" ).expanduser ()
14-
1512
1613def random_points (n , size = 1.0 ):
1714 return [Vec3 .random () * size for _ in range (n )]
@@ -66,9 +63,7 @@ def profile_rtree_building(repeat: int, max_size: int):
6663 for size in range (100 , 2000 , 100 ):
6764 points = random_points (size , 50.0 )
6865 name = f"RTree({ size } , { max_size } )"
69- t0 = profile (
70- profile_build_time_random_rtree , repeat , points , max_size
71- )
66+ t0 = profile (profile_build_time_random_rtree , repeat , points , max_size )
7267 time_str = f"{ t0 :6.2f} s"
7368 print (f"Build random { name } , { repeat } x , { time_str } " )
7469 log .append ((size , t0 ))
@@ -81,9 +76,7 @@ def profile_rtree_contains_all_points(repeat: int, max_size: int):
8176 points = random_points (size , 50.0 )
8277 tree = RTree (points , max_size )
8378 name = f"RTree({ size } , { max_size } )"
84- t0 = profile (
85- profile_tree_contains_points , repeat , tree , points
86- )
79+ t0 = profile (profile_tree_contains_points , repeat , tree , points )
8780 time_str = f"{ t0 :6.2f} s"
8881 print (f"{ name } contains all points, { repeat } x , { time_str } " )
8982 log .append ((size , t0 ))
@@ -98,9 +91,7 @@ def profile_rtree_nearest_neighbor(repeat: int, max_size: int):
9891 name = f"RTree({ size } , { max_size } )"
9992
10093 search_points = random_points (100 , 50.0 )
101- t0 = profile (
102- profile_tree_nearest_neighbor , repeat , tree , search_points
103- )
94+ t0 = profile (profile_tree_nearest_neighbor , repeat , tree , search_points )
10495 time_str = f"{ t0 :6.2f} s"
10596 print (f"{ name } nearest neighbor, { repeat } x , { time_str } " )
10697 log .append ((size , t0 ))
@@ -113,9 +104,7 @@ def profile_brute_force_contains_all_points(repeat: int):
113104 points = random_points (size , 50.0 )
114105
115106 name = f"Brute Force({ size } )"
116- t0 = profile (
117- profile_brute_force_contains_points , repeat , points
118- )
107+ t0 = profile (profile_brute_force_contains_points , repeat , points )
119108 time_str = f"{ t0 :6.2f} s"
120109 print (f"{ name } contains all points, { repeat } x , { time_str } " )
121110 log .append ((size , t0 ))
@@ -171,15 +160,20 @@ def show_log(log, name: str):
171160 if PROFILE_RTREE_CONTAINS :
172161 log = profile_rtree_contains_all_points (10 , max_size )
173162 if plt :
174- show_log (log , f"Random RTree contains all points, max node size={ max_size } " )
163+ show_log (
164+ log ,
165+ f"Random RTree contains all points, max node size={ max_size } " ,
166+ )
175167 if PROFILE_BRUTE_FORCE_CONTAINS :
176168 log = profile_brute_force_contains_all_points (10 )
177169 if plt :
178170 show_log (log , f"Brute force contains all points" )
179171 if PROFILE_RTREE_NEIGHBOR :
180172 log = profile_rtree_nearest_neighbor (10 , max_size )
181173 if plt :
182- show_log (log , f"Random RTree nearest neighbor, max node size={ max_size } " )
174+ show_log (
175+ log , f"Random RTree nearest neighbor, max node size={ max_size } "
176+ )
183177 if PROFILE_BRUTE_FORCE_NEIGHBOR :
184178 log = profile_brute_force_nearest_neighbor (10 )
185179 if plt :
0 commit comments