本文整理汇总了TypeScript中app/model/paths.Path.getSubPaths方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Path.getSubPaths方法的具体用法?TypeScript Path.getSubPaths怎么用?TypeScript Path.getSubPaths使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app/model/paths.Path
的用法示例。
在下文中一共展示了Path.getSubPaths方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: autoAddCollapsingSubPaths
export function autoAddCollapsingSubPaths(from: Path, to: Path): [Path, Path] {
const deleteCollapsingSubPathsFn = (p: Path) => {
return p.getSubPaths().some(s => s.isCollapsing())
? p
.mutate()
.deleteCollapsingSubPaths()
.build()
: p;
};
from = deleteCollapsingSubPathsFn(from);
to = deleteCollapsingSubPathsFn(to);
const numFrom = from.getSubPaths().length;
const numTo = to.getSubPaths().length;
if (numFrom === numTo) {
return [from, to];
}
// TODO: allow the user to specify the location of collapsing paths?
const pm = (numFrom < numTo ? from : to).mutate();
for (let subIdx = Math.min(numFrom, numTo); subIdx < Math.max(numFrom, numTo); subIdx++) {
const opp = numFrom < numTo ? to : from;
const pole = opp.getPoleOfInaccessibility(subIdx);
pm.addCollapsingSubPath(pole, opp.getSubPath(subIdx).getCommands().length);
}
if (numFrom < numTo) {
from = pm.build();
} else {
to = pm.build();
}
return [from, to];
}
示例2: autoConvert
export function autoConvert(from: Path, to: Path): [Path, Path] {
[from, to] = autoUnconvertSubPaths(from, to);
const numFrom = from.getSubPaths().length;
const numTo = to.getSubPaths().length;
for (let subIdx = 0; subIdx < Math.min(numFrom, numTo); subIdx++) {
// Only auto convert when the number of commands in both canvases
// are equal. Otherwise we'll wait for the user to add more points.
[from, to] = autoConvertSubPath(from, to, subIdx);
}
return [from, to];
}
示例3:
const deleteCollapsingSubPathsFn = (p: Path) => {
return p.getSubPaths().some(s => s.isCollapsing())
? p
.mutate()
.deleteCollapsingSubPaths()
.build()
: p;
};
示例4: autoFix
export function autoFix(from: Path, to: Path): [Path, Path] {
[from, to] = autoUnconvertSubPaths(from, to);
[from, to] = autoAddCollapsingSubPaths(from, to);
[from, to] = orderSubPaths(from, to);
const min = Math.min(from.getSubPaths().length, to.getSubPaths().length);
for (let subIdx = 0; subIdx < min; subIdx++) {
// Pass the command with the larger subpath as the 'from' command.
const numFromCmds = from.getSubPath(subIdx).getCommands().length;
const numToCmds = to.getSubPath(subIdx).getCommands().length;
const shouldSwap = numFromCmds < numToCmds;
if (shouldSwap) {
[from, to] = [to, from];
}
[from, to] = alignSubPath(from, to, subIdx);
if (shouldSwap) {
[from, to] = [to, from];
}
}
for (let subIdx = 0; subIdx < min; subIdx++) {
[from, to] = permuteSubPath(from, to, subIdx);
}
return [from, to];
}
示例5: orderSubPaths
/**
* Reorders the subpaths in each path to minimize the distance each shape will
* travel during the morph.
*/
function orderSubPaths(from: Path, to: Path): [Path, Path] {
if (from.getSubPaths().length > 8 || to.getSubPaths().length > 8) {
// Don't attempt to order paths with many subpaths.
return [from, to];
}
const shouldSwap = from.getSubPaths().length < to.getSubPaths().length;
if (shouldSwap) {
[from, to] = [to, from];
}
const fromSubPaths = from.getSubPaths();
const toSubPaths = to.getSubPaths();
const distances = fromSubPaths.map((f, i) => {
return toSubPaths.map((t, j) => {
const pole1 = from.getPoleOfInaccessibility(i);
const pole2 = to.getPoleOfInaccessibility(j);
return MathUtil.distance(pole1, pole2);
});
});
let min = Infinity;
let best: number[] = [];
(function recurseFn(arr: number[], order: number[] = []) {
if (order.length === toSubPaths.length) {
let sum = 0;
for (let i = 0; i < order.length; i++) {
sum += distances[order[i]][i];
}
if (sum < min) {
min = sum;
best = order;
}
return;
}
for (let i = 0; i < arr.length; i++) {
const [cur] = arr.splice(i, 1);
recurseFn([...arr], [...order, cur]);
if (arr.length) {
arr.splice(i, 0, cur);
}
}
})(_.range(fromSubPaths.length));
const pm = from.mutate();
for (let i = 0; i < best.length; i++) {
const m = best[i];
pm.moveSubPath(m, i);
for (let j = i + 1; j < best.length; j++) {
const n = best[j];
if (n < m) {
best[j]++;
}
}
}
from = pm.build();
if (shouldSwap) {
[from, to] = [to, from];
}
return [from, to];
}