point.cpp

来自「通用网络游戏开发框架」· C++ 代码 · 共 52 行

CPP
52
字号
// ============================================================================
// Point implementation
//
// (c) 2003 Ken Reed
//
// This is free software. You can redistribute it and/or modify it under the
// terms of the GNU General Public License version 2 as published by the Free
// Software Foundation.
// ============================================================================

#include "stdafx.h"
#include "point.h"

#include <math.h>

// ============================================================================
// Construction
// ============================================================================

Point::Point()               : x(0),  y(0)  {}
Point::Point(int xp, int yp) : x(xp), y(yp) {}


// ============================================================================
// Distance to another point
// ============================================================================

int Point::distance_to(Point target)
{
   int xo ( (abs) (x - target.x) );
   int yo ( (abs) (y - target.y) );

   double distance ( sqrt(double ((xo * xo) + (yo * yo))) );

   return (int) distance;
}


// ============================================================================
// Convert to POINT (so we can pass our Points to MS POINTS)
// ============================================================================

Point::operator POINT() const
{
   POINT p;

   p.x = x;
   p.y = y;

   return p;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?