{"version":3,"file":"StrokeProjectionsBase.mjs","names":[],"sources":["../../../../../src/util/misc/projectStroke/StrokeProjectionsBase.ts"],"sourcesContent":["import type { XY } from '../../../Point';\nimport { Point } from '../../../Point';\nimport { degreesToRadians } from '../radiansDegreesConversion';\nimport { createVector } from '../vectors';\nimport type { TProjectStrokeOnPointsOptions, TProjection } from './types';\n\n/**\n * @see https://github.com/fabricjs/fabric.js/pull/8344\n * @todo consider removing skewing from points before calculating stroke projection,\n * see https://github.com/fabricjs/fabric.js/commit/494a10ee2f8c2278ae9a55b20bf50cf6ee25b064#commitcomment-94751537\n */\nexport abstract class StrokeProjectionsBase {\n  declare options: TProjectStrokeOnPointsOptions;\n  declare scale: Point;\n  declare strokeUniformScalar: Point;\n  declare strokeProjectionMagnitude: number;\n\n  constructor(options: TProjectStrokeOnPointsOptions) {\n    this.options = options;\n    this.strokeProjectionMagnitude = this.options.strokeWidth / 2;\n    this.scale = new Point(this.options.scaleX, this.options.scaleY);\n    this.strokeUniformScalar = this.options.strokeUniform\n      ? new Point(1 / this.options.scaleX, 1 / this.options.scaleY)\n      : new Point(1, 1);\n  }\n\n  /**\n   * When the stroke is uniform, scaling affects the arrangement of points. So we must take it into account.\n   */\n  protected createSideVector(from: XY, to: XY) {\n    const v = createVector(from, to);\n    return this.options.strokeUniform ? v.multiply(this.scale) : v;\n  }\n\n  protected abstract calcOrthogonalProjection(\n    from: Point,\n    to: Point,\n    magnitude?: number,\n  ): Point;\n\n  protected projectOrthogonally(from: Point, to: Point, magnitude?: number) {\n    return this.applySkew(\n      from.add(this.calcOrthogonalProjection(from, to, magnitude)),\n    );\n  }\n\n  protected isSkewed() {\n    return this.options.skewX !== 0 || this.options.skewY !== 0;\n  }\n\n  protected applySkew(point: Point) {\n    const p = new Point(point);\n    // skewY must be applied before skewX as this distortion affects skewX calculation\n    p.y += p.x * Math.tan(degreesToRadians(this.options.skewY));\n    p.x += p.y * Math.tan(degreesToRadians(this.options.skewX));\n    return p;\n  }\n\n  protected scaleUnitVector(unitVector: Point, scalar: number) {\n    return unitVector.multiply(this.strokeUniformScalar).scalarMultiply(scalar);\n  }\n\n  protected abstract projectPoints(): Point[];\n\n  public abstract project(): TProjection[];\n}\n"],"mappings":";;;;;;;;;AAWA,IAAsB,wBAAtB,MAA4C;CAM1C,YAAY,SAAwC;AAClD,OAAK,UAAU;AACf,OAAK,4BAA4B,KAAK,QAAQ,cAAc;AAC5D,OAAK,QAAQ,IAAI,MAAM,KAAK,QAAQ,QAAQ,KAAK,QAAQ,OAAO;AAChE,OAAK,sBAAsB,KAAK,QAAQ,gBACpC,IAAI,MAAM,IAAI,KAAK,QAAQ,QAAQ,IAAI,KAAK,QAAQ,OAAO,GAC3D,IAAI,MAAM,GAAG,EAAE;;;;;CAMrB,iBAA2B,MAAU,IAAQ;EAC3C,MAAM,IAAI,aAAa,MAAM,GAAG;AAChC,SAAO,KAAK,QAAQ,gBAAgB,EAAE,SAAS,KAAK,MAAM,GAAG;;CAS/D,oBAA8B,MAAa,IAAW,WAAoB;AACxE,SAAO,KAAK,UACV,KAAK,IAAI,KAAK,yBAAyB,MAAM,IAAI,UAAU,CAAC,CAC7D;;CAGH,WAAqB;AACnB,SAAO,KAAK,QAAQ,UAAU,KAAK,KAAK,QAAQ,UAAU;;CAG5D,UAAoB,OAAc;EAChC,MAAM,IAAI,IAAI,MAAM,MAAM;AAE1B,IAAE,KAAK,EAAE,IAAI,KAAK,IAAI,iBAAiB,KAAK,QAAQ,MAAM,CAAC;AAC3D,IAAE,KAAK,EAAE,IAAI,KAAK,IAAI,iBAAiB,KAAK,QAAQ,MAAM,CAAC;AAC3D,SAAO;;CAGT,gBAA0B,YAAmB,QAAgB;AAC3D,SAAO,WAAW,SAAS,KAAK,oBAAoB,CAAC,eAAe,OAAO"}