~ubuntu-branches/ubuntu/karmic/gnash/karmic

« back to all changes in this revision

Viewing changes to libbase/Point2d.h

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2008-10-13 14:29:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081013142949-f6qdvnu4mn05ltdc
Tags: 0.8.4~~bzr9980-0ubuntu1
* new upstream release 0.8.4 (LP: #240325)
* ship new lib usr/lib/gnash/libmozsdk.so.* in mozilla-plugin-gnash
  - update debian/mozilla-plugin-gnash.install
* ship new lib usr/lib/gnash/libgnashnet.so.* in gnash-common
  - update debian/gnash-common.install
* add basic debian/build_head script to build latest CVS head packages.
  - add debian/build_head
* new sound architecture requires build depend on libsdl1.2-dev
  - update debian/control
* head build script now has been completely migrated to bzr (upstream +
  ubuntu)
  - update debian/build_head
* disable kde gui until klash/qt4 has been fixed; keep kde packages as empty
  packages for now.
  - update debian/rules
  - debian/klash.install
  - debian/klash.links
  - debian/klash.manpages
  - debian/konqueror-plugin-gnash.install
* drop libkonq5-dev build dependency accordingly
  - update debian/control
* don't install headers manually anymore. gnash doesnt provide a -dev
  package after all
  - update debian/rules
* update libs installed in gnash-common; libgnashserver-*.so is not available
  anymore (removed); in turn we add the new libgnashcore-*.so
  - update debian/gnash-common.install
* use -Os for optimization and properly pass CXXFLAGS=$(CFLAGS) to configure
  - update debian/rules
* touch firefox .autoreg in postinst of mozilla plugin
  - update debian/mozilla-plugin-gnash.postinst
* link gnash in ubufox plugins directory for the plugin alternative switcher
  - add debian/mozilla-plugin-gnash.links
* suggest ubufox accordingly
  - update debian/control
* add new required build-depends on libgif-dev
  - update debian/control
* add Xb-Npp-Description and Xb-Npp-File as new plugin database meta data
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Point2d template - for gnash
 
2
// 
 
3
//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
4
// 
 
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.
 
9
// 
 
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.
 
14
// 
 
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
 
18
 
 
19
//
 
20
// Original author: Sandro Santilli <strk@keybit.net>
 
21
//
 
22
 
 
23
#ifndef GNASH_POINT2DH
 
24
#define GNASH_POINT2DH
 
25
 
 
26
#include <ostream>
 
27
#include <cmath>    // for sqrt()
 
28
#include <boost/cstdint.hpp>
 
29
 
 
30
namespace gnash {
 
31
namespace geometry { 
 
32
    
 
33
/// 2D Point class
 
34
//
 
35
/// A point which contains a x and a y coorinate in TWIPS.
 
36
/// 
 
37
class Point2d
 
38
{
 
39
public:
 
40
 
 
41
        /// The x coordinate
 
42
        boost::int32_t  x;  // TWIPS
 
43
 
 
44
        /// The y coordinate
 
45
        boost::int32_t  y;  // TWIPS
 
46
 
 
47
        /// Construct a Point2d with default x and y coordinates
 
48
        Point2d()
 
49
                :
 
50
                x(0), y(0)
 
51
        {
 
52
        }
 
53
 
 
54
        /// Construct a Point2d with given x and y ordinates
 
55
        Point2d(boost::int32_t cx, boost::int32_t cy)
 
56
                :
 
57
                x(cx), y(cy)
 
58
        {
 
59
        }
 
60
 
 
61
        /// Construct a Point2d as an interpolation of the given input points
 
62
        //
 
63
        /// @param p0 first point
 
64
        /// @param p1 second point
 
65
        /// @param t interpolation factor, between 0 and 1
 
66
        ///
 
67
        Point2d(const Point2d& p0, const Point2d& p1, float t)
 
68
                :
 
69
                x( p0.x + (boost::int32_t)((p1.x - p0.x) * t)),
 
70
                y( p0.y + (boost::int32_t)((p1.y - p0.y) * t))
 
71
        {
 
72
        }
 
73
 
 
74
        /// Set coordinates to given values
 
75
        //
 
76
        /// @return a reference to this instance
 
77
        ///
 
78
        Point2d& setTo(const boost::int32_t cx, const boost::int32_t cy)
 
79
        {
 
80
                x = cx;  
 
81
        y = cy;
 
82
                return *this;
 
83
        }
 
84
 
 
85
        /// Set coordinates to the ones of the interpolation between the given input points
 
86
        //
 
87
        /// @param p0 first point
 
88
        /// @param p1 second point
 
89
        /// @param t interpolation factor, between 0 and 1
 
90
        ///
 
91
        /// @return a reference to this instance
 
92
        ///
 
93
        Point2d& setTo(const Point2d& p0, const Point2d& p1, float t)
 
94
        {
 
95
                x = p0.x + (boost::int32_t)((p1.x - p0.x) * t);
 
96
                y = p0.y + (boost::int32_t)((p1.y - p0.y) * t);
 
97
                return *this;
 
98
        }
 
99
 
 
100
        /// Return square distance between two given points.
 
101
        static
 
102
        boost::int64_t squareDistance(const Point2d& p0, const Point2d& p1)
 
103
        {
 
104
                boost::int64_t hside = p1.x - p0.x;
 
105
                boost::int64_t vside = p1.y - p0.y;
 
106
 
 
107
                return hside*hside + vside*vside;
 
108
        }
 
109
 
 
110
        /// Return square distance between this and the given point
 
111
        boost::int64_t squareDistance(const Point2d& p) const
 
112
        {
 
113
                return squareDistance(*this, p);
 
114
        }
 
115
 
 
116
        /// Return distance between this and the given point
 
117
        boost::int32_t distance(const Point2d& p) const
 
118
        {
 
119
            return (boost::int32_t)( std::sqrt( static_cast<double>(squareDistance(p)) ) );
 
120
        }
 
121
 
 
122
        bool operator== (const Point2d& p) const
 
123
        {
 
124
                return (x == p.x) && (y == p.y);
 
125
        }
 
126
 
 
127
        bool operator!=(const Point2d& p) const
 
128
        {
 
129
                return ! (*this == p);
 
130
        }
 
131
};
 
132
 
 
133
/// Output operator
 
134
inline std::ostream&
 
135
operator<< (std::ostream& os, const Point2d& p)
 
136
{
 
137
        return os << "Point2d(" << p.x << "," << p.y << ")";
 
138
}
 
139
 
 
140
} // namespace gnash::geometry
 
141
 
 
142
typedef geometry::Point2d  point;
 
143
 
 
144
} // namespace gnash
 
145
 
 
146
#endif // GNASH_POINT2DH
 
147
 
 
148
// Local Variables:
 
149
// mode: C++
 
150
// indent-tabs-mode: t
 
151
// End: