本文整理汇总了TypeScript中app/scripts/common.MathUtil.arePointsEqual方法的典型用法代码示例。如果您正苦于以下问题:TypeScript MathUtil.arePointsEqual方法的具体用法?TypeScript MathUtil.arePointsEqual怎么用?TypeScript MathUtil.arePointsEqual使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app/scripts/common.MathUtil
的用法示例。
在下文中一共展示了MathUtil.arePointsEqual方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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);
}
示例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);
}
示例3: 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;
});
示例4: 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;
}
示例5: intersects
intersects(line: Line) {
if (MathUtil.arePointsEqual(this.p1, this.p2)) {
// Points can't be intersected.
return [];
}
// Check to see if the line from (a,b) to (c,d) intersects
// with the line from (p,q) to (r,s).
const { x: a, y: b } = this.p1;
const { x: c, y: d } = this.p2;
const { p1: { x: p, y: q }, p2: { x: r, y: s } } = line;
const det = round((c - a) * (s - q) - (r - p) * (d - b));
if (det === 0) {
// Then the two lines are parallel. In our case it is fine to
// return an empty list, even though the lines may technically
// be collinear.
return [];
} else {
const t = round(((s - q) * (r - a) + (p - r) * (s - b)) / det);
const u = round(((b - d) * (r - a) + (c - a) * (s - b)) / det);
return 0 <= t && t <= 1 && (0 <= u && u <= 1) ? [t] : [];
}
}
示例6: showMouse
showMouse(mousePoint: Point) {
if (!this.mousePoint || !MathUtil.arePointsEqual(this.mousePoint, mousePoint)) {
this.mousePoint = mousePoint;
this.draw();
}
}
示例7: shiftCommands
/**
* Returns a list of shifted commands.
*/
function shiftCommands(subPathState: SubPathState, cmds: Command[]) {
let shiftOffset = subPathState.getShiftOffset();
if (
!shiftOffset ||
cmds.length === 1 ||
!MathUtil.arePointsEqual(_.first(cmds).end, _.last(cmds).end)
) {
// If there is no shift offset, the sub path is one command long,
// or if the sub path is not closed, then do nothing.
return cmds;
}
const numCommands = cmds.length;
if (subPathState.isReversed()) {
shiftOffset *= -1;
shiftOffset += numCommands - 1;
}
// If the last command is a 'Z', replace it with a line before we shift.
const lastCmd = _.last(cmds);
if (lastCmd.type === 'Z') {
// TODO: replacing the 'Z' messes up certain stroke-linejoin values
cmds[numCommands - 1] = lastCmd
.mutate()
.setSvgChar('L')
.setPoints(...lastCmd.points)
.build();
}
const newCmds: Command[] = [];
// Handle these case separately cause they are annoying and I'm sick of edge cases.
if (shiftOffset === 1) {
newCmds.push(
cmds[0]
.mutate()
.setPoints(cmds[0].start, cmds[1].end)
.build(),
);
for (let i = 2; i < cmds.length; i++) {
newCmds.push(cmds[i]);
}
newCmds.push(cmds[1]);
return newCmds;
} else if (shiftOffset === numCommands - 1) {
newCmds.push(
cmds[0]
.mutate()
.setPoints(cmds[0].start, cmds[numCommands - 2].end)
.build(),
);
newCmds.push(_.last(cmds));
for (let i = 1; i < cmds.length - 1; i++) {
newCmds.push(cmds[i]);
}
return newCmds;
}
// Shift the sequence of commands. After the shift, the original move
// command will be at index 'numCommands - shiftOffset'.
for (let i = 0; i < numCommands; i++) {
newCmds.push(cmds[(i + shiftOffset) % numCommands]);
}
// The first start point will either be undefined,
// or the end point of the previous sub path.
const prevMoveCmd = newCmds.splice(numCommands - shiftOffset, 1)[0];
newCmds.push(newCmds.shift());
newCmds.unshift(
cmds[0]
.mutate()
.setPoints(prevMoveCmd.start, _.last(newCmds).end)
.build(),
);
return newCmds;
}