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


TypeScript common.MathUtil類代碼示例

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


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

示例1: getPointAtLength

 getPointAtLength(distance: number): Point {
   const t = distance / this.getPathLength();
   const { x: x1, y: y1 } = this.p1;
   const { x: x2, y: y2 } = this.p2;
   return {
     x: MathUtil.lerp(x1, x2, t),
     y: MathUtil.lerp(y1, y2, t),
   };
 }
開發者ID:arpitsaan,項目名稱:ShapeShifter,代碼行數:9,代碼來源:LineCalculator.ts

示例2: split

 split(t1: number, t2: number) {
   const { x: x1, y: y1 } = this.p1;
   const { x: x2, y: y2 } = this.p2;
   const p1 = { x: MathUtil.lerp(x1, x2, t1), y: MathUtil.lerp(y1, y2, t1) };
   const p2 = { x: MathUtil.lerp(x1, x2, t2), y: MathUtil.lerp(y1, y2, t2) };
   if (MathUtil.arePointsEqual(p1, p2)) {
     return new PointCalculator(this.id, this.svgChar, p1);
   }
   return new LineCalculator(this.id, this.svgChar, p1, p2);
 }
開發者ID:arpitsaan,項目名稱:ShapeShifter,代碼行數:10,代碼來源:LineCalculator.ts

示例3: interpolateValue

 // @Override
 interpolateValue(start: string, end: string, f: number) {
   if (!start || !end) {
     return undefined;
   }
   const s = ColorUtil.parseAndroidColor(start);
   const e = ColorUtil.parseAndroidColor(end);
   return ColorUtil.toAndroidString({
     r: _.clamp(Math.round(MathUtil.lerp(s.r, e.r, f)), 0, 0xff),
     g: _.clamp(Math.round(MathUtil.lerp(s.g, e.g, f)), 0, 0xff),
     b: _.clamp(Math.round(MathUtil.lerp(s.b, e.b, f)), 0, 0xff),
     a: _.clamp(Math.round(MathUtil.lerp(s.a, e.a, f)), 0, 0xff),
   });
 }
開發者ID:arpitsaan,項目名稱:ShapeShifter,代碼行數:14,代碼來源:ColorProperty.ts

示例4: intersects

 intersects(line: Line): number[] {
   if (MathUtil.arePointsEqual(_.first(this.points), _.last(this.points))) {
     // Points can't be intersected.
     return [];
   }
   return this.bezierJs.intersects(line);
 }
開發者ID:arpitsaan,項目名稱:ShapeShifter,代碼行數:7,代碼來源:BezierCalculator.ts

示例5: project

 project(point: Point) {
   const x = this.point.x;
   const y = this.point.y;
   const t = 0.5;
   const d = MathUtil.distance(this.point, point);
   return { x, y, t, d } as Projection;
 }
開發者ID:arpitsaan,項目名稱:ShapeShifter,代碼行數:7,代碼來源:PointCalculator.ts

示例6: Command

 start.getCommands().forEach((startCmd, i) => {
   const endCmd = end.getCommands()[i];
   const points: Point[] = [];
   for (let j = 0; j < startCmd.points.length; j++) {
     const p1 = startCmd.points[j];
     const p2 = endCmd.points[j];
     if (p1 && p2) {
       // The 'start' point of the first Move command in a path
       // will be undefined. Skip it.
       const px = MathUtil.lerp(p1.x, p2.x, fraction);
       const py = MathUtil.lerp(p1.y, p2.y, fraction);
       points.push({ x: px, y: py });
     } else {
       points.push(undefined);
     }
   }
   // TODO: avoid re-generating unique ids on each animation frame.
   newCommands.push(new Command(startCmd.type, points));
 });
開發者ID:arpitsaan,項目名稱:ShapeShifter,代碼行數:19,代碼來源:PathUtil.ts

示例7:

 const getScoreFn = (a: Command, b: Command) => {
   const charA = a.type;
   const charB = b.type;
   if (charA !== charB && !a.canConvertTo(charB) && !b.canConvertTo(charA)) {
     return MISMATCH;
   }
   const { x, y } = a.end;
   const start = { x, y };
   const end = b.end;
   return 1 / Math.max(MATCH, MathUtil.distance(start, end));
 };
開發者ID:arpitsaan,項目名稱:ShapeShifter,代碼行數:11,代碼來源:AutoAwesome.ts

示例8: toCommand

 toCommand() {
   let points: Point[];
   switch (this.svgChar) {
     case 'L':
     case 'Z':
       points = [this.p1, this.p2];
       break;
     case 'Q':
       const cp = {
         x: MathUtil.lerp(this.p1.x, this.p2.x, 0.5),
         y: MathUtil.lerp(this.p1.y, this.p2.y, 0.5),
       };
       points = [this.p1, cp, this.p2];
       break;
     case 'C':
       const cp1 = {
         x: MathUtil.lerp(this.p1.x, this.p2.x, 1 / 3),
         y: MathUtil.lerp(this.p1.y, this.p2.y, 1 / 3),
       };
       const cp2 = {
         x: MathUtil.lerp(this.p1.x, this.p2.x, 2 / 3),
         y: MathUtil.lerp(this.p1.y, this.p2.y, 2 / 3),
       };
       points = [this.p1, cp1, cp2, this.p2];
       break;
     default:
       throw new Error('Invalid command type: ' + this.svgChar);
   }
   return new CommandBuilder(this.svgChar, points).setId(this.id).build();
 }
開發者ID:arpitsaan,項目名稱:ShapeShifter,代碼行數:30,代碼來源:LineCalculator.ts

示例9: if

  commands.forEach(cmd => {
    const start = cmd.start;
    const end = cmd.end;

    if (start && !MathUtil.arePointsEqual(start, previousEndPoint)) {
      // This is to support the case where the list of commands
      // is size fragmented.
      ctx.moveTo(start.x, start.y);
    }

    if (cmd.type === 'M') {
      ctx.moveTo(end.x, end.y);
    } else if (cmd.type === 'L') {
      ctx.lineTo(end.x, end.y);
    } else if (cmd.type === 'Q') {
      ctx.quadraticCurveTo(cmd.points[1].x, cmd.points[1].y, cmd.points[2].x, cmd.points[2].y);
    } else if (cmd.type === 'C') {
      ctx.bezierCurveTo(
        cmd.points[1].x,
        cmd.points[1].y,
        cmd.points[2].x,
        cmd.points[2].y,
        cmd.points[3].x,
        cmd.points[3].y,
      );
    } else if (cmd.type === 'Z') {
      if (MathUtil.arePointsEqual(start, previousEndPoint)) {
        ctx.closePath();
      } else {
        // This is to support the case where the list of commands
        // is size fragmented.
        ctx.lineTo(end.x, end.y);
      }
    }
    previousEndPoint = end;
  });
開發者ID:arpitsaan,項目名稱:ShapeShifter,代碼行數:36,代碼來源:CanvasUtil.ts

示例10: shift

 private shift(subIdx: number, calcOffsetFn: (offset: number, numCommands: number) => number) {
   const sps = this.findSubPathStateLeaf(subIdx);
   const numCmdsInSubPath = _.sumBy(sps.getCommandStates(), cs => cs.getCommands().length);
   if (numCmdsInSubPath <= 1) {
     return this;
   }
   const firstCmd = sps.getCommandStates()[0].getCommands()[0];
   const lastCmd = _.last(_.last(sps.getCommandStates()).getCommands());
   if (!MathUtil.arePointsEqual(firstCmd.end, lastCmd.end)) {
     // TODO: in some cases there may be rounding errors that cause a closed subpath
     // to show up as non-closed. is there anything we can do to alleviate this?
     console.warn('Ignoring attempt to shift a non-closed subpath');
     return this;
   }
   this.setSubPathStateLeaf(
     subIdx,
     sps
       .mutate()
       .setShiftOffset(calcOffsetFn(sps.getShiftOffset(), numCmdsInSubPath))
       .build(),
   );
   return this;
 }
開發者ID:arpitsaan,項目名稱:ShapeShifter,代碼行數:23,代碼來源:Path.ts


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