codes#2

struct Point
{
	double x,y;
	friend inline const Point operator * (const Point &p1,const double &k)
	{
		return (Point){p1.x*k,p1.y*k};
	}
	friend inline const Point operator + (const Point &p1,const Point &p2)
	{
		return (Point){p1.x+p2.x,p1.y+p2.y};
	}
	friend inline const Point operator - (const Point &p1,const Point &p2)
	{
		return (Point){p2.x-p1.x,p2.y-p1.y};
	}
	friend inline const Point operator / (const Point &p1,const double &k)
	{
		return(Point){p1.x/k,p1.y/k};
	}
};
struct Vector
{
	double x,y;
	Vector(const Point &a=(Point){0,0},const Point &b=(Point){0,0})
	{
		x=b.x-a.x,y=b.y-a.y;
		return;
	}
	Vector(const double &x,const double &y)
	{
		this->x=x,this->y=y;
		return;
	}
	inline const double Module()
	{
		return sqrt(x*x+y*y);
	}
};
struct Segment
{
	Point a,b;
	Segment(const Point &a=(Point){0,0},const Point &b=(Point){0,0})
	{
		this->a=a,this->b=b;
		return;
	}
};
struct Line
{
	Point a,b;
	Line(const Point &a=(Point){0,0},const Point &b=(Point){0,0})
	{
		this->a=a,this->b=b;
		return;
	}
};
struct Ray
{
	Point p;
	Vector vec;
};
posted @ 2019-11-06 09:23  ZYyboT  阅读(118)  评论(0)    收藏  举报