<commit_before>// [VexFlow](http://vexflow.com) - Copyright (c) <NAME> 2010.
// MIT License

/**
 * BoundingBoxComputation computes metrics for a bounding box by continuously
 * taking canvas path commands.
 *
 * Warning: This class is merely a crutch to get bounding box information without
 * explicit metadata. This is likely to get deprecated following SMuFL support.
 *
 * based on: https://github.com/canvg/canvg/blob/master/src/BoundingBox.ts (MIT License)
 */
export class BoundingBoxComputation {
  protected x1: number;
  protected y1: number;
  protected x2: number;
  protected y2: number;

  constructor(x1?: number, y1?: number, x2?: number, y2?: number) {
    // pass in initial points if you want
    this.x1 = Number.NaN;
    this.y1 = Number.NaN;
    this.x2 = Number.NaN;
    this.y2 = Number.NaN;

    this.addPoint(x1, y1);
    this.addPoint(x2, y2);
  }

  /** Get calculated X1. */
  getX1(): number {
    return this.x1;
  }

  /** Get calculated Y1. */
  getY1(): number {
    return this.y1;
  }

  /** Get calculated width. */
  width(): number {
    return this.x2 - this.x1;
  }

  /** Get calculated height. */
  height(): number {
    return this.y2 - this.y1;
  }

  /** Do nothing. */
  noOp(): void {
    // do nothing
  }

  /** Add point to BoundingBox. */
  addPoint(x: number | undefined, y: number | undefined): void {
    if (x != undefined) {
      if (isNaN(this.x1) || isNaN(this.x2)) {
        this.x1 = x;
        this.x2 = x;
      }
      if (x < this.x1) this.x1 = x;
      if (x > this.x2) this.x2 = x;
    }

    if (y != undefined) {
      if (isNaN(this.y1) || isNaN(this.y2)) {
        this.y1 = y;
        this.y2 = y;
      }
      if (y < this.y1) this.y1 = y;
      if (y > this.y2) this.y2 = y;
    }
  }

  /** Add X to BoundingBox. */
  addX(x: number): void {
    this.addPoint(x, undefined);
  }

  /** Add Y to BoundingBox. */
  addY(y: number): void {
    this.addPoint(undefined, y);
  }

  /** Add quadratic curve to BoundingBox. */
  addQuadraticCurve(p0x: number, p0y: number, p1x: number, p1y: number, p2x: number, p2y: number): void {
    const cp1x = p0x + (2 / 3) * (p1x - p0x); // CP1 = QP0 + 2/3 *(QP1-QP0)
    const cp1y = p0y + (2 / 3) * (p1y - p0y); // CP1 = QP0 + 2/3 *(QP1-QP0)
    const cp2x = cp1x + (1 / 3) * (p2x - p0x); // CP2 = CP1 + 1/3 *(QP2-QP0)
    const cp2y = cp1y + (1 / 3) * (p2y - p0y); // CP2 = CP1 + 1/3 *(QP2-QP0)
    this.addBezierCurve(p0x, p0y, cp1x, cp1y, cp2x, cp2y, p2x, p2y);
  }<commit_msg>Compute quadratic Beizer bounding box directly.<commit_after>// [VexFlow](http://vexflow.com) - Copyright (c) <NAME> 2010.
// MIT License

/**
 * BoundingBoxComputation computes metrics for a bounding box by continuously
 * taking canvas path commands.
 *
 * Warning: This class is merely a crutch to get bounding box information without
 * explicit metadata. This is likely to get deprecated following SMuFL support.
 *
 * based on: https://github.com/canvg/canvg/blob/master/src/BoundingBox.ts (MIT License)
 */
export class BoundingBoxComputation {
  protected x1: number = Number.NaN;
  protected y1: number = Number.NaN;
  protected x2: number = Number.NaN;
  protected y2: number = Number.NaN;

  /** Get calculated X1. */
  getX1(): number {
    return this.x1;
  }

  /** Get calculated Y1. */
  getY1(): number {
    return this.y1;
  }

  /** Get calculated width. */
  width(): number {
    return this.x2 - this.x1;
  }

  /** Get calculated height. */
  height(): number {
    return this.y2 - this.y1;
  }

  /** Add point to BoundingBox. */
  addPoint(x: number, y: number): void {
    if (isNaN(this.x1) || x < this.x1) this.x1 = x;
    if (isNaN(this.x2) || x > this.x2) this.x2 = x;
    if (isNaN(this.y1) || y < this.y1) this.y1 = y;
    if (isNaN(this.y2) || y > this.y2) this.y2 = y;
  }

  /** Add X to BoundingBox. */
  addX(x: number): void {
    this.addPoint(x, this.y1);
  }

  /** Add Y to BoundingBox. */
  addY(y: number): void {
    this.addPoint(this.x1, y);
  }

  /** Add quadratic curve to BoundingBox. */
  addQuadraticCurve(p0x: number, p0y: number, p1x: number, p1y: number, p2x: number, p2y: number): void {
    this.addPoint(p0x, p0y);
    this.addPoint(p2x, p2y);

    const p01x = p1x - p0x;
    const p12x = p2x - p1x;
    let denom = p01x - p12x;
    if (denom != 0) {
      const t = p01x / denom;
      if (t > 0 && t < 1) {
        const it = 1 - t;
        this.addX(it * it * p0x + 2 * it * t * p1x + t * t * p2x);
      }
    }

    const p01y = p1y - p0y;
    const p12y = p2y - p1y;
    denom = p01y - p12y;
    if (denom != 0) {
      const t = p01y / denom;
      if (t > 0 && t < 1) {
        const it = 1 - t;
        this.addY(it * it * p0y + 2 * it * t * p1y + t * t * p2y);
      }
    }
  }
{'fraction_non_alphanumeric': 0.15721812434141202, 'fraction_numerical': 0.040885142255005266, 'mean_word_length': 2.279889426399447, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2463821', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1855, 'n_words': 519}