2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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 23:41:33 +04:00
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
#ifndef MOZILLA_GFX_POINT_H_
|
|
|
|
#define MOZILLA_GFX_POINT_H_
|
2011-05-26 23:41:33 +04:00
|
|
|
|
2013-11-22 23:45:50 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2011-06-24 21:41:16 +04:00
|
|
|
#include "Types.h"
|
2014-08-19 21:08:16 +04:00
|
|
|
#include "Coord.h"
|
|
|
|
#include "BaseCoord.h"
|
2011-06-24 21:41:16 +04:00
|
|
|
#include "BasePoint.h"
|
2013-11-27 15:22:02 +04:00
|
|
|
#include "BasePoint3D.h"
|
2014-03-18 08:06:23 +04:00
|
|
|
#include "BasePoint4D.h"
|
2011-06-24 21:41:16 +04:00
|
|
|
#include "BaseSize.h"
|
2017-06-02 10:11:34 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2011-05-26 23:41:33 +04:00
|
|
|
|
2013-08-08 23:56:09 +04:00
|
|
|
#include <cmath>
|
2020-03-28 16:57:20 +03:00
|
|
|
#include <type_traits>
|
2013-08-08 23:56:09 +04:00
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
namespace mozilla {
|
2014-06-10 20:43:52 +04:00
|
|
|
|
|
|
|
template <typename>
|
|
|
|
struct IsPixel;
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
namespace gfx {
|
2011-05-26 23:41:33 +04:00
|
|
|
|
2013-05-29 17:32:30 +04:00
|
|
|
// This should only be used by the typedefs below.
|
|
|
|
struct UnknownUnits {};
|
2011-11-14 08:29:01 +04:00
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
2014-06-10 20:43:52 +04:00
|
|
|
|
|
|
|
template <>
|
2020-03-28 16:57:20 +03:00
|
|
|
struct IsPixel<gfx::UnknownUnits> : std::true_type {};
|
2014-06-10 20:43:52 +04:00
|
|
|
|
|
|
|
namespace gfx {
|
|
|
|
|
2016-07-26 17:48:30 +03:00
|
|
|
/// Use this for parameters of functions to allow implicit conversions to
|
|
|
|
/// integer types but not floating point types.
|
|
|
|
/// We use this wrapper to prevent IntSize and IntPoint's constructors to
|
|
|
|
/// take foating point values as parameters, and not require their constructors
|
|
|
|
/// to have implementations for each permutation of integer types.
|
|
|
|
template <typename T>
|
|
|
|
struct IntParam {
|
|
|
|
constexpr MOZ_IMPLICIT IntParam(char val) : value(val) {}
|
|
|
|
constexpr MOZ_IMPLICIT IntParam(unsigned char val) : value(val) {}
|
|
|
|
constexpr MOZ_IMPLICIT IntParam(short val) : value(val) {}
|
|
|
|
constexpr MOZ_IMPLICIT IntParam(unsigned short val) : value(val) {}
|
|
|
|
constexpr MOZ_IMPLICIT IntParam(int val) : value(val) {}
|
|
|
|
constexpr MOZ_IMPLICIT IntParam(unsigned int val) : value(val) {}
|
|
|
|
constexpr MOZ_IMPLICIT IntParam(long val) : value(val) {}
|
|
|
|
constexpr MOZ_IMPLICIT IntParam(unsigned long val) : value(val) {}
|
|
|
|
constexpr MOZ_IMPLICIT IntParam(long long val) : value(val) {}
|
|
|
|
constexpr MOZ_IMPLICIT IntParam(unsigned long long val) : value(val) {}
|
|
|
|
template <typename Unit>
|
|
|
|
constexpr MOZ_IMPLICIT IntParam(IntCoordTyped<Unit> val) : value(val) {}
|
|
|
|
|
|
|
|
// Disable the evil ones!
|
|
|
|
MOZ_IMPLICIT IntParam(float val) = delete;
|
|
|
|
MOZ_IMPLICIT IntParam(double val) = delete;
|
|
|
|
|
|
|
|
T value;
|
|
|
|
};
|
|
|
|
|
2016-07-26 17:48:34 +03:00
|
|
|
template <class units, class>
|
|
|
|
struct PointTyped;
|
|
|
|
template <class units, class>
|
|
|
|
struct SizeTyped;
|
|
|
|
|
2013-05-29 17:32:30 +04:00
|
|
|
template <class units>
|
|
|
|
struct IntPointTyped
|
2014-08-19 21:08:16 +04:00
|
|
|
: public BasePoint<int32_t, IntPointTyped<units>, IntCoordTyped<units> >,
|
2013-05-29 17:32:30 +04:00
|
|
|
public units {
|
2014-06-10 20:43:52 +04:00
|
|
|
static_assert(IsPixel<units>::value,
|
|
|
|
"'units' must be a coordinate system tag");
|
|
|
|
|
2016-07-26 17:48:30 +03:00
|
|
|
typedef IntParam<int32_t> ToInt;
|
2014-08-19 21:08:16 +04:00
|
|
|
typedef IntCoordTyped<units> Coord;
|
|
|
|
typedef BasePoint<int32_t, IntPointTyped<units>, IntCoordTyped<units> > Super;
|
2013-05-29 17:32:30 +04:00
|
|
|
|
2016-07-09 00:39:53 +03:00
|
|
|
constexpr IntPointTyped() : Super() {}
|
2016-07-26 17:48:30 +03:00
|
|
|
constexpr IntPointTyped(ToInt aX, ToInt aY)
|
|
|
|
: Super(Coord(aX.value), Coord(aY.value)) {}
|
|
|
|
|
|
|
|
static IntPointTyped<units> Round(float aX, float aY) {
|
|
|
|
return IntPointTyped(int32_t(floorf(aX + 0.5)), int32_t(floorf(aY + 0.5)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static IntPointTyped<units> Ceil(float aX, float aY) {
|
|
|
|
return IntPointTyped(int32_t(ceil(aX)), int32_t(ceil(aY)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static IntPointTyped<units> Floor(float aX, float aY) {
|
|
|
|
return IntPointTyped(int32_t(floorf(aX)), int32_t(floorf(aY)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static IntPointTyped<units> Truncate(float aX, float aY) {
|
|
|
|
return IntPointTyped(int32_t(aX), int32_t(aY));
|
|
|
|
}
|
2013-06-12 02:13:11 +04:00
|
|
|
|
2016-07-26 17:48:34 +03:00
|
|
|
static IntPointTyped<units> Round(const PointTyped<units, float>& aPoint);
|
|
|
|
static IntPointTyped<units> Ceil(const PointTyped<units, float>& aPoint);
|
|
|
|
static IntPointTyped<units> Floor(const PointTyped<units, float>& aPoint);
|
|
|
|
static IntPointTyped<units> Truncate(const PointTyped<units, float>& aPoint);
|
|
|
|
|
2013-06-12 02:13:11 +04: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 08:29:01 +04:00
|
|
|
};
|
2013-05-29 17:32:30 +04:00
|
|
|
typedef IntPointTyped<UnknownUnits> IntPoint;
|
2011-11-14 08:29:01 +04:00
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
template <class units, class F = Float>
|
2013-05-29 17:32:30 +04:00
|
|
|
struct PointTyped
|
2015-06-11 23:43:40 +03:00
|
|
|
: public BasePoint<F, PointTyped<units, F>, CoordTyped<units, F> >,
|
2013-05-29 17:32:30 +04:00
|
|
|
public units {
|
2014-06-10 20:43:52 +04:00
|
|
|
static_assert(IsPixel<units>::value,
|
|
|
|
"'units' must be a coordinate system tag");
|
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
typedef CoordTyped<units, F> Coord;
|
|
|
|
typedef BasePoint<F, PointTyped<units, F>, CoordTyped<units, F> > Super;
|
2011-11-14 08:29:01 +04:00
|
|
|
|
2016-07-09 00:39:53 +03:00
|
|
|
constexpr PointTyped() : Super() {}
|
|
|
|
constexpr PointTyped(F aX, F aY) : Super(Coord(aX), Coord(aY)) {}
|
2014-08-19 21:08:16 +04:00
|
|
|
// The mixed-type constructors (Float, Coord) and (Coord, Float) are needed to
|
|
|
|
// avoid ambiguities because Coord is implicitly convertible to Float.
|
2016-07-09 00:39:53 +03:00
|
|
|
constexpr PointTyped(F aX, Coord aY) : Super(Coord(aX), aY) {}
|
|
|
|
constexpr PointTyped(Coord aX, F aY) : Super(aX, Coord(aY)) {}
|
|
|
|
constexpr PointTyped(Coord aX, Coord aY) : Super(aX.value, aY.value) {}
|
|
|
|
constexpr MOZ_IMPLICIT PointTyped(const IntPointTyped<units>& point)
|
|
|
|
: Super(F(point.x), F(point.y)) {}
|
2013-05-31 05:30:13 +04:00
|
|
|
|
2019-01-09 18:37:52 +03:00
|
|
|
bool WithinEpsilonOf(const PointTyped<units, F>& aPoint, F aEpsilon) const {
|
2017-06-28 18:42:23 +03:00
|
|
|
return fabs(aPoint.x - this->x) < aEpsilon &&
|
|
|
|
fabs(aPoint.y - this->y) < aEpsilon;
|
|
|
|
}
|
|
|
|
|
2013-05-31 05:30:13 +04:00
|
|
|
// XXX When all of the code is ported, the following functions to convert to
|
|
|
|
// and from unknown types should be removed.
|
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
static PointTyped<units, F> FromUnknownPoint(
|
|
|
|
const PointTyped<UnknownUnits, F>& aPoint) {
|
|
|
|
return PointTyped<units, F>(aPoint.x, aPoint.y);
|
2013-05-31 05:30:13 +04:00
|
|
|
}
|
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
PointTyped<UnknownUnits, F> ToUnknownPoint() const {
|
|
|
|
return PointTyped<UnknownUnits, F>(this->x, this->y);
|
2013-05-31 05:30:13 +04:00
|
|
|
}
|
2011-06-24 21:41:16 +04:00
|
|
|
};
|
2013-05-29 17:32:30 +04:00
|
|
|
typedef PointTyped<UnknownUnits> Point;
|
2015-06-11 23:43:40 +03:00
|
|
|
typedef PointTyped<UnknownUnits, double> PointDouble;
|
2011-05-26 23:41:33 +04:00
|
|
|
|
2013-06-15 00:11:31 +04:00
|
|
|
template <class units>
|
|
|
|
IntPointTyped<units> RoundedToInt(const PointTyped<units>& aPoint) {
|
2016-07-26 17:48:30 +03:00
|
|
|
return IntPointTyped<units>::Round(aPoint.x, aPoint.y);
|
2014-08-19 21:08:16 +04:00
|
|
|
}
|
2016-11-21 21:50:33 +03:00
|
|
|
|
2014-08-19 21:08:16 +04:00
|
|
|
template <class units>
|
|
|
|
IntPointTyped<units> TruncatedToInt(const PointTyped<units>& aPoint) {
|
2016-07-26 17:48:30 +03:00
|
|
|
return IntPointTyped<units>::Truncate(aPoint.x, aPoint.y);
|
2013-06-15 00:11:31 +04:00
|
|
|
}
|
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
template <class units, class F = Float>
|
|
|
|
struct Point3DTyped : public BasePoint3D<F, Point3DTyped<units, F> > {
|
2014-06-10 20:43:52 +04:00
|
|
|
static_assert(IsPixel<units>::value,
|
|
|
|
"'units' must be a coordinate system tag");
|
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
typedef BasePoint3D<F, Point3DTyped<units, F> > Super;
|
2013-11-27 15:22:02 +04:00
|
|
|
|
|
|
|
Point3DTyped() : Super() {}
|
2015-06-11 23:43:40 +03:00
|
|
|
Point3DTyped(F aX, F aY, F aZ) : Super(aX, aY, aZ) {}
|
2013-11-27 15:22:02 +04:00
|
|
|
|
|
|
|
// XXX When all of the code is ported, the following functions to convert to
|
|
|
|
// and from unknown types should be removed.
|
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
static Point3DTyped<units, F> FromUnknownPoint(
|
|
|
|
const Point3DTyped<UnknownUnits, F>& aPoint) {
|
|
|
|
return Point3DTyped<units, F>(aPoint.x, aPoint.y, aPoint.z);
|
2013-11-27 15:22:02 +04:00
|
|
|
}
|
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
Point3DTyped<UnknownUnits, F> ToUnknownPoint() const {
|
|
|
|
return Point3DTyped<UnknownUnits, F>(this->x, this->y, this->z);
|
2013-11-27 15:22:02 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
typedef Point3DTyped<UnknownUnits> Point3D;
|
2015-06-11 23:43:40 +03:00
|
|
|
typedef Point3DTyped<UnknownUnits, double> PointDouble3D;
|
2013-11-27 15:22:02 +04:00
|
|
|
|
2016-07-26 17:48:34 +03:00
|
|
|
template <typename units>
|
|
|
|
IntPointTyped<units> IntPointTyped<units>::Round(
|
|
|
|
const PointTyped<units, float>& aPoint) {
|
|
|
|
return IntPointTyped::Round(aPoint.x, aPoint.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename units>
|
|
|
|
IntPointTyped<units> IntPointTyped<units>::Ceil(
|
|
|
|
const PointTyped<units, float>& aPoint) {
|
|
|
|
return IntPointTyped::Ceil(aPoint.x, aPoint.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename units>
|
|
|
|
IntPointTyped<units> IntPointTyped<units>::Floor(
|
|
|
|
const PointTyped<units, float>& aPoint) {
|
|
|
|
return IntPointTyped::Floor(aPoint.x, aPoint.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename units>
|
|
|
|
IntPointTyped<units> IntPointTyped<units>::Truncate(
|
|
|
|
const PointTyped<units, float>& aPoint) {
|
|
|
|
return IntPointTyped::Truncate(aPoint.x, aPoint.y);
|
|
|
|
}
|
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
template <class units, class F = Float>
|
|
|
|
struct Point4DTyped : public BasePoint4D<F, Point4DTyped<units, F> > {
|
2014-06-10 20:43:52 +04:00
|
|
|
static_assert(IsPixel<units>::value,
|
|
|
|
"'units' must be a coordinate system tag");
|
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
typedef BasePoint4D<F, Point4DTyped<units, F> > Super;
|
2014-03-18 08:06:23 +04:00
|
|
|
|
|
|
|
Point4DTyped() : Super() {}
|
2015-06-11 23:43:40 +03:00
|
|
|
Point4DTyped(F aX, F aY, F aZ, F aW) : Super(aX, aY, aZ, aW) {}
|
2014-03-18 08:06:23 +04:00
|
|
|
|
2016-11-21 21:50:33 +03:00
|
|
|
explicit Point4DTyped(const Point3DTyped<units, F>& aPoint)
|
|
|
|
: Super(aPoint.x, aPoint.y, aPoint.z, 1) {}
|
|
|
|
|
2014-03-18 08:06:23 +04:00
|
|
|
// XXX When all of the code is ported, the following functions to convert to
|
|
|
|
// and from unknown types should be removed.
|
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
static Point4DTyped<units, F> FromUnknownPoint(
|
|
|
|
const Point4DTyped<UnknownUnits, F>& aPoint) {
|
|
|
|
return Point4DTyped<units, F>(aPoint.x, aPoint.y, aPoint.z, aPoint.w);
|
2014-03-18 08:06:23 +04:00
|
|
|
}
|
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
Point4DTyped<UnknownUnits, F> ToUnknownPoint() const {
|
|
|
|
return Point4DTyped<UnknownUnits, F>(this->x, this->y, this->z, this->w);
|
2014-03-18 08:06:23 +04:00
|
|
|
}
|
2014-08-22 17:40:02 +04:00
|
|
|
|
2016-11-21 21:50:33 +03:00
|
|
|
PointTyped<units, F> As2DPoint() const {
|
|
|
|
return PointTyped<units, F>(this->x / this->w, this->y / this->w);
|
|
|
|
}
|
|
|
|
|
|
|
|
Point3DTyped<units, F> As3DPoint() const {
|
|
|
|
return Point3DTyped<units, F>(this->x / this->w, this->y / this->w,
|
|
|
|
this->z / this->w);
|
2014-08-22 17:40:02 +04:00
|
|
|
}
|
2014-03-18 08:06:23 +04:00
|
|
|
};
|
|
|
|
typedef Point4DTyped<UnknownUnits> Point4D;
|
2015-06-11 23:43:40 +03:00
|
|
|
typedef Point4DTyped<UnknownUnits, double> PointDouble4D;
|
2014-03-18 08:06:23 +04:00
|
|
|
|
2013-05-29 17:32:30 +04:00
|
|
|
template <class units>
|
|
|
|
struct IntSizeTyped : public BaseSize<int32_t, IntSizeTyped<units> >,
|
|
|
|
public units {
|
2014-06-10 20:43:52 +04:00
|
|
|
static_assert(IsPixel<units>::value,
|
|
|
|
"'units' must be a coordinate system tag");
|
|
|
|
|
2016-07-26 17:48:30 +03:00
|
|
|
typedef IntParam<int32_t> ToInt;
|
2013-05-29 17:32:30 +04:00
|
|
|
typedef BaseSize<int32_t, IntSizeTyped<units> > Super;
|
2011-11-14 08:29:01 +04:00
|
|
|
|
2016-07-09 00:39:53 +03:00
|
|
|
constexpr IntSizeTyped() : Super() {}
|
2016-07-26 17:48:30 +03:00
|
|
|
constexpr IntSizeTyped(ToInt aWidth, ToInt aHeight)
|
|
|
|
: Super(aWidth.value, aHeight.value) {}
|
|
|
|
|
|
|
|
static IntSizeTyped<units> Round(float aWidth, float aHeight) {
|
|
|
|
return IntSizeTyped(int32_t(floorf(aWidth + 0.5)),
|
|
|
|
int32_t(floorf(aHeight + 0.5)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static IntSizeTyped<units> Truncate(float aWidth, float aHeight) {
|
|
|
|
return IntSizeTyped(int32_t(aWidth), int32_t(aHeight));
|
|
|
|
}
|
|
|
|
|
|
|
|
static IntSizeTyped<units> Ceil(float aWidth, float aHeight) {
|
|
|
|
return IntSizeTyped(int32_t(ceil(aWidth)), int32_t(ceil(aHeight)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static IntSizeTyped<units> Floor(float aWidth, float aHeight) {
|
|
|
|
return IntSizeTyped(int32_t(floorf(aWidth)), int32_t(floorf(aHeight)));
|
|
|
|
}
|
2013-06-12 02:13:11 +04:00
|
|
|
|
2016-07-26 17:48:34 +03:00
|
|
|
static IntSizeTyped<units> Round(const SizeTyped<units, float>& aSize);
|
|
|
|
static IntSizeTyped<units> Ceil(const SizeTyped<units, float>& aSize);
|
|
|
|
static IntSizeTyped<units> Floor(const SizeTyped<units, float>& aSize);
|
|
|
|
static IntSizeTyped<units> Truncate(const SizeTyped<units, float>& aSize);
|
|
|
|
|
2013-06-12 02:13:11 +04: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 21:41:16 +04:00
|
|
|
};
|
2013-05-29 17:32:30 +04:00
|
|
|
typedef IntSizeTyped<UnknownUnits> IntSize;
|
2017-06-02 10:11:34 +03:00
|
|
|
typedef Maybe<IntSize> MaybeIntSize;
|
2011-05-26 23:41:33 +04:00
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
template <class units, class F = Float>
|
2016-11-24 03:26:55 +03:00
|
|
|
struct SizeTyped : public BaseSize<F, SizeTyped<units, F> >, public units {
|
2014-06-10 20:43:52 +04:00
|
|
|
static_assert(IsPixel<units>::value,
|
|
|
|
"'units' must be a coordinate system tag");
|
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
typedef BaseSize<F, SizeTyped<units, F> > Super;
|
2011-05-26 23:41:33 +04:00
|
|
|
|
2016-07-09 00:39:53 +03:00
|
|
|
constexpr SizeTyped() : Super() {}
|
|
|
|
constexpr SizeTyped(F aWidth, F aHeight) : Super(aWidth, aHeight) {}
|
2013-05-29 17:32:30 +04:00
|
|
|
explicit SizeTyped(const IntSizeTyped<units>& size)
|
2015-06-11 23:43:40 +03:00
|
|
|
: Super(F(size.width), F(size.height)) {}
|
2013-06-12 02:13:11 +04:00
|
|
|
|
|
|
|
// XXX When all of the code is ported, the following functions to convert to
|
|
|
|
// and from unknown types should be removed.
|
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
static SizeTyped<units, F> FromUnknownSize(
|
|
|
|
const SizeTyped<UnknownUnits, F>& aSize) {
|
|
|
|
return SizeTyped<units, F>(aSize.width, aSize.height);
|
2013-06-12 02:13:11 +04:00
|
|
|
}
|
|
|
|
|
2015-06-11 23:43:40 +03:00
|
|
|
SizeTyped<UnknownUnits, F> ToUnknownSize() const {
|
|
|
|
return SizeTyped<UnknownUnits, F>(this->width, this->height);
|
2013-06-12 02:13:11 +04:00
|
|
|
}
|
2011-05-26 23:41:33 +04:00
|
|
|
};
|
2013-05-29 17:32:30 +04:00
|
|
|
typedef SizeTyped<UnknownUnits> Size;
|
2015-06-11 23:43:40 +03:00
|
|
|
typedef SizeTyped<UnknownUnits, double> SizeDouble;
|
2011-05-26 23:41:33 +04:00
|
|
|
|
2013-09-03 23:12:24 +04: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)));
|
|
|
|
}
|
|
|
|
|
2016-07-26 17:48:34 +03:00
|
|
|
template <typename units>
|
|
|
|
IntSizeTyped<units> IntSizeTyped<units>::Round(
|
|
|
|
const SizeTyped<units, float>& aSize) {
|
|
|
|
return IntSizeTyped::Round(aSize.width, aSize.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename units>
|
|
|
|
IntSizeTyped<units> IntSizeTyped<units>::Ceil(
|
|
|
|
const SizeTyped<units, float>& aSize) {
|
|
|
|
return IntSizeTyped::Ceil(aSize.width, aSize.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename units>
|
|
|
|
IntSizeTyped<units> IntSizeTyped<units>::Floor(
|
|
|
|
const SizeTyped<units, float>& aSize) {
|
|
|
|
return IntSizeTyped::Floor(aSize.width, aSize.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename units>
|
|
|
|
IntSizeTyped<units> IntSizeTyped<units>::Truncate(
|
|
|
|
const SizeTyped<units, float>& aSize) {
|
|
|
|
return IntSizeTyped::Truncate(aSize.width, aSize.height);
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2011-05-26 23:41:33 +04:00
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
#endif /* MOZILLA_GFX_POINT_H_ */
|