當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript math.angle_between函數代碼示例

本文整理匯總了TypeScript中core/util/math.angle_between函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript angle_between函數的具體用法?TypeScript angle_between怎麽用?TypeScript angle_between使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了angle_between函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: _hit_point

  protected _hit_point(geometry: PointGeometry): Selection {
    let dist, sx0, sx1, sy0, sy1, x0, x1, y0, y1;
    const {sx, sy} = geometry;
    const x = this.renderer.xscale.invert(sx);
    const y = this.renderer.yscale.invert(sy);

    // check diameter first
    const max_diameter = 2 * this.max_radius
    if (this.model.properties.radius.units === "data") {
      x0 = x - max_diameter;
      x1 = x + max_diameter;

      y0 = y - max_diameter;
      y1 = y + max_diameter;

    } else {
      sx0 = sx - max_diameter;
      sx1 = sx + max_diameter;
      [x0, x1] = this.renderer.xscale.r_invert(sx0, sx1);

      sy0 = sy - max_diameter;
      sy1 = sy + max_diameter;
      [y0, y1] = this.renderer.yscale.r_invert(sy0, sy1);
    }

    const candidates = [];

    const bbox = hittest.validate_bbox_coords([x0, x1], [y0, y1]);
    for (const i of this.index.indices(bbox)) {
      const r2 = Math.pow(this.sradius[i], 2);
      [sx0, sx1] = this.renderer.xscale.r_compute(x, this._x[i]);
      [sy0, sy1] = this.renderer.yscale.r_compute(y, this._y[i]);
      dist = Math.pow(sx0-sx1, 2) + Math.pow(sy0-sy1, 2);
      if (dist <= r2) {
        candidates.push([i, dist]);
      }
    }

    const direction = this.model.properties.direction.value();
    const hits: [number, number][] = [];
    for (const [i, dist] of candidates) {
      // NOTE: minus the angle because JS uses non-mathy convention for angles
      const angle = Math.atan2(sy-this.sy[i], sx-this.sx[i]);
      if (angle_between(-angle, -this._start_angle[i], -this._end_angle[i], direction)) {
        hits.push([i, dist]);
      }
    }

    return hittest.create_hit_test_result_from_hits(hits);
  }
開發者ID:,項目名稱:,代碼行數:50,代碼來源:

示例2: _hit_point

  protected _hit_point(geometry: PointGeometry): Selection {
    const {sx, sy} = geometry
    const x = this.renderer.xscale.invert(sx)
    const y = this.renderer.yscale.invert(sy)

    // check radius first
    let x0: number, y0: number
    let x1: number, y1: number
    if (this.model.properties.outer_radius.units == "data") {
      x0 = x - this.max_outer_radius
      x1 = x + this.max_outer_radius

      y0 = y - this.max_outer_radius
      y1 = y + this.max_outer_radius
    } else {
      const sx0 = sx - this.max_outer_radius
      const sx1 = sx + this.max_outer_radius
      ;[x0, x1] = this.renderer.xscale.r_invert(sx0, sx1)

      const sy0 = sy - this.max_outer_radius
      const sy1 = sy + this.max_outer_radius
      ;[y0, y1] = this.renderer.yscale.r_invert(sy0, sy1)
    }

    const candidates = []

    const bbox = hittest.validate_bbox_coords([x0, x1], [y0, y1])
    for (const i of this.index.indices(bbox)) {
      const or2 = Math.pow(this.souter_radius[i], 2)
      const ir2 = Math.pow(this.sinner_radius[i], 2)
      const [sx0, sx1] = this.renderer.xscale.r_compute(x, this._x[i])
      const [sy0, sy1] = this.renderer.yscale.r_compute(y, this._y[i])
      const dist = Math.pow(sx0-sx1, 2) + Math.pow(sy0-sy1, 2)
      if (dist <= or2 && dist >= ir2)
        candidates.push([i, dist])
    }

    const direction = this.model.properties.direction.value()
    const hits: [number, number][] = []
    for (const [i, dist] of candidates) {
      // NOTE: minus the angle because JS uses non-mathy convention for angles
      const angle = Math.atan2(sy-this.sy[i], sx-this.sx[i])
      if (angle_between(-angle, -this._start_angle[i], -this._end_angle[i], direction)) {
        hits.push([i, dist])
      }
    }

    return hittest.create_hit_test_result_from_hits(hits)
  }
開發者ID:digitalsatori,項目名稱:Bokeh,代碼行數:49,代碼來源:annular_wedge.ts

示例3: _hit_point

  _hit_point(geometry) {
    const {sx, sy} = geometry;
    const x = this.renderer.xscale.invert(sx);
    const y = this.renderer.yscale.invert(sy);

    // check radius first
    let x0, x1, y0, y1
    if (this.model.properties.outer_radius.units === "data") {
      x0 = x - this.max_outer_radius;
      x1 = x + this.max_outer_radius;

      y0 = y - this.max_outer_radius;
      y1 = y + this.max_outer_radius;
    } else {
      const sx0 = sx - this.max_outer_radius;
      const sx1 = sx + this.max_outer_radius;
      [x0, x1] = this.renderer.xscale.r_invert(sx0, sx1);

      const sy0 = sy - this.max_outer_radius;
      const sy1 = sy + this.max_outer_radius;
      [y0, y1] = this.renderer.yscale.r_invert(sy0, sy1);
    }

    const candidates = [];

    const bbox = hittest.validate_bbox_coords([x0, x1], [y0, y1]);
    for (const i of this.index.indices(bbox)) {
      const or2 = Math.pow(this.souter_radius[i], 2);
      const ir2 = Math.pow(this.sinner_radius[i], 2);
      const [sx0, sx1] = this.renderer.xscale.r_compute(x, this._x[i]);
      const [sy0, sy1] = this.renderer.yscale.r_compute(y, this._y[i]);
      const dist = Math.pow(sx0-sx1, 2) + Math.pow(sy0-sy1, 2);
      if ((dist <= or2) && (dist >= ir2)) {
        candidates.push([i, dist]);
      }
    }

    const direction = this.model.properties.direction.value();
    const hits = [];
    for (const [i, dist] of candidates) {
      // NOTE: minus the angle because JS uses non-mathy convention for angles
      const angle = Math.atan2(sy-this.sy[i], sx-this.sx[i]);
      if (angle_between(-angle, -this._start_angle[i], -this._end_angle[i], direction)) {
        hits.push([i, dist]);
      }
    }

    return hittest.create_1d_hit_test_result(hits);
  }
開發者ID:FourtekIT-incubator,項目名稱:bokeh,代碼行數:49,代碼來源:annular_wedge.ts

示例4: it

 it("should return true if `mid` angle between `lhs` and `rhs`", () => {
   expect(math.angle_between(0, -1, 1, 1)).to.be.equal(true)
   expect(math.angle_between(0, -1, 1, 0)).to.be.equal(false)
 })
開發者ID:jsignell,項目名稱:bokeh,代碼行數:4,代碼來源:math.ts


注:本文中的core/util/math.angle_between函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。