You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
2.5 KiB

10 months ago
#include "stdafx.h"
#include "BranchPoint.h"
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
10 months ago
using namespace std;
// �򵥵�·����Ϣ��·���滮��ֱ�ӽ���
struct Path
{
vector<string> wirelist; // ·���е�������
vector<P> points; // ·���ϵĵ㣬���������ͷ�֧��
vector<int> inOut; // ��������������Ϊ0������Ϊ1,��֧��Ϊ-1
double dia; // ·��ֱ��
Path()
{
dia = 0;
10 months ago
}
// ����path�������
inline int size()
{
assert(inOut.size() == points.size());
10 months ago
return points.size();
}
// ��·���о����Ŀ����ͷ�֧�㶼���dz�ʹ�ù���״̬
void markPoint()
{
for (int i = 0; i < points.size(); i++)
{
P &tp = points[i];
if (tp.type == 1 || tp.type == 2)
{
BranchPoint *pb = branchPointSet.getBranchPointPointer(tp.ref);
pb->used = true;
pb->pc1->used = true;
pb->pc2->used = true;
10 months ago
}
else if (tp.type == 0)
{
clipSet.c[tp.ref].used = true;
10 months ago
}
}
}
// �̶����о����ķ�֧��
void fixBranchPoint()
{
for (int i = 0; i < points.size(); i++)
{
P &tp = points[i];
if (tp.type == 1)
{
BranchPoint *pb = branchPointSet.getBranchPointPointer(tp.ref);
10 months ago
pb->fix();
}
}
}
// ����·���Ϸ���
void illegalCheck()
{
map<P, int> vis;
for (int i = 0; i < points.size(); i++)
{
assert(vis[points[i]] == 0);
vis[points[i]] = 1;
if (i == 0 || i == points.size() - 1)
{
assert(points[i].type == 3);
10 months ago
}
if (points[i].type != 0)
{
assert(inOut[i] < 0);
10 months ago
}
}
}
// ��·���еĵ㷭ת���������򣬲�����inOut����
void processDir()
{
for (int j = 0; j < points.size(); j++)
{
if (points[j].type != 0)
{
10 months ago
inOut.push_back(-1);
continue;
}
double reverse = 0;
P dir = dirP(points[j]);
if (j != 0)
{
reverse += pi / 2 - Angle(points[j] - points[j - 1], dir);
10 months ago
}
if (j != points.size() - 1)
{
reverse += pi / 2 - Angle(points[j + 1] - points[j], dir);
10 months ago
}
if (reverse < 0)
{
// points[j].reverse();
10 months ago
inOut.push_back(1);
}
else
inOut.push_back(0);
10 months ago
}
}
// ��·��ȷ���󣬴���һЩ����pass���洦������Ϣ
void postProcess()
{
10 months ago
this->fixBranchPoint();
// this->processDir();
10 months ago
this->markPoint();
}
// ��ת����·��
void reverse()
{
std::reverse(points.begin(), points.end());
assert(inOut.size() == points.size());
for (int i = 0; i < points.size(); i++)
{
if (inOut[i] != -1)
{
inOut[i] = inOut[i] ^ 1;
10 months ago
points[i].reverse();
}
}
}
};