| 1 |
|
| 2 |
import os, sys |
| 3 |
TOPDIR = os.path.abspath(os.path.join(os.path.dirname(__file__),"../..")) |
| 4 |
sys.path.insert(0, TOPDIR) |
| 5 |
|
| •6 |
import tools.unittests |
| 7 |
from wxgeometrie.geolib.tests.geotestlib import rand_dte, rand_pt |
| 8 |
from wxgeometrie.geolib import ( |
| 9 |
Intersection_droite_cercle, Intersection_cercles, |
| 10 |
Point, Droite, |
| 11 |
Intersection_droites, Parallele, Feuille, Cercle, |
| 12 |
Mediatrice, Segment, |
| 13 |
) |
| 14 |
|
| •15 |
class GeolibTest(tools.unittests.TestCase): |
| 16 |
def test_Intersection_droites(self): |
| 17 |
d1 = rand_dte() |
| 18 |
d2 = rand_dte() |
| 19 |
A = Intersection_droites(d1, d2) |
| 20 |
if not d1.parallele(d2): |
| 21 |
self.assertTrue(A in d1 and A in d2) |
| 22 |
d3 = Parallele(d1, rand_pt()) |
| 23 |
self.assertFalse(Intersection_droites(d1, d3).existe) |
| 24 |
D = Point(-14.201335283549275, 1.5093204196583834) |
| 25 |
U = Point(-14.201335283549273, 17.644024286752096) |
| 26 |
d = Droite(U, D) |
| 27 |
s = Segment(U, D) |
| 28 |
V = Point(1.933368583544437, 7.5065025053891166) |
| 29 |
W = Point(7.1347038670937115, 8.3895493390615954) |
| 30 |
d2 = Droite(W, V) |
| 31 |
M1 = Intersection_droites(s, d2) |
| 32 |
M2 = Intersection_droites(d, d2) |
| 33 |
self.assertTrue(M1.existe) |
| 34 |
self.assertTrue(M2.existe) |
| 35 |
|
| 36 |
def test_Intersection_droite_cercle(self): |
| 37 |
A = Point(-3.075, 2.0) |
| 38 |
B = Point(0.0, 1.625) |
| 39 |
c1 = Cercle(A, B) |
| 40 |
C = Point(-0.375, 4.425) |
| 41 |
D = Point(3.25, 0.125) |
| 42 |
d1 = Droite(C, D) |
| 43 |
self.assertFalse(Intersection_droite_cercle(d1, c1).existe) |
| 44 |
C(-5.675, 4.95) |
| 45 |
I = Intersection_droite_cercle(d1, c1, True) |
| 46 |
self.assertTrue(I.egal((-4.87791007862, 4.51908023858))) |
| 47 |
J = Intersection_droite_cercle(d1, c1, False) |
| 48 |
self.assertTrue(J.egal((0.0201000262814, 1.87113640036))) |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
def test_Intersection_cercles(self): |
| 53 |
A = Point(-4.4375, 1.95833333333) |
| 54 |
B = Point(-2.10416666667, 0.875) |
| 55 |
c1 = Cercle(A, B) |
| 56 |
C = Point(2.1875, 1.35416666667) |
| 57 |
c2 = Cercle(C,B) |
| 58 |
D = Intersection_cercles(c2, c1, False) |
| 59 |
self.assertTrue(D.egale((-1.9466976004889973, 2.6017297602107377))) |
| 60 |
self.assertTrue(Intersection_cercles(c2, c1, True).egale(B)) |
| 61 |
self.assertTrue( Droite(A, C).confondu(Mediatrice(B, D))) |
| 62 |
|
| 63 |
def test_intersection_et_feuille(self): |
| 64 |
"""On teste que par défaut, le deuxième d'intersection soit différent du premier.""" |
| 65 |
f = Feuille() |
| 66 |
f.objets._ = Point(-5.11060948081, 0.144469525959) |
| 67 |
f.objets._ = Point(-3.97291196388, 0.794582392777) |
| 68 |
f.objets._ = Cercle(f.objets.M1, f.objets.M2) |
| 69 |
f.objets._ = Point(-3.26862302483, -1.10158013544) |
| 70 |
f.objets._ = Point(-5.79683972912, 2.41986455982) |
| 71 |
f.objets._ = Droite(f.objets.M3, f.objets.M4) |
| 72 |
f.objets._ = Intersection_droite_cercle(f.objets.d1, f.objets.c1, True) |
| 73 |
f.objets._ = Intersection_droite_cercle(f.objets.d1, f.objets.c1) |
| 74 |
e) |
| 75 |
self.assertFalse(f.objets.M6.premier_point) |
| 76 |
|
| 77 |
def test_intersections_non_deplacables(self): |
| 78 |
d1 = rand_dte() |
| 79 |
d2 = rand_dte() |
| 80 |
A = Intersection_droites(d1, d2) |
| 81 |
self.assertFalse(A._modifiable) |
| 82 |
self.assertFalse(A._deplacable) |