{"version":3,"file":"HueRotation.mjs","names":[],"sources":["../../../src/filters/HueRotation.ts"],"sourcesContent":["import { cos } from '../util/misc/cos';\nimport { sin } from '../util/misc/sin';\nimport {\n  ColorMatrix,\n  type ColorMatrixOwnProps,\n  colorMatrixDefaultValues,\n} from './ColorMatrix';\nimport type { TWebGLPipelineState, T2DPipelineState } from './typedefs';\nimport { classRegistry } from '../ClassRegistry';\n\nexport type HueRotationOwnProps = ColorMatrixOwnProps & {\n  rotation: number;\n};\n\nexport type HueRotationSerializedProps = {\n  rotation: number;\n};\n\nexport const hueRotationDefaultValues: HueRotationOwnProps = {\n  ...colorMatrixDefaultValues,\n  rotation: 0,\n};\n\n/**\n * HueRotation filter class\n * @example\n * const filter = new HueRotation({\n *   rotation: -0.5\n * });\n * object.filters.push(filter);\n * object.applyFilters();\n */\nexport class HueRotation extends ColorMatrix<\n  'HueRotation',\n  HueRotationOwnProps,\n  HueRotationSerializedProps\n> {\n  /**\n   * HueRotation value, from -1 to 1.\n   */\n  declare rotation: HueRotationOwnProps['rotation'];\n\n  static type = 'HueRotation';\n\n  static defaults = hueRotationDefaultValues;\n\n  calculateMatrix() {\n    const rad = this.rotation * Math.PI,\n      cosine = cos(rad),\n      sine = sin(rad),\n      aThird = 1 / 3,\n      aThirdSqtSin = Math.sqrt(aThird) * sine,\n      OneMinusCos = 1 - cosine;\n    this.matrix = [\n      cosine + OneMinusCos / 3,\n      aThird * OneMinusCos - aThirdSqtSin,\n      aThird * OneMinusCos + aThirdSqtSin,\n      0,\n      0,\n      aThird * OneMinusCos + aThirdSqtSin,\n      cosine + aThird * OneMinusCos,\n      aThird * OneMinusCos - aThirdSqtSin,\n      0,\n      0,\n      aThird * OneMinusCos - aThirdSqtSin,\n      aThird * OneMinusCos + aThirdSqtSin,\n      cosine + aThird * OneMinusCos,\n      0,\n      0,\n      0,\n      0,\n      0,\n      1,\n      0,\n    ];\n  }\n\n  isNeutralState() {\n    return this.rotation === 0;\n  }\n\n  applyTo(options: TWebGLPipelineState | T2DPipelineState) {\n    this.calculateMatrix();\n    super.applyTo(options);\n  }\n\n  toObject() {\n    return {\n      type: this.type,\n      rotation: this.rotation,\n    };\n  }\n}\n\nclassRegistry.setClass(HueRotation);\n"],"mappings":";;;;;;AAkBA,MAAa,2BAAgD;CAC3D,GAAG;CACH,UAAU;CACX;;;;;;;;;;AAWD,IAAa,cAAb,cAAiC,YAI/B;CAUA,kBAAkB;EAChB,MAAM,MAAM,KAAK,WAAW,KAAK,IAC/B,SAAS,IAAI,IAAI,EACjB,OAAO,IAAI,IAAI,EACf,SAAS,IAAI,GACb,eAAe,KAAK,KAAK,OAAO,GAAG,MACnC,cAAc,IAAI;AACpB,OAAK,SAAS;GACZ,SAAS,cAAc;GACvB,SAAS,cAAc;GACvB,SAAS,cAAc;GACvB;GACA;GACA,SAAS,cAAc;GACvB,SAAS,SAAS;GAClB,SAAS,cAAc;GACvB;GACA;GACA,SAAS,cAAc;GACvB,SAAS,cAAc;GACvB,SAAS,SAAS;GAClB;GACA;GACA;GACA;GACA;GACA;GACA;GACD;;CAGH,iBAAiB;AACf,SAAO,KAAK,aAAa;;CAG3B,QAAQ,SAAiD;AACvD,OAAK,iBAAiB;AACtB,QAAM,QAAQ,QAAQ;;CAGxB,WAAW;AACT,SAAO;GACL,MAAM,KAAK;GACX,UAAU,KAAK;GAChB;;;6BAhDI,QAAO,cAAc;6BAErB,YAAW,yBAAyB;AAkD7C,cAAc,SAAS,YAAY"}