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.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef ThreeDPoint_h_
8 #define ThreeDPoint_h_
10 #include <cmath>
11 #include <algorithm>
13 namespace mozilla {
15 namespace dom {
17 struct ThreeDPoint {
18 ThreeDPoint()
19 : x(0.)
20 , y(0.)
21 , z(0.)
22 {
23 }
24 ThreeDPoint(double aX, double aY, double aZ)
25 : x(aX)
26 , y(aY)
27 , z(aZ)
28 {
29 }
31 double Magnitude() const
32 {
33 return sqrt(x * x + y * y + z * z);
34 }
36 void Normalize()
37 {
38 // Normalize with the maximum norm first to avoid overflow and underflow.
39 double invMax = 1 / MaxNorm();
40 x *= invMax;
41 y *= invMax;
42 z *= invMax;
44 double invDistance = 1 / Magnitude();
45 x *= invDistance;
46 y *= invDistance;
47 z *= invDistance;
48 }
50 ThreeDPoint CrossProduct(const ThreeDPoint& rhs) const
51 {
52 return ThreeDPoint(y * rhs.z - z * rhs.y,
53 z * rhs.x - x * rhs.z,
54 x * rhs.y - y * rhs.x);
55 }
57 double DotProduct(const ThreeDPoint& rhs)
58 {
59 return x * rhs.x + y * rhs.y + z * rhs.z;
60 }
62 bool IsZero() const
63 {
64 return x == 0 && y == 0 && z == 0;
65 }
67 // For comparing two vectors of close to unit magnitude.
68 bool FuzzyEqual(const ThreeDPoint& other);
70 double x, y, z;
72 private:
73 double MaxNorm() const
74 {
75 return std::max(fabs(x), std::max(fabs(y), fabs(z)));
76 }
77 };
79 ThreeDPoint operator-(const ThreeDPoint& lhs, const ThreeDPoint& rhs);
80 ThreeDPoint operator*(const ThreeDPoint& lhs, const ThreeDPoint& rhs);
81 ThreeDPoint operator*(const ThreeDPoint& lhs, const double rhs);
82 bool operator==(const ThreeDPoint& lhs, const ThreeDPoint& rhs);
84 }
85 }
87 #endif