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"
|
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
|
|
|
|
2011-04-19 07:07:21 +04:00
|
|
|
typedef nsIntSize gfxIntSize;
|
2007-02-08 23:47:48 +03:00
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
struct THEBES_API gfxSize : public mozilla::gfx::BaseSize<gfxFloat, gfxSize> {
|
|
|
|
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) {}
|
|
|
|
gfxSize(const nsIntSize& aSize) : Super(aSize.width, aSize.height) {}
|
2005-04-06 05:54:26 +04:00
|
|
|
};
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
struct THEBES_API gfxPoint : public mozilla::gfx::BasePoint<gfxFloat, gfxPoint> {
|
|
|
|
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) {}
|
|
|
|
gfxPoint(const nsIntPoint& aPoint) : Super(aPoint.x, aPoint.y) {}
|
2007-02-08 23:47:48 +03:00
|
|
|
|
2008-01-12 20:30:27 +03:00
|
|
|
// Round() is *not* rounding to nearest integer if the values are negative.
|
|
|
|
// They are always rounding as floor(n + 0.5).
|
|
|
|
// See https://bugzilla.mozilla.org/show_bug.cgi?id=410748#c14
|
2006-07-18 03:45:21 +04:00
|
|
|
gfxPoint& Round() {
|
2011-05-30 23:08:55 +04:00
|
|
|
x = floor(x + 0.5);
|
|
|
|
y = floor(y + 0.5);
|
2005-06-28 13:18:55 +04:00
|
|
|
return *this;
|
|
|
|
}
|
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;
|
|
|
|
}
|
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 */
|