Merge pull request #494 from ParryQiu/master

fix(layer): 解决线图层绘制异常的问题
This commit is contained in:
@thinkinggis 2020-08-28 10:43:27 +08:00 committed by GitHub
commit 2f2b4940a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View File

@ -1,2 +1,2 @@
const version = '2.2.33'; const version = '2.2.32';
export { version }; export { version };

View File

@ -22,15 +22,26 @@ export function computeMiter(
export function computeNormal(out: vec2, dir: vec2) { export function computeNormal(out: vec2, dir: vec2) {
return vec2.set(out, -dir[1], dir[0]); return vec2.set(out, -dir[1], dir[0]);
} }
export function direction(out: vec2, a: vec2, b: vec2) { export function direction(out: vec2, a: vec2, b: vec2) {
vec2.sub(out, a, b); vec2.sub(out, a, b);
vec2.normalize(out, out); vec2.normalize(out, out);
return out; return out;
} }
function isPointEqual(a: vec2, b: vec2) { function isPointEqual(a: vec2, b: vec2) {
return a[0] === b[0] && a[1] === b[1]; 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 { export interface IExtrudeLineOption {
join: string; join: string;
cap: string; cap: string;
@ -80,16 +91,14 @@ export default class ExtrudePolyline {
this.started = false; this.started = false;
this.normal = null; this.normal = null;
this.totalDistance = 0; this.totalDistance = 0;
// 去除数组里重复的点
points = getArrayUnique(points);
const total = points.length; const total = points.length;
let count = complex.startIndex; let count = complex.startIndex;
for (let i = 1; i < total; i++) { for (let i = 1; i < total; i++) {
const last = points[i - 1] as vec2; const last = points[i - 1] as vec2;
const cur = points[i] as vec2; const cur = points[i] as vec2;
const next = i < points.length - 1 ? points[i + 1] : null; 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); const amt = this.segment(complex, count, last, cur, next as vec2);
count += amt; count += amt;
} }

View File

@ -6,6 +6,7 @@ describe('template', () => {
el.id = 'test-div-id'; el.id = 'test-div-id';
el.style.width = '500px'; el.style.width = '500px';
el.style.height = '500px'; el.style.height = '500px';
el.style.position = 'absolute';
document.querySelector('body')?.appendChild(el); document.querySelector('body')?.appendChild(el);
const scene = new Scene({ const scene = new Scene({
id: 'test-div-id', id: 'test-div-id',