实现了直线的Join

pull/59/head
ChenX 7 years ago
parent fb0c909497
commit 27dc66e6c4

@ -153,3 +153,39 @@ test('拉伸直线的夹点', () =>
expect(line.StartPoint).toMatchSnapshot(); expect(line.StartPoint).toMatchSnapshot();
expect(line.EndPoint).toMatchSnapshot(); expect(line.EndPoint).toMatchSnapshot();
}); });
test('直线合并', () =>
{
let l1 = new Line(new Vector3(0, 0, 0), new Vector3(0, 5, 0));
let l2 = new Line(new Vector3(0, 10, 0), new Vector3(0, 5, 0));
//终点对终点
let jOk = l1.Join(l2);
expect(jOk).toBeTruthy();
//包含
l1 = new Line(new Vector3(0, 15, 0), new Vector3(0, 5, 0));
expect(l1.Join(l2)).toBeTruthy();
//终点对起点
l1 = new Line(new Vector3(0, 15, 0), new Vector3(0, 10, 0));
expect(l1.Join(l2)).toBeTruthy();
//起点对终点
l1 = new Line(new Vector3(0, 5, 0), new Vector3(0, 15, 0));
expect(l1.Join(l2)).toBeTruthy();
//不平行1
l1 = new Line(new Vector3(1, 5, 0), new Vector3(0, 15, 0));
expect(l1.Join(l2)).toBeFalsy();
});
test('直线合并不平行', () =>
{
let l1 = new Line(new Vector3(0, 0, 0), new Vector3(0, 5, 0));
let l2 = new Line(new Vector3(1, 10, 0), new Vector3(0, 5, 0));
expect(l1.Join(l2)).toBeFalsy();
});

@ -0,0 +1,28 @@
import { app } from "../ApplicationServices/Application";
import { Curve } from '../DatabaseServices/Curve';
import { Command } from "../Editor/CommandMachine";
import { PromptStatus } from "../Editor/PromptResult";
export class Command_Join implements Command
{
async exec()
{
let cu1Res = await app.m_Editor.GetEntity();
if (cu1Res.Status != PromptStatus.OK) return;
let cu2Res = await app.m_Editor.GetEntity();
if (cu2Res.Status != PromptStatus.OK) return;
if (cu1Res.Entity instanceof Curve)
{
if (cu2Res.Entity instanceof Curve)
{
let bIsOK = cu1Res.Entity.Join(cu2Res.Entity);
if (bIsOK)
{
cu2Res.Entity.Erase();
}
}
}
}
}

@ -76,7 +76,7 @@ export class Command_TestOffset implements Command
if (cu instanceof Polyline) if (cu instanceof Polyline)
{ {
c.z = (IsPointInPolyLine(cu, p)) ? -1 : 1; c.z = (IsPointInPolyLine(cu, p)) ? 1 : -1;
} }
lastpls = cu.GetOffsetCurves(p.distanceTo(cu.GetClosestPointTo(p, !cu.IsClose)) * Math.sign(c.z)); lastpls = cu.GetOffsetCurves(p.distanceTo(cu.GetClosestPointTo(p, !cu.IsClose)) * Math.sign(c.z));

@ -3,7 +3,7 @@ import * as THREE from 'three';
import { Geometry, Matrix4, Object3D, Vector3, Box3 } from 'three'; import { Geometry, Matrix4, Object3D, Vector3, Box3 } from 'three';
import { ColorMaterial } from '../Common/ColorPalette'; import { ColorMaterial } from '../Common/ColorPalette';
import { equal, polar } from '../Geometry/GeUtils'; import { equal, polar, isParallelTo } from '../Geometry/GeUtils';
import { RenderType } from '../GraphicsSystem/Enum'; import { RenderType } from '../GraphicsSystem/Enum';
import import
{ {
@ -218,6 +218,33 @@ export class Line extends Curve
} }
} }
Join(cu: Curve): boolean
{
if (cu instanceof Line)
{
//如果不平行
if (!isParallelTo(this.GetFistDeriv(0), cu.GetFistDeriv(0)))
return false;
let param1 = this.GetParamAtPoint(cu.StartPoint);
let param2 = this.GetParamAtPoint(cu.EndPoint);
if (this.PtOnCurve(cu.StartPoint))
{
if (!this.ParamOnCurve(param2))
this.Extend(param2);
return true;
}
else if (this.PtOnCurve(cu.EndPoint))
{
if (!this.ParamOnCurve(param1))
this.Extend(param1);
return true;
}
}
return false;
};
Reverse() Reverse()
{ {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();

@ -27,6 +27,7 @@ import { Command_Export } from '../Add-on/Export';
import { Command_Extend } from '../Add-on/Extends'; import { Command_Extend } from '../Add-on/Extends';
import { CommandFillet } from '../Add-on/Fillet'; import { CommandFillet } from '../Add-on/Fillet';
import { Command_GenerateCode } from '../Add-on/GenerateCode'; import { Command_GenerateCode } from '../Add-on/GenerateCode';
import { Command_Join } from '../Add-on/Join';
import { LoadImg } from '../Add-on/LoadImg'; import { LoadImg } from '../Add-on/LoadImg';
import { Command_Move } from '../Add-on/Move'; import { Command_Move } from '../Add-on/Move';
import { Command_Offset, Command_TestOffset } from '../Add-on/Offset'; import { Command_Offset, Command_TestOffset } from '../Add-on/Offset';
@ -162,6 +163,7 @@ export function registerCommand()
commandMachine.RegisterCommand("code", new Command_GenerateCode()); commandMachine.RegisterCommand("code", new Command_GenerateCode());
commandMachine.RegisterCommand("join", new Command_Join());
// commandMachine.RegisterCommand("st", new SaveTarget()) // commandMachine.RegisterCommand("st", new SaveTarget())
// commandMachine.RegisterCommand("rt", new RevTarget()) // commandMachine.RegisterCommand("rt", new RevTarget())

Loading…
Cancel
Save