Skip to content

Commit

Permalink
Add random intersections test
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarize committed Dec 4, 2022
1 parent 4c6abc5 commit b6e5a62
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/test_path.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# External dependencies
from __future__ import division, absolute_import, print_function
import os
import time
from sys import version_info
import unittest
from math import sqrt, pi
Expand Down Expand Up @@ -1491,6 +1492,49 @@ def test_intersect(self):
self.assertTrue(len(yix) == 1)
###################################################################

def test_random_intersections(self):
from random import Random
r = Random()
distance = 100
distribution = 10000
count = 500

def random_complex(offset_x=0.0, offset_y=0.0):
return complex(r.random() * distance + offset_x, r.random() * distance + offset_y)

def random_line():
offset_x = r.random() * distribution
offset_y = r.random() * distribution
return Line(random_complex(offset_x, offset_y), random_complex(offset_x, offset_y))

def random_quad():
offset_x = r.random() * distribution
offset_y = r.random() * distribution
return QuadraticBezier(random_complex(offset_x, offset_y), random_complex(offset_x, offset_y), random_complex(offset_x, offset_y))

def random_cubic():
offset_x = r.random() * distribution
offset_y = r.random() * distribution
return CubicBezier(random_complex(offset_x, offset_y), random_complex(offset_x, offset_y), random_complex(offset_x, offset_y), random_complex(offset_x, offset_y))

def random_path():
path = Path()
for i in range(count):
type_segment = random.randint(0, 3)
if type_segment == 0:
path.append(random_line())
if type_segment == 1:
path.append(random_quad())
if type_segment == 2:
path.append(random_cubic())
return path

path1 = random_path()
path2 = random_path()
t = time.time()
path1.intersect(path2)
print(f"\nIntersection calculation took {time.time() - t} seconds.\n")

def test_line_line_0(self):
l0 = Line(start=(25.389999999999997+99.989999999999995j),
end=(25.389999999999997+90.484999999999999j))
Expand Down

0 comments on commit b6e5a62

Please sign in to comment.