1
// Point2d template - for gnash
3
// Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 3 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
// Original author: Sandro Santilli <strk@keybit.net>
23
#ifndef GNASH_POINT2DH
24
#define GNASH_POINT2DH
27
#include <cmath> // for sqrt()
28
#include <boost/cstdint.hpp>
35
/// A point which contains a x and a y coorinate in TWIPS.
42
boost::int32_t x; // TWIPS
45
boost::int32_t y; // TWIPS
47
/// Construct a Point2d with default x and y coordinates
54
/// Construct a Point2d with given x and y ordinates
55
Point2d(boost::int32_t cx, boost::int32_t cy)
61
/// Construct a Point2d as an interpolation of the given input points
63
/// @param p0 first point
64
/// @param p1 second point
65
/// @param t interpolation factor, between 0 and 1
67
Point2d(const Point2d& p0, const Point2d& p1, float t)
69
x( p0.x + (boost::int32_t)((p1.x - p0.x) * t)),
70
y( p0.y + (boost::int32_t)((p1.y - p0.y) * t))
74
/// Set coordinates to given values
76
/// @return a reference to this instance
78
Point2d& setTo(const boost::int32_t cx, const boost::int32_t cy)
85
/// Set coordinates to the ones of the interpolation between the given input points
87
/// @param p0 first point
88
/// @param p1 second point
89
/// @param t interpolation factor, between 0 and 1
91
/// @return a reference to this instance
93
Point2d& setTo(const Point2d& p0, const Point2d& p1, float t)
95
x = p0.x + (boost::int32_t)((p1.x - p0.x) * t);
96
y = p0.y + (boost::int32_t)((p1.y - p0.y) * t);
100
/// Return square distance between two given points.
102
boost::int64_t squareDistance(const Point2d& p0, const Point2d& p1)
104
boost::int64_t hside = p1.x - p0.x;
105
boost::int64_t vside = p1.y - p0.y;
107
return hside*hside + vside*vside;
110
/// Return square distance between this and the given point
111
boost::int64_t squareDistance(const Point2d& p) const
113
return squareDistance(*this, p);
116
/// Return distance between this and the given point
117
boost::int32_t distance(const Point2d& p) const
119
return (boost::int32_t)( std::sqrt( static_cast<double>(squareDistance(p)) ) );
122
bool operator== (const Point2d& p) const
124
return (x == p.x) && (y == p.y);
127
bool operator!=(const Point2d& p) const
129
return ! (*this == p);
135
operator<< (std::ostream& os, const Point2d& p)
137
return os << "Point2d(" << p.x << "," << p.y << ")";
140
} // namespace gnash::geometry
142
typedef geometry::Point2d point;
146
#endif // GNASH_POINT2DH
150
// indent-tabs-mode: t