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_
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
>
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
) {
47 return *static_cast<Sub
*>(this);
49 Sub
& operator-=(const Sub
& aPoint
) {
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 {
70 #endif /* MOZILLA_GFX_BASEPOINT_H_ */