Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef MOZILLA_BASEPOINT3D_H_ |
michael@0 | 7 | #define MOZILLA_BASEPOINT3D_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/Assertions.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace mozilla { |
michael@0 | 12 | namespace gfx { |
michael@0 | 13 | |
michael@0 | 14 | /** |
michael@0 | 15 | * Do not use this class directly. Subclass it, pass that subclass as the |
michael@0 | 16 | * Sub parameter, and only use that subclass. This allows methods to safely |
michael@0 | 17 | * cast 'this' to 'Sub*'. |
michael@0 | 18 | */ |
michael@0 | 19 | template <class T, class Sub> |
michael@0 | 20 | struct BasePoint3D { |
michael@0 | 21 | T x, y, z; |
michael@0 | 22 | |
michael@0 | 23 | // Constructors |
michael@0 | 24 | BasePoint3D() : x(0), y(0), z(0) {} |
michael@0 | 25 | BasePoint3D(T aX, T aY, T aZ) : x(aX), y(aY), z(aZ) {} |
michael@0 | 26 | |
michael@0 | 27 | void MoveTo(T aX, T aY, T aZ) { x = aX; y = aY; z = aZ; } |
michael@0 | 28 | void MoveBy(T aDx, T aDy, T aDz) { x += aDx; y += aDy; z += aDz; } |
michael@0 | 29 | |
michael@0 | 30 | // Note that '=' isn't defined so we'll get the |
michael@0 | 31 | // compiler generated default assignment operator |
michael@0 | 32 | |
michael@0 | 33 | T& operator[](int aIndex) { |
michael@0 | 34 | MOZ_ASSERT(aIndex >= 0 && aIndex <= 2); |
michael@0 | 35 | return *((&x)+aIndex); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | const T& operator[](int aIndex) const { |
michael@0 | 39 | MOZ_ASSERT(aIndex >= 0 && aIndex <= 2); |
michael@0 | 40 | return *((&x)+aIndex); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | bool operator==(const Sub& aPoint) const { |
michael@0 | 44 | return x == aPoint.x && y == aPoint.y && z == aPoint.z; |
michael@0 | 45 | } |
michael@0 | 46 | bool operator!=(const Sub& aPoint) const { |
michael@0 | 47 | return x != aPoint.x || y != aPoint.y || z != aPoint.z; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | Sub operator+(const Sub& aPoint) const { |
michael@0 | 51 | return Sub(x + aPoint.x, y + aPoint.y, z + aPoint.z); |
michael@0 | 52 | } |
michael@0 | 53 | Sub operator-(const Sub& aPoint) const { |
michael@0 | 54 | return Sub(x - aPoint.x, y - aPoint.y, z - aPoint.z); |
michael@0 | 55 | } |
michael@0 | 56 | Sub& operator+=(const Sub& aPoint) { |
michael@0 | 57 | x += aPoint.x; |
michael@0 | 58 | y += aPoint.y; |
michael@0 | 59 | z += aPoint.z; |
michael@0 | 60 | return *static_cast<Sub*>(this); |
michael@0 | 61 | } |
michael@0 | 62 | Sub& operator-=(const Sub& aPoint) { |
michael@0 | 63 | x -= aPoint.x; |
michael@0 | 64 | y -= aPoint.y; |
michael@0 | 65 | z -= aPoint.z; |
michael@0 | 66 | return *static_cast<Sub*>(this); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | Sub operator*(T aScale) const { |
michael@0 | 70 | return Sub(x * aScale, y * aScale, z * aScale); |
michael@0 | 71 | } |
michael@0 | 72 | Sub operator/(T aScale) const { |
michael@0 | 73 | return Sub(x / aScale, y / aScale, z / aScale); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | Sub& operator*=(T aScale) { |
michael@0 | 77 | x *= aScale; |
michael@0 | 78 | y *= aScale; |
michael@0 | 79 | z *= aScale; |
michael@0 | 80 | return *static_cast<Sub*>(this); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | Sub& operator/=(T aScale) { |
michael@0 | 84 | x /= aScale; |
michael@0 | 85 | y /= aScale; |
michael@0 | 86 | z /= aScale; |
michael@0 | 87 | return *static_cast<Sub*>(this); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | Sub operator-() const { |
michael@0 | 91 | return Sub(-x, -y, -z); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | Sub CrossProduct(const Sub& aPoint) const { |
michael@0 | 95 | return Sub(y * aPoint.z - aPoint.y * z, |
michael@0 | 96 | z * aPoint.x - aPoint.z * x, |
michael@0 | 97 | x * aPoint.y - aPoint.x * y); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | T DotProduct(const Sub& aPoint) const { |
michael@0 | 101 | return x * aPoint.x + y * aPoint.y + z * aPoint.z; |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | T Length() const { |
michael@0 | 105 | return sqrt(x*x + y*y + z*z); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | // Invalid for points with distance from origin of 0. |
michael@0 | 109 | void Normalize() { |
michael@0 | 110 | *this /= Length(); |
michael@0 | 111 | } |
michael@0 | 112 | }; |
michael@0 | 113 | |
michael@0 | 114 | } |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | #endif /* MOZILLA_BASEPOINT3D_H_ */ |