本文整理汇总了TypeScript中app/model/paths.Path.isClockwise方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Path.isClockwise方法的具体用法?TypeScript Path.isClockwise怎么用?TypeScript Path.isClockwise使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app/model/paths.Path
的用法示例。
在下文中一共展示了Path.isClockwise方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: permuteSubPath
function permuteSubPath(from: Path, to: Path, subIdx: number): [Path, Path] {
if (from.isClockwise(subIdx) !== to.isClockwise(subIdx)) {
// Make sure the paths share the same direction.
to = to
.mutate()
.reverseSubPath(subIdx)
.build();
}
// Create and return a list of reversed and shifted from paths to test.
// Each generated 'from path' will be aligned with the target 'to path'.
const fromPaths: Path[] = [from];
if (from.getSubPath(subIdx).isClosed()) {
for (let i = 1; i < from.getSubPath(subIdx).getCommands().length - 1; i++) {
// TODO: we need to find a way to reduce the number of paths to try.
fromPaths.push(
from
.mutate()
.shiftSubPathBack(subIdx, i)
.build(),
);
}
}
let bestFromPath = from;
let min = Infinity;
for (const fromPath of fromPaths) {
const fromCmds = fromPath.getSubPath(subIdx).getCommands();
let sumOfSquares = 0;
const toCmds = to.getSubPath(subIdx).getCommands();
fromCmds.forEach(
(c, cmdIdx) => (sumOfSquares += MathUtil.distance(c.end, toCmds[cmdIdx].end) ** 2),
);
if (sumOfSquares < min) {
min = sumOfSquares;
bestFromPath = fromPath;
}
}
return [bestFromPath, to];
}