mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 772726. Part 8: Add Rect::NudgeToIntegers and share improved nudging code among all nudging APIs. r=bas
This commit is contained in:
parent
d3d8b75397
commit
db11746193
@ -30,11 +30,13 @@ EXPORTS_mozilla/gfx = \
|
||||
Matrix.h \
|
||||
Rect.h \
|
||||
Types.h \
|
||||
Tools.h \
|
||||
UserData.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
Factory.cpp \
|
||||
Factory.cpp \
|
||||
Rect.cpp \
|
||||
Matrix.cpp \
|
||||
DrawTargetCairo.cpp \
|
||||
SourceSurfaceCairo.cpp \
|
||||
|
@ -4,6 +4,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "Matrix.h"
|
||||
#include "Tools.h"
|
||||
#include <math.h>
|
||||
|
||||
namespace mozilla {
|
||||
@ -56,14 +57,6 @@ Matrix::TransformBounds(const Rect &aRect) const
|
||||
return Rect(min_x, min_y, max_x - min_x, max_y - min_y);
|
||||
}
|
||||
|
||||
static void NudgeToInteger(float *aVal)
|
||||
{
|
||||
float r = floorf(*aVal + 0.5f);
|
||||
if (fabsf(*aVal - r) < 1e-4f) {
|
||||
*aVal = r;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Matrix::NudgeToIntegers()
|
||||
{
|
||||
|
@ -52,6 +52,8 @@ struct Rect :
|
||||
Super(float(rect.x), float(rect.y),
|
||||
float(rect.width), float(rect.height)) {}
|
||||
|
||||
GFX2D_API void NudgeToIntegers();
|
||||
|
||||
bool ToIntRect(IntRect *aOut)
|
||||
{
|
||||
*aOut = IntRect(int32_t(X()), int32_t(Y()),
|
||||
|
@ -7,6 +7,8 @@
|
||||
#define MOZILLA_GFX_TOOLS_H_
|
||||
|
||||
#include "Types.h"
|
||||
#include "Point.h"
|
||||
#include <math.h>
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1600)
|
||||
#define hypotf _hypotf
|
||||
#endif
|
||||
@ -46,6 +48,20 @@ FuzzyEqual(Float aA, Float aB, Float aErr)
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void
|
||||
NudgeToInteger(float *aVal)
|
||||
{
|
||||
float r = floorf(*aVal + 0.5f);
|
||||
// The error threshold should be proportional to the rounded value. This
|
||||
// bounds the relative error introduced by the nudge operation. However,
|
||||
// when the rounded value is 0, the error threshold can't be proportional
|
||||
// to the rounded value (we'd never round), so we just choose the same
|
||||
// threshold as for a rounded value of 1.
|
||||
if (FuzzyEqual(r, *aVal, r == 0.0f ? 1e-6f : fabs(r*1e-6f))) {
|
||||
*aVal = r;
|
||||
}
|
||||
}
|
||||
|
||||
static inline Float
|
||||
Distance(Point aA, Point aB)
|
||||
{
|
||||
|
@ -5,9 +5,12 @@
|
||||
|
||||
#include "gfxMatrix.h"
|
||||
#include "gfx3DMatrix.h"
|
||||
#include "mozilla/gfx/Tools.h"
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
/* Force small values to zero. We do this to avoid having sin(360deg)
|
||||
* evaluate to a tiny but nonzero value.
|
||||
@ -810,14 +813,6 @@ bool gfx3DMatrix::IsBackfaceVisible() const
|
||||
return (_33 * det) < 0;
|
||||
}
|
||||
|
||||
static void NudgeToInteger(float *aVal)
|
||||
{
|
||||
float r = floorf(*aVal + 0.5f);
|
||||
if (fabsf(*aVal - r) < 1e-4f) {
|
||||
*aVal = r;
|
||||
}
|
||||
}
|
||||
|
||||
void gfx3DMatrix::NudgeToIntegers(void)
|
||||
{
|
||||
NudgeToInteger(&_11);
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "gfxMatrix.h"
|
||||
#include "cairo.h"
|
||||
#include "mozilla/gfx/Tools.h"
|
||||
|
||||
#define CAIRO_MATRIX(x) reinterpret_cast<cairo_matrix_t*>((x))
|
||||
#define CONST_CAIRO_MATRIX(x) reinterpret_cast<const cairo_matrix_t*>((x))
|
||||
@ -127,10 +128,8 @@ gfxMatrix::TransformBounds(const gfxRect& rect) const
|
||||
static void NudgeToInteger(double *aVal)
|
||||
{
|
||||
float f = float(*aVal);
|
||||
float r = NS_roundf(f);
|
||||
if (f == r) {
|
||||
*aVal = r;
|
||||
}
|
||||
mozilla::gfx::NudgeToInteger(&f);
|
||||
*aVal = f;
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user