module util; #define FRAC_1_SQRT_2 0.7071067811865475244008443621048490392848359376884740365883398689 public float2 cmul(float2 x, float2 y) { return float2(x[0] * y[0] - x[1] * y[1], x[0] * y[1] + x[1] * y[0]); } public float2 mul_ni(float2 x) { return float2(x[1], -x[0]); } public float2 rot_45(float2 c) { return float2(c[0] - c[1], c[0] + c[1]) * FRAC_1_SQRT_2; } public float2 rot_90(float2 c) { // The standard 2D rotation matrix gives: // [ cos(pi/2) -sin(pi/2)] [ 0 -1 ] // [ sin(pi/2) cos(pi/2)] = [ 1 0 ] return float2(-c[1], c[0]); } public float2 rot_180(float2 c) { // The standard 2D rotation matrix gives: // [ cos(pi) -sin(pi)] [ -1 0 ] // [ sin(pi) cos(pi)] = [ 0 -1 ] return float2(-c[0], -c[1]); } public float2 rot_270(float2 c) { // The standard 2D rotation matrix gives: // [ cos(3pi/2) -sin(3pi/2)] [ 0 1 ] // [ sin(3pi/2) cos(3pi/2)] = [ -1 0 ] return float2(c[1], -c[0]); }