2011-06-24 17:41:16 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 11:12:37 +00: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/. */
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
#ifndef MOZILLA_GFX_POINT_H_
|
|
|
|
#define MOZILLA_GFX_POINT_H_
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2013-11-22 19:45:50 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2011-06-24 17:41:16 +00:00
|
|
|
#include "Types.h"
|
|
|
|
#include "BasePoint.h"
|
2013-11-27 11:22:02 +00:00
|
|
|
#include "BasePoint3D.h"
|
2011-06-24 17:41:16 +00:00
|
|
|
#include "BaseSize.h"
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2013-08-08 19:56:09 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2013-05-29 13:32:30 +00:00
|
|
|
// This should only be used by the typedefs below.
|
|
|
|
struct UnknownUnits {};
|
2011-11-14 04:29:01 +00:00
|
|
|
|
2013-05-29 13:32:30 +00:00
|
|
|
template<class units>
|
|
|
|
struct IntPointTyped :
|
|
|
|
public BasePoint< int32_t, IntPointTyped<units> >,
|
|
|
|
public units {
|
|
|
|
typedef BasePoint< int32_t, IntPointTyped<units> > Super;
|
|
|
|
|
2014-02-06 18:06:08 +00:00
|
|
|
MOZ_CONSTEXPR IntPointTyped() : Super() {}
|
2013-11-22 19:45:50 +00:00
|
|
|
MOZ_CONSTEXPR IntPointTyped(int32_t aX, int32_t aY) : Super(aX, aY) {}
|
2013-06-11 22:13:11 +00:00
|
|
|
|
|
|
|
// XXX When all of the code is ported, the following functions to convert to and from
|
|
|
|
// unknown types should be removed.
|
|
|
|
|
|
|
|
static IntPointTyped<units> FromUnknownPoint(const IntPointTyped<UnknownUnits>& aPoint) {
|
|
|
|
return IntPointTyped<units>(aPoint.x, aPoint.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
IntPointTyped<UnknownUnits> ToUnknownPoint() const {
|
|
|
|
return IntPointTyped<UnknownUnits>(this->x, this->y);
|
|
|
|
}
|
2011-11-14 04:29:01 +00:00
|
|
|
};
|
2013-05-29 13:32:30 +00:00
|
|
|
typedef IntPointTyped<UnknownUnits> IntPoint;
|
2011-11-14 04:29:01 +00:00
|
|
|
|
2013-05-29 13:32:30 +00:00
|
|
|
template<class units>
|
|
|
|
struct PointTyped :
|
|
|
|
public BasePoint< Float, PointTyped<units> >,
|
|
|
|
public units {
|
|
|
|
typedef BasePoint< Float, PointTyped<units> > Super;
|
2011-11-14 04:29:01 +00:00
|
|
|
|
2014-02-06 18:06:08 +00:00
|
|
|
MOZ_CONSTEXPR PointTyped() : Super() {}
|
|
|
|
MOZ_CONSTEXPR PointTyped(Float aX, Float aY) : Super(aX, aY) {}
|
|
|
|
MOZ_CONSTEXPR PointTyped(const IntPointTyped<units>& point) : Super(float(point.x), float(point.y)) {}
|
2013-05-31 01:30:13 +00:00
|
|
|
|
|
|
|
// XXX When all of the code is ported, the following functions to convert to and from
|
|
|
|
// unknown types should be removed.
|
|
|
|
|
2013-06-11 22:13:11 +00:00
|
|
|
static PointTyped<units> FromUnknownPoint(const PointTyped<UnknownUnits>& aPoint) {
|
|
|
|
return PointTyped<units>(aPoint.x, aPoint.y);
|
2013-05-31 01:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PointTyped<UnknownUnits> ToUnknownPoint() const {
|
|
|
|
return PointTyped<UnknownUnits>(this->x, this->y);
|
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
};
|
2013-05-29 13:32:30 +00:00
|
|
|
typedef PointTyped<UnknownUnits> Point;
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2013-06-14 20:11:31 +00:00
|
|
|
template<class units>
|
|
|
|
IntPointTyped<units> RoundedToInt(const PointTyped<units>& aPoint) {
|
2013-08-08 19:56:09 +00:00
|
|
|
return IntPointTyped<units>(int32_t(floorf(aPoint.x + 0.5f)),
|
|
|
|
int32_t(floorf(aPoint.y + 0.5f)));
|
2013-06-14 20:11:31 +00:00
|
|
|
}
|
|
|
|
|
2013-11-27 11:22:02 +00:00
|
|
|
template<class units>
|
|
|
|
struct Point3DTyped :
|
|
|
|
public BasePoint3D< Float, Point3DTyped<units> > {
|
|
|
|
typedef BasePoint3D< Float, Point3DTyped<units> > Super;
|
|
|
|
|
|
|
|
Point3DTyped() : Super() {}
|
|
|
|
Point3DTyped(Float aX, Float aY, Float aZ) : Super(aX, aY, aZ) {}
|
|
|
|
|
|
|
|
// XXX When all of the code is ported, the following functions to convert to and from
|
|
|
|
// unknown types should be removed.
|
|
|
|
|
|
|
|
static Point3DTyped<units> FromUnknownPoint(const Point3DTyped<UnknownUnits>& aPoint) {
|
|
|
|
return Point3DTyped<units>(aPoint.x, aPoint.y, aPoint.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
Point3DTyped<UnknownUnits> ToUnknownPoint() const {
|
|
|
|
return Point3DTyped<UnknownUnits>(this->x, this->y, this->z);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
typedef Point3DTyped<UnknownUnits> Point3D;
|
|
|
|
|
2013-05-29 13:32:30 +00:00
|
|
|
template<class units>
|
|
|
|
struct IntSizeTyped :
|
|
|
|
public BaseSize< int32_t, IntSizeTyped<units> >,
|
|
|
|
public units {
|
|
|
|
typedef BaseSize< int32_t, IntSizeTyped<units> > Super;
|
2011-11-14 04:29:01 +00:00
|
|
|
|
2013-09-13 16:34:20 +00:00
|
|
|
MOZ_CONSTEXPR IntSizeTyped() : Super() {}
|
|
|
|
MOZ_CONSTEXPR IntSizeTyped(int32_t aWidth, int32_t aHeight) : Super(aWidth, aHeight) {}
|
2013-06-11 22:13:11 +00:00
|
|
|
|
|
|
|
// XXX When all of the code is ported, the following functions to convert to and from
|
|
|
|
// unknown types should be removed.
|
|
|
|
|
|
|
|
static IntSizeTyped<units> FromUnknownSize(const IntSizeTyped<UnknownUnits>& aSize) {
|
|
|
|
return IntSizeTyped<units>(aSize.width, aSize.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
IntSizeTyped<UnknownUnits> ToUnknownSize() const {
|
|
|
|
return IntSizeTyped<UnknownUnits>(this->width, this->height);
|
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
};
|
2013-05-29 13:32:30 +00:00
|
|
|
typedef IntSizeTyped<UnknownUnits> IntSize;
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2013-05-29 13:32:30 +00:00
|
|
|
template<class units>
|
|
|
|
struct SizeTyped :
|
|
|
|
public BaseSize< Float, SizeTyped<units> >,
|
|
|
|
public units {
|
|
|
|
typedef BaseSize< Float, SizeTyped<units> > Super;
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2014-02-06 18:06:08 +00:00
|
|
|
MOZ_CONSTEXPR SizeTyped() : Super() {}
|
|
|
|
MOZ_CONSTEXPR SizeTyped(Float aWidth, Float aHeight) : Super(aWidth, aHeight) {}
|
2013-05-29 13:32:30 +00:00
|
|
|
explicit SizeTyped(const IntSizeTyped<units>& size) :
|
2013-03-04 14:38:11 +00:00
|
|
|
Super(float(size.width), float(size.height)) {}
|
2013-06-11 22:13:11 +00:00
|
|
|
|
|
|
|
// XXX When all of the code is ported, the following functions to convert to and from
|
|
|
|
// unknown types should be removed.
|
|
|
|
|
|
|
|
static SizeTyped<units> FromUnknownSize(const SizeTyped<UnknownUnits>& aSize) {
|
|
|
|
return SizeTyped<units>(aSize.width, aSize.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
SizeTyped<UnknownUnits> ToUnknownSize() const {
|
|
|
|
return SizeTyped<UnknownUnits>(this->width, this->height);
|
|
|
|
}
|
2011-05-26 19:41:33 +00:00
|
|
|
};
|
2013-05-29 13:32:30 +00:00
|
|
|
typedef SizeTyped<UnknownUnits> Size;
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2013-09-03 19:12:24 +00:00
|
|
|
template<class units>
|
|
|
|
IntSizeTyped<units> RoundedToInt(const SizeTyped<units>& aSize) {
|
|
|
|
return IntSizeTyped<units>(int32_t(floorf(aSize.width + 0.5f)),
|
|
|
|
int32_t(floorf(aSize.height + 0.5f)));
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
2011-05-26 19:41:33 +00:00
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
#endif /* MOZILLA_GFX_POINT_H_ */
|