# -*- coding: iso-8859-1 -*-
from __future__ import division # 1/2 == .5 (par defaut, 1/2 == 0)

from customtest import *



class TestGeolibTransformations(CustomTest):

    def test_Rotation(self):
        A = Point(1.523, 45.35211)
        r = Rotation(A, math.pi/4)
        M = Point(1.4452,  -1.2545)
        self.assertAlmostEqual(r(M).coordonnees, (34.423837071540447, 12.341247113306926))
        self.assertAlmostEqual(r(A).coordonnees, A.coordonnees)
        d = Droite(A, M)
        d1 = Droite(A, r(M))
        self.assertAlmostEqual(r(d).equation_reduite, d1.equation_reduite)
        self.assert_(r(A) is A)


    def test_Translation(self):
        v = Vecteur_libre(random()+randint(50)-randint(50), random()+randint(50)-randint(50))
        t = Translation(v)
        M = Point(random()+randint(50)-randint(50), random()+randint(50)-randint(50))
        self.assertAlmostEqual(M.x + v.x, t(M).x)
        self.assertAlmostEqual(M.y + v.y, t(M).y)


    def test_Reflexion(self):
        d = Droite_equation(1, 6, -2)
        r = Reflexion(d)
        M = Point(random()+randint(50)-randint(50), random()+randint(50)-randint(50))
        m = Mediatrice(M,  r(M))
        self.assertAlmostEqual(d.equation_reduite,  m.equation_reduite)
        self.assert_(r(d) is d)

    def test_Homothetie(self):
        A = Point(1, -2)
        h = Homothetie(A, -3)
        M = Point(2, 7)
        self.assertAlmostEqual(h(M).coordonnees, (-2, -29))
        self.assert_(h(A) is A)


    def test_Symetrie_centrale(self):
        M = Point(random()+randint(50)-randint(50), random()+randint(50)-randint(50))
        A = Point(random()+randint(50)-randint(50), random()+randint(50)-randint(50))
        s = Symetrie_centrale(A)
        self.assertAlmostEqual(Milieu(M, s(M)).coordonnees, A.coordonnees)
        self.assert_(s(A) is A)



if __name__ == '__main__':
    unittest.main()
