2005-04-06 05:54:26 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2005-04-06 05:54:26 +04:00
|
|
|
|
2005-04-11 08:36:18 +04:00
|
|
|
#ifndef GFX_POINT_H
|
|
|
|
#define GFX_POINT_H
|
2005-04-08 09:44:32 +04:00
|
|
|
|
2008-01-07 10:00:49 +03:00
|
|
|
#include "nsMathUtils.h"
|
2011-06-24 21:41:16 +04:00
|
|
|
#include "mozilla/gfx/BaseSize.h"
|
|
|
|
#include "mozilla/gfx/BasePoint.h"
|
2015-07-10 02:27:38 +03:00
|
|
|
#include "mozilla/gfx/Matrix.h"
|
2011-04-19 07:07:21 +04:00
|
|
|
#include "nsSize.h"
|
|
|
|
#include "nsPoint.h"
|
2005-06-28 13:18:55 +04:00
|
|
|
|
2005-04-08 09:44:32 +04:00
|
|
|
#include "gfxTypes.h"
|
2005-04-06 05:54:26 +04:00
|
|
|
|
2013-05-30 01:59:24 +04:00
|
|
|
struct gfxSize : public mozilla::gfx::BaseSize<gfxFloat, gfxSize> {
|
2011-06-24 21:41:16 +04:00
|
|
|
typedef mozilla::gfx::BaseSize<gfxFloat, gfxSize> Super;
|
2007-02-08 23:47:48 +03:00
|
|
|
|
2011-04-19 07:07:21 +04:00
|
|
|
gfxSize() : Super() {}
|
|
|
|
gfxSize(gfxFloat aWidth, gfxFloat aHeight) : Super(aWidth, aHeight) {}
|
2015-05-28 16:00:17 +03:00
|
|
|
MOZ_IMPLICIT gfxSize(const mozilla::gfx::IntSize& aSize) : Super(aSize.width, aSize.height) {}
|
2005-04-06 05:54:26 +04:00
|
|
|
};
|
|
|
|
|
2013-05-30 01:59:24 +04:00
|
|
|
struct gfxPoint : public mozilla::gfx::BasePoint<gfxFloat, gfxPoint> {
|
2011-06-24 21:41:16 +04:00
|
|
|
typedef mozilla::gfx::BasePoint<gfxFloat, gfxPoint> Super;
|
2007-02-08 23:47:48 +03:00
|
|
|
|
2011-04-19 07:07:21 +04:00
|
|
|
gfxPoint() : Super() {}
|
|
|
|
gfxPoint(gfxFloat aX, gfxFloat aY) : Super(aX, aY) {}
|
2014-07-29 16:07:24 +04:00
|
|
|
MOZ_IMPLICIT gfxPoint(const nsIntPoint& aPoint) : Super(aPoint.x, aPoint.y) {}
|
2007-02-08 23:47:48 +03:00
|
|
|
|
2012-08-17 03:38:59 +04:00
|
|
|
bool WithinEpsilonOf(const gfxPoint& aPoint, gfxFloat aEpsilon) {
|
|
|
|
return fabs(aPoint.x - x) < aEpsilon && fabs(aPoint.y - y) < aEpsilon;
|
|
|
|
}
|
2015-07-10 02:27:38 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2005-04-06 05:54:26 +04:00
|
|
|
};
|
|
|
|
|
2012-12-23 19:50:30 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2005-04-11 08:36:18 +04:00
|
|
|
#endif /* GFX_POINT_H */
|