1 module skia.SKRotationScaleMatrix; 2 3 import skia.SKMatrix; 4 import std.math; 5 6 struct SKRotationScaleMatrix 7 { 8 // static readonly SKRotationScaleMatrix Empty; 9 10 // static readonly SKRotationScaleMatrix Identity = new SKRotationScaleMatrix (1, 0, 0, 0); 11 12 float fSCos; 13 float fSSin; 14 float fTX; 15 float fTY; 16 this (float scos, float ssin, float tx, float ty) 17 { 18 fSCos = scos; 19 fSSin = ssin; 20 fTX = tx; 21 fTY = ty; 22 } 23 24 const SKMatrix ToMatrix () 25 { 26 return SKMatrix (fSCos, -fSSin, fTX, fSSin, fSCos, fTY, 0, 0, 1); 27 } 28 29 30 static SKRotationScaleMatrix CreateDegrees (float scale, float degrees, float tx, float ty, float anchorX, float anchorY) 31 { 32 return Create (scale, degrees * SKMatrix.DegreesToRadians, tx, ty, anchorX, anchorY); 33 } 34 35 36 static SKRotationScaleMatrix Create (float scale, float radians, float tx, float ty, float anchorX, float anchorY) 37 { 38 auto s = cast(float)sin (radians) * scale; 39 auto c = cast(float)cos (radians) * scale; 40 auto x = tx + -c * anchorX + s * anchorY; 41 auto y = ty + -s * anchorX - c * anchorY; 42 43 return SKRotationScaleMatrix (c, s, x, y); 44 } 45 46 static SKRotationScaleMatrix CreateIdentity () 47 { 48 return SKRotationScaleMatrix (1, 0, 0, 0); 49 } 50 51 52 static SKRotationScaleMatrix CreateTranslation (float x, float y) 53 { 54 return SKRotationScaleMatrix (1, 0, x, y); 55 } 56 57 static SKRotationScaleMatrix CreateScale (float s) 58 { 59 return SKRotationScaleMatrix (s, 0, 0, 0); 60 } 61 62 static SKRotationScaleMatrix CreateRotation (float radians, float anchorX, float anchorY) 63 { 64 return Create (1, radians, 0, 0, anchorX, anchorY); 65 } 66 67 static SKRotationScaleMatrix CreateRotationDegrees (float degrees, float anchorX, float anchorY) 68 { 69 return CreateDegrees (1, degrees, 0, 0, anchorX, anchorY); 70 } 71 }