Browse Source

point定义实现分离

divide_struct_def_imp
郑敬润 1 year ago
parent
commit
e6caf49e27
  1. 9
      include/Path.h
  2. 111
      include/Point.h
  3. 97
      src/Point.cpp

9
include/Path.h

@ -9,7 +9,14 @@
#include <sstream>
#include <algorithm>
using namespace std;
P dirP(P &A)
{
P B;
B.x = A.dx;
B.y = A.dy;
B.z = A.dz;
return B;
}
// 简单的路径信息,路径规划的直接结果
struct Path
{

111
include/Point.h

@ -13,106 +13,23 @@ struct P
int type; // 0卡箍 1未确定分支点 2已确定分支点 3连接器
int ref; // 指向其代表的相应数据类型标号
bool operator<(P B) const
{
if (!Equal(x, B.x))
return x < B.x;
if (!Equal(y, B.y))
return y < B.y;
if (!Equal(z, B.z))
return z < B.z;
return false;
}
bool operator==(P B) const
{
return Equal(x, B.x) && Equal(y, B.y) && Equal(z, B.z);
}
bool operator!=(P B) const
{
return !(Equal(x, B.x) && Equal(y, B.y) && Equal(z, B.z));
}
void set(int i, double v)
{
if (i == 0)
x = v;
else if (i == 1)
y = v;
else if (i == 2)
z = v;
}
const double get(int i)
{
if (i == 0)
return x;
else if (i == 1)
return y;
else if (i == 2)
return z;
bool operator<(P B) const;
bool operator==(P B) const;
bool operator!=(P B) const;
return 0;
}
void set(int i, double v);
const double get(int i);
void reverse()
{
dx = -dx;
dy = -dy;
dz = -dz;
}
void reverse();
P(double x1, double y1, double z1)
{
x = x1;
y = y1;
z = z1;
dx = 0;
dy = dz = 0;
isend = 0;
type = ref = 0;
}
P()
{
x = y = z = 0;
dx = 0;
dy = dz = 0;
isend = 0;
type = ref = 0;
}
P operator-(P B) const
{
return P(x - B.x, y - B.y, z - B.z);
}
P operator+(P B) const
{
return P(x + B.x, y + B.y, z + B.z);
}
P operator*(double p) const
{
return P(x * p, y * p, z * p);
}
P operator/(double p) const
{
return P(x / p, y / p, z / p);
}
void print(string s)
{
cout << s << setprecision(10) << " : " << x << " " << y << " " << z << endl;
return;
}
P(double x1, double y1, double z1);
P();
P operator-(P B) const;
P operator+(P B) const;
P operator*(double p) const;
P operator/(double p) const;
void print(string s);
// 设置方向
void setDir(const P &dir)
{
dx = dir.x;
dy = dir.y;
dz = dir.z;
}
void setDir(const P &dir);
};
P dirP(P &A)
{
P B;
B.x = A.dx;
B.y = A.dy;
B.z = A.dz;
return B;
}

97
src/Point.cpp

@ -0,0 +1,97 @@
#include "Point.h"
bool P::operator<(P B) const
{
if (!Equal(x, B.x))
return x < B.x;
if (!Equal(y, B.y))
return y < B.y;
if (!Equal(z, B.z))
return z < B.z;
return false;
}
bool P::operator==(P B) const
{
return Equal(x, B.x) && Equal(y, B.y) && Equal(z, B.z);
}
bool P::operator!=(P B) const
{
return !(Equal(x, B.x) && Equal(y, B.y) && Equal(z, B.z));
}
void P::set(int i, double v)
{
if (i == 0)
x = v;
else if (i == 1)
y = v;
else if (i == 2)
z = v;
}
const double P::get(int i)
{
if (i == 0)
return x;
else if (i == 1)
return y;
else if (i == 2)
return z;
return 0;
}
void P::reverse()
{
dx = -dx;
dy = -dy;
dz = -dz;
}
P::P(double x1, double y1, double z1)
{
x = x1;
y = y1;
z = z1;
dx = 0;
dy = dz = 0;
isend = 0;
type = ref = 0;
}
P::P()
{
x = y = z = 0;
dx = 0;
dy = dz = 0;
isend = 0;
type = ref = 0;
}
P P::operator-(P B) const
{
return P(x - B.x, y - B.y, z - B.z);
}
P P::operator+(P B) const
{
return P(x + B.x, y + B.y, z + B.z);
}
P P::operator*(double p) const
{
return P(x * p, y * p, z * p);
}
P P::operator/(double p) const
{
return P(x / p, y / p, z / p);
}
void P::print(string s)
{
cout << s << setprecision(10) << " : " << x << " " << y << " " << z << endl;
return;
}
// ÉèÖ÷½Ïò
void P::setDir(const P &dir)
{
dx = dir.x;
dy = dir.y;
dz = dir.z;
}
Loading…
Cancel
Save