diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /gfx/thebes/gfxPoint.h | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'gfx/thebes/gfxPoint.h')
-rw-r--r-- | gfx/thebes/gfxPoint.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/gfx/thebes/gfxPoint.h b/gfx/thebes/gfxPoint.h new file mode 100644 index 000000000..5883244e3 --- /dev/null +++ b/gfx/thebes/gfxPoint.h @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef GFX_POINT_H +#define GFX_POINT_H + +#include "nsMathUtils.h" +#include "mozilla/gfx/BaseSize.h" +#include "mozilla/gfx/BasePoint.h" +#include "mozilla/gfx/Matrix.h" +#include "nsSize.h" +#include "nsPoint.h" + +#include "gfxTypes.h" + +struct gfxSize : public mozilla::gfx::BaseSize<gfxFloat, gfxSize> { + typedef mozilla::gfx::BaseSize<gfxFloat, gfxSize> Super; + + gfxSize() : Super() {} + gfxSize(gfxFloat aWidth, gfxFloat aHeight) : Super(aWidth, aHeight) {} + MOZ_IMPLICIT gfxSize(const mozilla::gfx::IntSize& aSize) : Super(aSize.width, aSize.height) {} +}; + +struct gfxPoint : public mozilla::gfx::BasePoint<gfxFloat, gfxPoint> { + typedef mozilla::gfx::BasePoint<gfxFloat, gfxPoint> Super; + + gfxPoint() : Super() {} + gfxPoint(gfxFloat aX, gfxFloat aY) : Super(aX, aY) {} + MOZ_IMPLICIT gfxPoint(const nsIntPoint& aPoint) : Super(aPoint.x, aPoint.y) {} + + bool WithinEpsilonOf(const gfxPoint& aPoint, gfxFloat aEpsilon) { + return fabs(aPoint.x - x) < aEpsilon && fabs(aPoint.y - y) < aEpsilon; + } + + void Transform(const mozilla::gfx::Matrix4x4 &aMatrix) + { + // Transform this point with aMatrix + double px = x; + double py = y; + + x = px * aMatrix._11 + py * aMatrix._21 + aMatrix._41; + y = px * aMatrix._12 + py * aMatrix._22 + aMatrix._42; + + double w = px * aMatrix._14 + py * aMatrix._24 + aMatrix._44; + x /= w; + y /= w; + } +}; + +inline gfxPoint +operator*(const gfxPoint& aPoint, const gfxSize& aSize) +{ + return gfxPoint(aPoint.x * aSize.width, aPoint.y * aSize.height); +} + +inline gfxPoint +operator/(const gfxPoint& aPoint, const gfxSize& aSize) +{ + return gfxPoint(aPoint.x / aSize.width, aPoint.y / aSize.height); +} + +inline gfxSize +operator/(gfxFloat aValue, const gfxSize& aSize) +{ + return gfxSize(aValue / aSize.width, aValue / aSize.height); +} + +#endif /* GFX_POINT_H */ |