fix(layer): 去除线图层绘制异常的问题

处理线图层数据存在重复点的时候,绘制的线图层粗细表现异常的问题。
This commit is contained in:
ParryQiu 2020-08-27 17:22:34 +08:00
parent f3474341cb
commit 687986a6d5
1 changed files with 13 additions and 4 deletions

View File

@ -22,15 +22,26 @@ export function computeMiter(
export function computeNormal(out: vec2, dir: vec2) {
return vec2.set(out, -dir[1], dir[0]);
}
export function direction(out: vec2, a: vec2, b: vec2) {
vec2.sub(out, a, b);
vec2.normalize(out, out);
return out;
}
function isPointEqual(a: vec2, b: vec2) {
return a[0] === b[0] && a[1] === b[1];
}
function getArrayUnique(matrix: number[][]) {
const result: number[][] = [];
matrix.map((item) => {
item.sort((a, b) => b - a);
result.push(item);
});
return result;
}
export interface IExtrudeLineOption {
join: string;
cap: string;
@ -80,16 +91,14 @@ export default class ExtrudePolyline {
this.started = false;
this.normal = null;
this.totalDistance = 0;
// 去除数组里重复的点
points = getArrayUnique(points);
const total = points.length;
let count = complex.startIndex;
for (let i = 1; i < total; i++) {
const last = points[i - 1] as vec2;
const cur = points[i] as vec2;
const next = i < points.length - 1 ? points[i + 1] : null;
// 如果当前点和前一点相同,跳过
if (isPointEqual(last, cur)) {
continue;
}
const amt = this.segment(complex, count, last, cur, next as vec2);
count += amt;
}