|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import { Vector3 } from 'three';
|
|
|
|
|
|
|
|
|
|
import { Curve } from '../DatabaseServices/Curve';
|
|
|
|
|
import { angle, equal } from './GeUtils';
|
|
|
|
|
|
|
|
|
|
//路线
|
|
|
|
|
export interface Route
|
|
|
|
@ -14,7 +15,7 @@ export interface Route
|
|
|
|
|
interface Stand
|
|
|
|
|
{
|
|
|
|
|
//位置
|
|
|
|
|
postion: Vector3;
|
|
|
|
|
position: Vector3;
|
|
|
|
|
//路径
|
|
|
|
|
routes: Array<Route>;
|
|
|
|
|
}
|
|
|
|
@ -72,7 +73,7 @@ export class RegionParse
|
|
|
|
|
this.m_RegionsOutline.push(routeS);
|
|
|
|
|
//计数增加
|
|
|
|
|
for (let route of routeS)
|
|
|
|
|
this.AddCuUsedCout(route.curve, 1);
|
|
|
|
|
this.AddCuUsedCount(route.curve, 1);
|
|
|
|
|
this.FindMinRegion(wayS);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -97,7 +98,7 @@ export class RegionParse
|
|
|
|
|
let needFinds = new Set<Stand>();
|
|
|
|
|
standS.forEach(w => needFinds.add(w));
|
|
|
|
|
//已经走过的
|
|
|
|
|
let wayedStands = new Set<Stand>();
|
|
|
|
|
let passingStands = new Set<Stand>();
|
|
|
|
|
|
|
|
|
|
let regs: RegionRouteS = [];
|
|
|
|
|
|
|
|
|
@ -106,7 +107,7 @@ export class RegionParse
|
|
|
|
|
//找到最小站
|
|
|
|
|
let minStand = this.FindMinStand(needFinds);
|
|
|
|
|
//添加为已经计算
|
|
|
|
|
wayedStands.add(minStand);
|
|
|
|
|
passingStands.add(minStand);
|
|
|
|
|
needFinds.delete(minStand);
|
|
|
|
|
|
|
|
|
|
//逆时针搜索
|
|
|
|
@ -131,12 +132,12 @@ export class RegionParse
|
|
|
|
|
wayS.forEach(w =>
|
|
|
|
|
{
|
|
|
|
|
//站点拓展,如果该地点没有被走过,那么加入到需要搜寻的站点表
|
|
|
|
|
if (!wayedStands.has(w))
|
|
|
|
|
if (!passingStands.has(w))
|
|
|
|
|
needFinds.add(w);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (let route of routeS)
|
|
|
|
|
this.AddCuUsedCout(route.curve, 1);
|
|
|
|
|
this.AddCuUsedCount(route.curve, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -163,11 +164,11 @@ export class RegionParse
|
|
|
|
|
minStand = stand;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (minStand.postion.y > stand.postion.y)
|
|
|
|
|
if (minStand.position.y > stand.position.y)
|
|
|
|
|
{
|
|
|
|
|
minStand = stand;
|
|
|
|
|
}
|
|
|
|
|
else if (minStand.postion.y === stand.postion.y && minStand.postion.x > stand.postion.x)
|
|
|
|
|
else if (minStand.position.y === stand.position.y && minStand.position.x > stand.position.x)
|
|
|
|
|
{
|
|
|
|
|
minStand = stand;
|
|
|
|
|
}
|
|
|
|
@ -175,8 +176,6 @@ export class RegionParse
|
|
|
|
|
return minStand;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构建节点图 this.m_NodeMap 将初始化
|
|
|
|
|
*
|
|
|
|
@ -199,13 +198,18 @@ export class RegionParse
|
|
|
|
|
{
|
|
|
|
|
s.routes.sort((r1, r2) =>
|
|
|
|
|
{
|
|
|
|
|
let v1 = r1.to.postion.clone().sub(s.postion);
|
|
|
|
|
let v2 = r2.to.postion.clone().sub(s.postion);
|
|
|
|
|
let a1 = Math.atan2(v1.y, v1.x);
|
|
|
|
|
let a2 = Math.atan2(v2.y, v2.x);
|
|
|
|
|
if (a1 < 0) a1 += Math.PI * 2;
|
|
|
|
|
if (a2 < 0) a2 += Math.PI * 2;
|
|
|
|
|
return a1 < a2 ? -1 : 1;
|
|
|
|
|
let a1: number, a2: number;
|
|
|
|
|
if (equal(r1.curve.StartPoint, s.position))
|
|
|
|
|
a1 = angle(r1.curve.GetFistDeriv(0));
|
|
|
|
|
else
|
|
|
|
|
a1 = angle(r1.curve.GetFistDeriv(r1.curve.EndParam).negate());
|
|
|
|
|
|
|
|
|
|
if (equal(r2.curve.StartPoint, s.position))
|
|
|
|
|
a2 = angle(r2.curve.GetFistDeriv(0));
|
|
|
|
|
else
|
|
|
|
|
a2 = angle(r2.curve.GetFistDeriv(r1.curve.EndParam).negate());
|
|
|
|
|
|
|
|
|
|
return a1 - a2;
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
@ -225,7 +229,7 @@ export class RegionParse
|
|
|
|
|
if (this.m_NodeMap.has(gp))
|
|
|
|
|
return this.m_NodeMap.get(gp);
|
|
|
|
|
|
|
|
|
|
let stand = { postion: gp, routes: [] };
|
|
|
|
|
let stand = { position: gp, routes: [] };
|
|
|
|
|
this.m_NodeMap.set(p, stand);
|
|
|
|
|
return stand;
|
|
|
|
|
}
|
|
|
|
@ -255,7 +259,7 @@ export class RegionParse
|
|
|
|
|
lastCurve: Curve, //上一条线索引
|
|
|
|
|
wayStands: Set<Stand>, //走过的站
|
|
|
|
|
routeS: Set<Route>, //走过的路
|
|
|
|
|
cuMaxiumCout: number, //允许最大的行走次数
|
|
|
|
|
cuMaximumCount: number, //允许最大的行走次数
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
let routeCount = nowStand.routes.length;
|
|
|
|
@ -281,8 +285,8 @@ export class RegionParse
|
|
|
|
|
//下一站
|
|
|
|
|
let route = nowStand.routes[index];
|
|
|
|
|
|
|
|
|
|
let usedCout = this.GetCuUsedCount(route.curve);
|
|
|
|
|
if (usedCout >= cuMaxiumCout)
|
|
|
|
|
let usedCount = this.GetCuUsedCount(route.curve);
|
|
|
|
|
if (usedCount >= cuMaximumCount)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
//如果发现这条路已经走回去,中途回路
|
|
|
|
@ -307,7 +311,7 @@ export class RegionParse
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
//在下个路口试着往前走
|
|
|
|
|
let isFind = this.FindRegion(firstS, route.to, route.curve, wayStands, routeS, cuMaxiumCout);
|
|
|
|
|
let isFind = this.FindRegion(firstS, route.to, route.curve, wayStands, routeS, cuMaximumCount);
|
|
|
|
|
if (isFind)
|
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
@ -329,7 +333,7 @@ export class RegionParse
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
private AddCuUsedCout(cu: Curve, add: number)
|
|
|
|
|
private AddCuUsedCount(cu: Curve, add: number)
|
|
|
|
|
{
|
|
|
|
|
this.m_CountCu.set(cu, this.GetCuUsedCount(cu) + add);
|
|
|
|
|
}
|
|
|
|
|