#pragma once
#include "Datastruct.h"
#include "BAS_DRAW_FUN.h"
#include "BaseLine.h"
#include <cmath>
#include <vector>
#include<algorithm>
using namespace std;

class CDrawRoad :public BAS_DRAW_FUN {
public:
	//关联交点半径数组（xy点位 z半径）
	vector<DPoint3d>ConRDArray;
	int isDrawPDB;
	int isIniRdaious; // 初始化内外侧半径时使用

	CDrawRoad();
	//构造函数 传入单条道路 
	CDrawRoad(Road RoadData);
	//构造函数 传入路网数组
	CDrawRoad(vector<Road> RoadData);
	//析构函数
	virtual ~CDrawRoad();
	//路网原始数组
	vector<Road> m_RoadData;
	//对原始路网检测后的路网数组
	vector<Road>m_RoadDataCheck;
	//路网内包含的道路个数
	int m_RoadNum;
	//路网边线
	vector<Rd_BX>JDdataOutFinally;
	//路网边线（炸开）
	vector<Road_BX>JDdataOutFinally_DRAW;
	//路网分段数组 记录每一段的起终里程和绘制模式
	vector<DLDrawFD>DrawFDArray;

	vector<DPoint3d>AllPoints;
	vector<DPoint3d>LinearPoints;
	vector<DPoint3d>CurvesPoints;
	double LuMianHou; //路面厚度

	//根据道路内部记录的路网编号，将道路分组
	void CheckRD(Road rd1, vector<vector<Road>>& RD);
	void CheckRDBX(vector<JDdata>& JDARRAY, int isZX = 0);
	double cal_T_ang(vector<JDdata> JDARRAY, int i, double& ANG);
	//判断是否自相交
	int CheckZiJiao(vector <JDdata> JD);
	//计算道路中心线线元
	BOOL Cal_xianyuan(Road& m_RoadData1) const;
	//计算道路边线线元
	BOOL Cal_xianyuan(Road_BX& m_RoadData2) const;
	//根据道路交点数组，计算线元
	BOOL Cal_xianyuan(vector<JDdata> JDARRAY) const;
	//计算道路线元用
	int getBPMTL(double a, double R, double L1, double L2, double* BPMTL) const;
	//路网中心线，某处里程转化为NE坐标
	static bool TrsCmltoNE(double Cml, xlpoint& PZ, Road m_road);
	//路网边线，某处里程转化为NE坐标
	static bool TrsCmltoNE(double Cml, xlpoint& PZ, Road_BX m_road);
	static void InitJDdata(JDdata& tpJD);
	bool TrsNEtoCml(Road RD, double N, double E, double& Cml) const;
	bool TrsNEtoCml(Road_BX RD, double N, double E, double& Cml) const;
	bool TrsNEtoCml(Rd_BX RD, double N, double E, double& Cml) const;
	bool TrsCmltoI(Road RD, double CML, int& num)const;
	void Draw_xianyuan(Road& Draw_Road, CString RDStyle);
	void CheckJDData(vector<JDdata> JDdataIn, vector<vector<JDdata>>& JDdataOut, RoadChaiChuArray CCDin, vector<RoadChaiChuArray>& CCDout);
	void InterSectRDSelf(vector<JDdata> JDARRAY, double R, vector<QiuJiao_inf>& resJD) const;
	void RD_QiuJiao(vector<Road>& m_RoadData3) const;
	void FormCmlArrayCCD(vector<DLDrawFD>& GDFDArray, RoadChaiChuArray m_ChaiChuArray, double RoadL);
	void CheckQiuJiaoPushback(QiuJiao_inf TMP, vector<QiuJiao_inf>& resJD) const;
	Road_BX GENENewRoad_BX(Road RDData, double LeftOrRight);
	void MakeWXYByStartEndcml(Road Draw_Road,double(*XYArray)[10], int XYNum, double lc1, double lc2, int isChai);
	void MakeWXYByStartEndcml(Road_BX Draw_Road, double(*XYArray)[10], int XYNum, double lc1, double lc2, int isChai);
	int INTERJD(double& x, double& y, double X1, double Y1, double X2, double Y2, double X3, double Y3, double X4, double Y4) const;
	void GENE_RD_Net_BX(vector<Road>m_RoadData4, vector<Rd_BX>& JDdataOutFinally);
	int CheckZXBK(vector<JDdata> JDARRAY, int Iindex, int leftOrright) const;
	void CalAndDrawRoad();
	void DRAW_RD_Net_BX(vector<Rd_BX> JDdataOutFinally, vector<Road_BX>& Road_BXArray);
	void Draw_xianyuan_BX(Road_BX& Draw_Road, CString RDStyle);
	bool TrsCmltoGC(Road RD, double Cml, double& GC) const;
	bool TrsCmltoGC(Road_BX RD, double Cml, double& GC) const;
	bool CalGCFromRoadGC(Road RD, double X, double Y, double& GC) const;
	bool CalGCFromRoadGC(Road_BX RD, double X, double Y, double& GC) const;
	bool GetGCFromRoadGCForHHQX(double cml, double length1, double GCC, double GC1, double& GC) const;
	static bool GetPointIsInLine(DPoint3d pf, DPoint3d p1, DPoint3d p2, double range = 0.01);
	void GeneBXCCDpt(Road_BX RD_LuJian, vector<JDdata> DLJDdataTmp, RoadChaiChuArray& FDChaiChuArray);
	int CheckFourPtIsLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double KUANDU, DPoint3d& tmpptPTGX);
	void InterSectRD(vector<JDdata> JDARRAY1, vector<JDdata> JDARRAY2, double R1, double R2, vector<QiuJiao_inf>& qiujiao) const;
	vector<DPoint3d> JC_JD_qian_hou(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x,
		double y, double kuan1_left, double kuan1_right, double kuan2_left, double kuan2_right, double R1, double R2, int isqian = 1) const;
	vector<DPoint3d> JC_JD_qian_hou_zy(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4,
		double kuan1_left, double kuan1_right, double kuan2_left, double kuan2_right, double R1, double R2, int isqian = 1) const;
	vector<DPoint3d> JC_JD(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x, double y,
		double kuan1_left, double kuan1_right, double kuan2_left, double kuan2_right, double R1, double R2) const;
	vector<DPoint3d> JC_JD_zy(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4,
		double kuan1_left, double kuan1_right, double kuan2_left, double kuan2_right, double R1, double R2) const;
	vector<DPoint3d> DrawCross(DPoint3d centralPoint, double LuMianKuan,double LuMianHou,double fwj);
};
