public virtual void SetTransformStruct(NSAffineTransformStruct val) { _matrix = val; _isIdentity = false; _isFlipY = false; if (_matrix.m11 == 1.0 && _matrix.m12 == 0.0 && _matrix.m21 == 0.0) { if (_matrix.m22 == 1.0) { _isIdentity = true; } else if (_matrix.m22 == -1.0) { _isFlipY = true; } } //check(); }
private static NSAffineTransformStruct matrix_multiply(NSAffineTransformStruct MA, NSAffineTransformStruct MB) { NSAffineTransformStruct MC; MC.m11 = MA.m11 * MB.m11 + MA.m12 * MB.m21; MC.m12 = MA.m11 * MB.m12 + MA.m12 * MB.m22; MC.m21 = MA.m21 * MB.m11 + MA.m22 * MB.m21; MC.m22 = MA.m21 * MB.m12 + MA.m22 * MB.m22; MC.tX = MA.tX * MB.m11 + MA.tY * MB.m21 + MB.tX; MC.tY = MA.tX * MB.m12 + MA.tY * MB.m22 + MB.tY; return MC; }
public virtual void ScaleBy(double scale) { NSAffineTransformStruct scam = IdentityTransform; scam.m11 = scale; scam.m22 = scale; _matrix = matrix_multiply(scam, _matrix); _isIdentity = false; _isFlipY = false; //check(); }
public virtual void RotateByRadians(double angleRad) { if (angleRad != 0.0) { double sine; double cosine; NSAffineTransformStruct rotm; sine = Math.Sin(angleRad); cosine = Math.Cos(angleRad); rotm.m11 = cosine; rotm.m12 = sine; rotm.m21 = -sine; rotm.m22 = cosine; rotm.tX = rotm.tY = 0; _matrix = matrix_multiply(rotm, _matrix); _isIdentity = false; _isFlipY = false; //check(); } }
public virtual void PrependTransform(ref NSAffineTransform aTransform) { //valid(aTransform); if (aTransform._isIdentity) { double newTX; newTX = aTransform._matrix.tX * _matrix.m11 + aTransform._matrix.tY * _matrix.m21 + _matrix.tX; _matrix.tY = aTransform._matrix.tX * _matrix.m12 + aTransform._matrix.tY * _matrix.m22 + _matrix.tY; _matrix.tX = newTX; //check(); return; } if (aTransform._isFlipY) { double newTX; newTX = aTransform._matrix.tX * _matrix.m11 + aTransform._matrix.tY * _matrix.m21 + _matrix.tX; _matrix.tY = aTransform._matrix.tX * _matrix.m12 + aTransform._matrix.tY * _matrix.m22 + _matrix.tY; _matrix.tX = newTX; _matrix.m21 = -_matrix.m21; _matrix.m22 = -_matrix.m22; if (_isIdentity) { _isFlipY = true; _isIdentity = false; } else if (_isFlipY) { _isFlipY = false; _isIdentity = true; } //check(); return; } if (_isIdentity) { _matrix.m11 = aTransform._matrix.m11; _matrix.m12 = aTransform._matrix.m12; _matrix.m21 = aTransform._matrix.m21; _matrix.m22 = aTransform._matrix.m22; _matrix.tX += aTransform._matrix.tX; _matrix.tY += aTransform._matrix.tY; _isIdentity = false; _isFlipY = aTransform._isFlipY; //check(); return; } if (_isFlipY) { _matrix.m11 = aTransform._matrix.m11; _matrix.m12 = -aTransform._matrix.m12; _matrix.m21 = aTransform._matrix.m21; _matrix.m22 = -aTransform._matrix.m22; _matrix.tX += aTransform._matrix.tX; _matrix.tY -= aTransform._matrix.tY; _isIdentity = false; _isFlipY = false; //check(); return; } _matrix = matrix_multiply(aTransform._matrix, _matrix); _isIdentity = false; _isFlipY = false; //check(); }
public virtual id InitWithTransform(ref NSAffineTransform aTransform) { id self = this; _matrix = aTransform._matrix; _isIdentity = aTransform._isIdentity; _isFlipY = aTransform._isFlipY; return self; }
public override id Init() { id self = this; _matrix = IdentityTransform; _isIdentity = true; return self; }