diff --git a/core/src/avm1/globals/matrix.rs b/core/src/avm1/globals/matrix.rs index 3fd6e4318..0549159e1 100644 --- a/core/src/avm1/globals/matrix.rs +++ b/core/src/avm1/globals/matrix.rs @@ -358,6 +358,23 @@ fn transform_point<'gc>( Ok(object.into()) } +fn delta_transform_point<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + this: Object<'gc>, + args: &[Value<'gc>], +) -> Result, Error<'gc>> { + let matrix = object_to_matrix(this, activation)?; + let point = value_to_point( + args.get(0).unwrap_or(&Value::Undefined).to_owned(), + activation, + )?; + + let x = point.0 * matrix.a as f64 + point.1 * matrix.c as f64; + let y = point.0 * matrix.b as f64 + point.1 * matrix.d as f64; + let object = point_to_object((x, y), activation)?; + Ok(object.into()) +} + fn to_string<'gc>( activation: &mut Activation<'_, 'gc, '_>, this: Object<'gc>, @@ -481,5 +498,13 @@ pub fn create_proto<'gc>( Some(fn_proto), ); + object.force_set_function( + "deltaTransformPoint", + delta_transform_point, + gc_context, + EnumSet::empty(), + Some(fn_proto), + ); + object.into() } diff --git a/core/tests/swfs/avm1/matrix/output.txt b/core/tests/swfs/avm1/matrix/output.txt index 0bd590df0..b2b0c51d0 100644 --- a/core/tests/swfs/avm1/matrix/output.txt +++ b/core/tests/swfs/avm1/matrix/output.txt @@ -160,3 +160,14 @@ false (x=18, y=23) +/// deltaTransformPoint +// matrix = new Matrix(2, 3, 5, 7, 11, 13); +(a=2, b=3, c=5, d=7, tx=11, ty=13) + +// matrix.deltaTransformPoint(); +(x=NaN, y=NaN) + +// matrix.deltaTransformPoint(new Point(1, 1)); +(x=7, y=10) + + diff --git a/core/tests/swfs/avm1/matrix/test.fla b/core/tests/swfs/avm1/matrix/test.fla index ae0e4793e..928ecea31 100644 Binary files a/core/tests/swfs/avm1/matrix/test.fla and b/core/tests/swfs/avm1/matrix/test.fla differ diff --git a/core/tests/swfs/avm1/matrix/test.swf b/core/tests/swfs/avm1/matrix/test.swf index a01904713..b9b04bb29 100644 Binary files a/core/tests/swfs/avm1/matrix/test.swf and b/core/tests/swfs/avm1/matrix/test.swf differ