• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript common.MathUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript common.Matrix类代码示例发布时间:2022-05-25
下一篇:
TypeScript common.ColorUtil类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap