Bug 849918 - Initial support for PannerNode's 3D positional audio (equalpower panning...
[gecko.git] / gfx / 2d / BasePoint.h
bloba7da0cc0360980effbe5c50b18bd73383d92c09a
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef MOZILLA_GFX_BASEPOINT_H_
7 #define MOZILLA_GFX_BASEPOINT_H_
9 namespace mozilla {
10 namespace gfx {
12 /**
13 * Do not use this class directly. Subclass it, pass that subclass as the
14 * Sub parameter, and only use that subclass. This allows methods to safely
15 * cast 'this' to 'Sub*'.
17 template <class T, class Sub>
18 struct BasePoint {
19 T x, y;
21 // Constructors
22 BasePoint() : x(0), y(0) {}
23 BasePoint(T aX, T aY) : x(aX), y(aY) {}
25 void MoveTo(T aX, T aY) { x = aX; y = aY; }
26 void MoveBy(T aDx, T aDy) { x += aDx; y += aDy; }
28 // Note that '=' isn't defined so we'll get the
29 // compiler generated default assignment operator
31 bool operator==(const Sub& aPoint) const {
32 return x == aPoint.x && y == aPoint.y;
34 bool operator!=(const Sub& aPoint) const {
35 return x != aPoint.x || y != aPoint.y;
38 Sub operator+(const Sub& aPoint) const {
39 return Sub(x + aPoint.x, y + aPoint.y);
41 Sub operator-(const Sub& aPoint) const {
42 return Sub(x - aPoint.x, y - aPoint.y);
44 Sub& operator+=(const Sub& aPoint) {
45 x += aPoint.x;
46 y += aPoint.y;
47 return *static_cast<Sub*>(this);
49 Sub& operator-=(const Sub& aPoint) {
50 x -= aPoint.x;
51 y -= aPoint.y;
52 return *static_cast<Sub*>(this);
55 Sub operator*(T aScale) const {
56 return Sub(x * aScale, y * aScale);
58 Sub operator/(T aScale) const {
59 return Sub(x / aScale, y / aScale);
62 Sub operator-() const {
63 return Sub(-x, -y);
70 #endif /* MOZILLA_GFX_BASEPOINT_H_ */