Bug 1758688 [wpt PR 33067] - [FedCM] Make revoke a non-static method, a=testonly
[gecko.git] / gfx / 2d / ScaleFactor.h
blobe7eb783d0d628c75425e8d1dbb220c733664aacf
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 MOZILLA_GFX_SCALEFACTOR_H_
8 #define MOZILLA_GFX_SCALEFACTOR_H_
10 #include <ostream>
12 #include "mozilla/Attributes.h"
14 #include "gfxPoint.h"
16 namespace mozilla {
17 namespace gfx {
20 * This class represents a scaling factor between two different pixel unit
21 * systems. This is effectively a type-safe float, intended to be used in
22 * combination with the known-type instances of gfx::Point, gfx::Rect, etc.
24 * This class is meant to be used in cases where a single scale applies to
25 * both the x and y axes. For cases where two diferent scales apply, use
26 * ScaleFactors2D.
28 template <class src, class dst>
29 struct ScaleFactor {
30 float scale;
32 constexpr ScaleFactor() : scale(1.0) {}
33 constexpr ScaleFactor(const ScaleFactor<src, dst>& aCopy)
34 : scale(aCopy.scale) {}
35 explicit constexpr ScaleFactor(float aScale) : scale(aScale) {}
37 ScaleFactor<dst, src> Inverse() { return ScaleFactor<dst, src>(1 / scale); }
39 ScaleFactor<src, dst>& operator=(const ScaleFactor<src, dst>&) = default;
41 bool operator==(const ScaleFactor<src, dst>& aOther) const {
42 return scale == aOther.scale;
45 bool operator!=(const ScaleFactor<src, dst>& aOther) const {
46 return !(*this == aOther);
49 bool operator<(const ScaleFactor<src, dst>& aOther) const {
50 return scale < aOther.scale;
53 bool operator<=(const ScaleFactor<src, dst>& aOther) const {
54 return scale <= aOther.scale;
57 bool operator>(const ScaleFactor<src, dst>& aOther) const {
58 return scale > aOther.scale;
61 bool operator>=(const ScaleFactor<src, dst>& aOther) const {
62 return scale >= aOther.scale;
65 template <class other>
66 ScaleFactor<other, dst> operator/(
67 const ScaleFactor<src, other>& aOther) const {
68 return ScaleFactor<other, dst>(scale / aOther.scale);
71 template <class other>
72 ScaleFactor<src, other> operator/(
73 const ScaleFactor<other, dst>& aOther) const {
74 return ScaleFactor<src, other>(scale / aOther.scale);
77 template <class other>
78 ScaleFactor<src, other> operator*(
79 const ScaleFactor<dst, other>& aOther) const {
80 return ScaleFactor<src, other>(scale * aOther.scale);
83 template <class other>
84 ScaleFactor<other, dst> operator*(
85 const ScaleFactor<other, src>& aOther) const {
86 return ScaleFactor<other, dst>(scale * aOther.scale);
89 friend std::ostream& operator<<(std::ostream& aStream,
90 const ScaleFactor<src, dst>& aSF) {
91 return aStream << aSF.scale;
95 } // namespace gfx
96 } // namespace mozilla
98 #endif /* MOZILLA_GFX_SCALEFACTOR_H_ */