From 594c33cd52e95c1b3336d32c80f31e84859d3236 Mon Sep 17 00:00:00 2001 From: ChenX Date: Wed, 29 May 2019 12:02:11 +0800 Subject: [PATCH] =?UTF-8?q?!319=20z=E6=96=B9=E5=90=91=E5=8F=8A=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E6=96=B9=E5=90=91=E4=B8=80=E6=AC=A1=E6=80=A7=E5=90=88?= =?UTF-8?q?=E5=B9=B6=20Merge=20pull=20request=20!319=20from=20=E8=82=96?= =?UTF-8?q?=E8=AF=97=E9=9B=85/zJoin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Add-on/Join.ts | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/Add-on/Join.ts b/src/Add-on/Join.ts index f1a68f93f..9255936e6 100644 --- a/src/Add-on/Join.ts +++ b/src/Add-on/Join.ts @@ -11,7 +11,7 @@ import { Polyline } from "../DatabaseServices/Polyline"; import { Command } from "../Editor/CommandMachine"; import { PromptStatus } from "../Editor/PromptResult"; import { FuzzDirection } from "../Geometry/FuzzVector"; -import { ptToString } from "../Geometry/GeUtils"; +import { ptToString, comparePoint } from "../Geometry/GeUtils"; import { PlaneExt } from "../Geometry/Plane"; export class Command_Join implements Command @@ -214,29 +214,30 @@ export class Command_Join implements Command } private JoinSameTypeBrs(brs: Board[]) { - while (brs.length > 0) + let sortFn = comparePoint("xyz"); + //排序 使横向合并优先 + brs.sort((a, b) => + { + return sortFn(a.MinPoint, b.MinPoint); + }); + while (brs.length > 1) { let br = brs.shift();//取第一个 - - while (brs.length > 0) + //剩余的 无法合并的板件 + let remBrs = brs.filter(b => { - //剩余的 无法合并的板件 - let remBrs = brs.filter(b => + let isSuccess = br.Join(b); + if (isSuccess) { - let isSuccess = br.Join(b); - if (isSuccess) - { - b.Erase(); - return false; - } - return true; - }); + b.Erase(); + return false; + } + return true; + }); - if (remBrs.length === brs.length) - break;//退出循环.下一个 - else - brs = remBrs; //更新为剩下的板件列表 - } + if (remBrs.length !== brs.length) + remBrs.push(br);//将合并成功的板件推回尾部 + brs = remBrs;//更新 } } }