gecko-dev/gfx/thebes/gfxPoint.h

60 строки
1.7 KiB
C
Исходник Обычный вид История

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
#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 "mozilla/gfx/Point.h"
#include "nsSize.h"
#include "nsPoint.h"
#include "gfxTypes.h"
2005-04-06 05:54:26 +04:00
typedef mozilla::gfx::SizeDouble gfxSize;
2005-04-06 05:54:26 +04:00
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;
}
2005-04-06 05:54:26 +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);
}
#endif /* GFX_POINT_H */