<?xml version="1.0"?>
<mx:Application name="lightspark_geom_Transform_test"
	xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute"
	applicationComplete="appComplete();"
	backgroundColor="white">

<mx:Script>
<![CDATA[
import flash.display.DisplayObject;
import Tests;

private function appComplete():void
{
	var s:Sprite = new Sprite();
	s.x=10;
	var t:Transform = s.transform;
	var m3:Matrix = t.matrix;
	var m4:Matrix = t.matrix;
	Tests.assertFalse(m3===m4,"Different objects when accessing Transform::matrix");
	t.matrix = null;
	Tests.assertEquals(null, t.matrix, "Null assigned to ::matrix");
	Tests.assertEquals(10, s.x, "Unmodified transform after matrix=null, X");
	Tests.assertEquals(0, s.y, "Unmodified transform after matrix=null, Y");
	var t2:Transform = s.transform;
	Tests.assertFalse(t===t2, "Different objects when accessing DisplayObject::transform", true);
	Tests.assertEquals(null, t2.matrix, "Null assigned to ::matrix even on different object");
	//Create a weird matrix
	var m:Matrix = new Matrix();
	m.scale(2, -3);
	m.rotate(45*Math.PI/180);
	m.translate(1,2);
	t.matrix = m;
	var computedX:Number = s.x;
	var computedY:Number = s.y;
	Tests.assertEquals(1, computedX, "X computed from matrix");
	Tests.assertEquals(2, computedY, "Y computed from matrix");
	var computedScaleX:Number = s.scaleX;
	var computedScaleY:Number = s.scaleY;
	Tests.assertEqualsDelta(2, computedScaleX, 0.00001, "scaleX computed from matrix");
	Tests.assertEqualsDelta(-3, computedScaleY, 0.00001, "scaleY computed from matrix");
	var computedRotation:Number = s.rotation;
	Tests.assertEqualsDelta(45, computedRotation, 0.00001, "rotation computed from matrix");
	s.rotation=0;
	Tests.assertEquals(1, s.x, "X after changing ::rotation");
	Tests.assertEquals(2, s.y, "Y after changing ::rotation");
	Tests.assertEqualsDelta(2, s.scaleX, 0.00001, "scaleX after changing ::rotation");
	Tests.assertEqualsDelta(-3, s.scaleY, 0.00001, "scaleY after changing ::rotation");
	Tests.assertEqualsDelta(0, s.rotation, 0.00001, "rotation after changing ::rotation");
	Tests.assertEqualsDelta(2,s.transform.matrix.a,0.0001,"Whole matrix (a)");
	Tests.assertEqualsDelta(0,s.transform.matrix.b,0.00001,"Whole matrix (b)");
	Tests.assertEqualsDelta(0,s.transform.matrix.c,0.00001,"Whole matrix (c)");
	Tests.assertEqualsDelta(-3,s.transform.matrix.d,0.0001,"Whole matrix (d)");
	Tests.assertEquals(1,s.transform.matrix.tx,"Whole matrix (tx)");
	Tests.assertEquals(2,s.transform.matrix.ty,"Whole matrix (ty)");

	//TODO: Improve support for non canonical matrices
	//e.g. var m:Matrix = new Matrix(0,2,3,0,1,2);

	var m2:Matrix = new Matrix();
	m2.scale(computedScaleX, computedScaleY);
	m2.translate(computedX, computedY);
	Tests.assertEqualsDelta(s.transform.matrix.a,m2.a,0.0001,"Synthetic matrix (a)");
	Tests.assertEqualsDelta(s.transform.matrix.b,m2.b,0.00001,"Synthetic matrix (b)");
	Tests.assertEqualsDelta(s.transform.matrix.c,m2.c,0.00001,"Synthetic matrix (c)");
	Tests.assertEqualsDelta(s.transform.matrix.d,m2.d,0.0001,"Synthetic matrix (d)");
	Tests.assertEquals(s.transform.matrix.tx,m2.tx,"Synthetic matrix (tx)");
	Tests.assertEquals(s.transform.matrix.ty,m2.ty,"Synthetic matrix (ty)");

	Tests.report(visual, name);
}
]]>
</mx:Script>

<mx:UIComponent id="visual" />

</mx:Application>
