2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef GFX_POINT_H
|
|
|
|
#define GFX_POINT_H
|
|
|
|
|
2008-01-06 23:00:49 -08:00
|
|
|
#include "nsMathUtils.h"
|
2011-06-24 10:41:16 -07:00
|
|
|
#include "mozilla/gfx/BaseSize.h"
|
|
|
|
#include "mozilla/gfx/BasePoint.h"
|
2011-04-18 20:07:21 -07:00
|
|
|
#include "nsSize.h"
|
|
|
|
#include "nsPoint.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "gfxTypes.h"
|
|
|
|
|
2013-05-29 14:59:24 -07:00
|
|
|
struct gfxSize : public mozilla::gfx::BaseSize<gfxFloat, gfxSize> {
|
2011-06-24 10:41:16 -07:00
|
|
|
typedef mozilla::gfx::BaseSize<gfxFloat, gfxSize> Super;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-18 20:07:21 -07:00
|
|
|
gfxSize() : Super() {}
|
|
|
|
gfxSize(gfxFloat aWidth, gfxFloat aHeight) : Super(aWidth, aHeight) {}
|
|
|
|
gfxSize(const nsIntSize& aSize) : Super(aSize.width, aSize.height) {}
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2013-05-29 14:59:24 -07:00
|
|
|
struct gfxPoint : public mozilla::gfx::BasePoint<gfxFloat, gfxPoint> {
|
2011-06-24 10:41:16 -07:00
|
|
|
typedef mozilla::gfx::BasePoint<gfxFloat, gfxPoint> Super;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-18 20:07:21 -07:00
|
|
|
gfxPoint() : Super() {}
|
|
|
|
gfxPoint(gfxFloat aX, gfxFloat aY) : Super(aX, aY) {}
|
|
|
|
gfxPoint(const nsIntPoint& aPoint) : Super(aPoint.x, aPoint.y) {}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-12 09:30:27 -08: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
|
2007-03-22 10:30:00 -07:00
|
|
|
gfxPoint& Round() {
|
2011-05-30 12:08:55 -07:00
|
|
|
x = floor(x + 0.5);
|
|
|
|
y = floor(y + 0.5);
|
2007-03-22 10:30:00 -07:00
|
|
|
return *this;
|
|
|
|
}
|
2012-08-16 16:38:59 -07:00
|
|
|
|
|
|
|
bool WithinEpsilonOf(const gfxPoint& aPoint, gfxFloat aEpsilon) {
|
|
|
|
return fabs(aPoint.x - x) < aEpsilon && fabs(aPoint.y - y) < aEpsilon;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2012-12-23 07:50:30 -08: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);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* GFX_POINT_H */
|