PDF-geometry

#ifndef MUPDF_FITZ_MATH_H
#define MUPDF_FITZ_MATH_H

#include “mupdf/fitz/system.h”

#include <assert.h>

/**
Multiply scaled two integers in the 0…255 range
将 0…255 范围内的两个整数相乘
/
static inline int fz_mul255(int a, int b)
{
/
see Jim Blinn’s book “Dirty Pixels” for how this works */
int x = a * b + 128;
x += x >> 8;
return x >> 8;
}

/**
Undo alpha premultiplication.
撤消 alpha 预乘。
*/
static inline int fz_div255(int c, int a)
{
return a ? c * (255 * 256 / a) >> 8 : 0;
}

/**
Expand a value A from the 0…255 range to the 0…256 range
将值 A 从 0…255 范围扩展到 0…256 范围
*/
#define FZ_EXPAND(A) ((A)+((A)>>7))

/**
Combine values A (in any range) and B (in the 0…256 range),
to give a single value in the same range as A was.
/
#define FZ_COMBINE(A,B) (((A)
(B))>>8)

/**
Combine values A and C (in the same (any) range) and B and D (in
the 0…256 range), to give a single value in the same range as A
and C were.
组合值 A 和 C(在相同(任何)范围内)和 B 和 D(在
0…256 范围),给出与 A 相同范围内的单个值
和 C 是。
*/
#define FZ_COMBINE2(A,B,C,D) (((A) * (B) + © * (D))>>8)

/**
Blend SRC and DST (in the same range) together according to
AMOUNT (in the 0…256 range).
根据以下条件将 SRC 和 DST(在同一范围内)混合在一起
AMOUNT(在 0…256 范围内)。
/
#define FZ_BLEND(SRC, DST, AMOUNT) ((((SRC)-(DST))
(AMOUNT) + ((DST)<<8))>>8)

/**
Range checking atof
范围检查atof
*/
float fz_atof(const char *s);

/**
atoi that copes with NULL
处理NULL的atoi
*/
int fz_atoi(const char *s);

/**
64bit atoi that copes with NULL
处理 NULL 的 64 位 atoi
*/
int64_t fz_atoi64(const char *s);

/**
Some standard math functions, done as static inlines for speed.
People with compilers that do not adequately implement inline
may like to reimplement these using macros.
一些标准数学函数,以静态内联方式完成以提高速度。
编译器没有充分实现内联的人
可能想使用宏重新实现这些。
*/
static inline float fz_abs(float f)
{
return (f < 0 ? -f : f);
}

static inline int fz_absi(int i)
{
return (i < 0 ? -i : i);
}

static inline float fz_min(float a, float b)
{
return (a < b ? a : b);
}

static inline int fz_mini(int a, int b)
{
return (a < b ? a : b);
}

static inline size_t fz_minz(size_t a, size_t b)
{
return (a < b ? a : b);
}

static inline float fz_max(float a, float b)
{
return (a > b ? a : b);
}

static inline int fz_maxi(int a, int b)
{
return (a > b ? a : b);
}

static inline size_t fz_maxz(size_t a, size_t b)
{
return (a > b ? a : b);
}

static inline int64_t fz_maxi64(int64_t a, int64_t b)
{
return (a > b ? a : b);
}

static inline float fz_clamp(float f, float min, float max)
{
return (f > min ? (f < max ? f : max) : min);
}

static inline int fz_clampi(int i, int min, int max)
{
return (i > min ? (i < max ? i : max) : min);
}

static inline double fz_clampd(double d, double min, double max)
{
return (d > min ? (d < max ? d : max) : min);
}

static inline void *fz_clampp(void *p, void *min, void *max)
{
return (p > min ? (p < max ? p : max) : min);
}

#define DIV_BY_ZERO(a, b, min, max) (((a) < 0) ^ ((b) < 0) ? (min) : (max))

/**
fz_point is a point in a two-dimensional space.
fz_point 是二维空间中的一个点。
*/
typedef struct
{
float x, y;
} fz_point;

static inline fz_point fz_make_point(float x, float y)
{
fz_point p = { x, y };
return p;
}

/**
fz_rect is a rectangle represented by two diagonally opposite
corners at arbitrary coordinates.

Rectangles are always axis-aligned with the X- and Y- axes. We
wish to distinguish rectangles in 3 categories; infinite, finite,
and invalid. Zero area rectangles are a sub-category of finite
ones.

For all valid rectangles, x0 <= x1 and y0 <= y1 in all cases.
Infinite rectangles have x0 = y0 = FZ_MIN_INF_RECT,
x1 = y1 = FZ_MAX_INF_RECT. For any non infinite valid rectangle,
the area is defined as (x1 - x0) * (y1 - y0).

To check for empty or infinite rectangles use fz_is_empty_rect
and fz_is_infinite_rect. To check for valid rectangles use
fz_is_valid_rect.

We choose this representation, so that we can easily distinguish
the difference between intersecting 2 valid rectangles and
getting an invalid one, as opposed to getting a zero area one
(which nonetheless has valid bounds within the plane).

x0, y0: The top left corner.

x1, y1: The bottom right corner.

We choose FZ_{MIN,MAX}_INF_RECT to be the largest 32bit signed
integer values that survive roundtripping to floats.
fz_rect 是由两个对角线表示的矩形
任意坐标处的角。

矩形始终与 X 轴和 Y 轴在轴上对齐。我们
希望区分 3 类矩形;无限,有限,
并且无效。零面积矩形是有限的一个子类别
那些。

对于所有有效矩形,在所有情况下 x0 <= x1 和 y0 <= y1。
无限矩形有 x0 = y0 = FZ_MIN_INF_RECT,
x1 = y1 = FZ_MAX_INF_RECT。对于任何非无限有效矩形,
面积定义为 (x1 - x0) * (y1 - y0)。

要检查空矩形或无限矩形,请使用 fz_is_empty_rect
和 fz_is_infinite_rect。要检查有效的矩形使用
fz_is_valid_rect。

我们选择这种表示方式,以便我们可以轻松区分
相交2个有效矩形和
得到一个无效的,而不是得到一个零区域一
(尽管如此,它在平面内具有有效的边界)。

x0, y0:左上角。

x1, y1:右下角。

我们选择 FZ_{MIN,MAX}_INF_RECT 作为最大的 32 位有符号
在往返浮点数的过程中幸存下来的整数值。

*/
#define FZ_MIN_INF_RECT ((int)0x80000000)
#define FZ_MAX_INF_RECT ((int)0x7fffff80)

typedef struct
{
float x0, y0;
float x1, y1;
} fz_rect;

static inline fz_rect fz_make_rect(float x0, float y0, float x1, float y1)
{
fz_rect r = { x0, y0, x1, y1 };
return r;
}

/**
fz_irect is a rectangle using integers instead of floats.

It's used in the draw device and for pixmap dimensions.
fz_irect 是一个使用整数代替浮点数的矩形。

它用于绘图设备和像素图尺寸。

*/
typedef struct
{
int x0, y0;
int x1, y1;
} fz_irect;

static inline fz_irect fz_make_irect(int x0, int y0, int x1, int y1)
{
fz_irect r = { x0, y0, x1, y1 };
return r;
}

/**
A rectangle with sides of length one.

The bottom left corner is at (0, 0) and the top right corner
is at (1, 1).
边长为 1 的矩形。

左下角在 (0, 0) 和右上角
在 (1, 1) 处。

*/
extern const fz_rect fz_unit_rect;

/**
An empty rectangle with an area equal to zero.
面积为零的空矩形。
*/
extern const fz_rect fz_empty_rect;
extern const fz_irect fz_empty_irect;

/**
An infinite rectangle.
一个无限长的矩形。
*/
extern const fz_rect fz_infinite_rect;
extern const fz_irect fz_infinite_irect;

/**
Check if rectangle is empty.

An empty rectangle is defined as one whose area is zero.
All invalid rectangles are empty.
检查矩形是否为空。

空矩形定义为面积为零的矩形。
所有无效的矩形都是空的。

*/
static inline int fz_is_empty_rect(fz_rect r)
{
return (r.x0 >= r.x1 || r.y0 >= r.y1);
}

static inline int fz_is_empty_irect(fz_irect r)
{
return (r.x0 >= r.x1 || r.y0 >= r.y1);
}

/**
Check if rectangle is infinite.
*/
static inline int fz_is_infinite_rect(fz_rect r)
{
return (r.x0 == FZ_MIN_INF_RECT && r.x1 == FZ_MAX_INF_RECT &&
r.y0 == FZ_MIN_INF_RECT && r.y1 == FZ_MAX_INF_RECT);
}

/**
Check if an integer rectangle
is infinite.
检查是否为整数矩形是无限的。
*/
static inline int fz_is_infinite_irect(fz_irect r)
{
return (r.x0 == FZ_MIN_INF_RECT && r.x1 == FZ_MAX_INF_RECT &&
r.y0 == FZ_MIN_INF_RECT && r.y1 == FZ_MAX_INF_RECT);
}

/**
Check if rectangle is valid.
检查矩形是否有效。
*/
static inline int fz_is_valid_rect(fz_rect r)
{
return (r.x0 <= r.x1 && r.y0 <= r.y1);
}

/**
Check if an integer rectangle is valid.
检查整数矩形是否有效。
*/
static inline int fz_is_valid_irect(fz_irect r)
{
return (r.x0 <= r.x1 && r.y0 <= r.y1);
}

/**
Return the width of an irect. Invalid irects return 0.
返回一个矩形的宽度。 无效的指令返回 0。
/
static inline unsigned int
fz_irect_width(fz_irect r)
{
unsigned int w;
if (r.x0 >= r.x1)
return 0;
/
Check for w overflowing. This should never happen, but
* if it does, it’s pretty likely an indication of a severe
* problem. */
w = (unsigned int)r.x1 - r.x0;
assert((int)w >= 0);
if ((int)w < 0)
return 0;
return (int)w;
}

/**
Return the height of an irect. Invalid irects return 0.
返回一个直角的高度。 无效的指令返回 0。
/
static inline int
fz_irect_height(fz_irect r)
{
unsigned int h;
if (r.y0 >= r.y1)
return 0;
/
Check for h overflowing. This should never happen, but
* if it does, it’s pretty likely an indication of a severe
* problem. */
h = (unsigned int)(r.y1 - r.y0);
assert((int)h >= 0);
if ((int)h < 0)
return 0;
return (int)h;
}

/**
fz_matrix is a row-major 3x3 matrix used for representing
transformations of coordinates throughout MuPDF.

Since all points reside in a two-dimensional space, one vector
is always a constant unit vector; hence only some elements may
vary in a matrix. Below is how the elements map between
different representations.

/ a b 0 \
| c d 0 | normally represented as [ a b c d e f ].
\ e f 1 /

fz_matrix 是一个行主 3x3 矩阵,用于表示
整个 MuPDF 的坐标转换。

由于所有点都位于二维空间中,因此一个向量
总是一个常数单位向量; 因此只有一些元素可以
在矩阵中变化。 下面是元素之间的映射方式
不同的表示。

/ a b 0 \
| cd 0 | 通常表示为 [ a b c d e f ]。
\e f 1 /

*/
typedef struct
{
float a, b, c, d, e, f;
} fz_matrix;

/**
Identity transform matrix.
单位变换矩阵。
*/
extern const fz_matrix fz_identity;

static inline fz_matrix fz_make_matrix(float a, float b, float c, float d, float e, float f)
{
fz_matrix m = { a, b, c, d, e, f };
return m;
}

static inline int fz_is_identity(fz_matrix m)
{
return m.a == 1 && m.b == 0 && m.c == 0 && m.d == 1 && m.e == 0 && m.f == 0;
}

/**
Multiply two matrices.

The order of the two matrices are important since matrix
multiplication is not commutative.

Returns result.
将两个矩阵相乘。

两个矩阵的顺序很重要,因为矩阵
乘法不是可交换的。

返回结果。

*/
fz_matrix fz_concat(fz_matrix left, fz_matrix right);

/**
Create a scaling matrix.

The returned matrix is of the form [ sx 0 0 sy 0 0 ].

m: Pointer to the matrix to populate

sx, sy: Scaling factors along the X- and Y-axes. A scaling
factor of 1.0 will not cause any scaling along the relevant
axis.

Returns m.

创建缩放矩阵。

返回的矩阵的形式为 [ sx 0 0 sy 0 0 ]。

m:指向要填充的矩阵的指针

sx, sy:沿 X 轴和 Y 轴的缩放因子。 一个缩放
1.0 的因子不会导致相关的任何缩放
轴。

返回 m。

*/
fz_matrix fz_scale(float sx, float sy);

/**
Scale a matrix by premultiplication.

m: Pointer to the matrix to scale

sx, sy: Scaling factors along the X- and Y-axes. A scaling
factor of 1.0 will not cause any scaling along the relevant
axis.

Returns m (updated).

通过预乘缩放矩阵。

m:指向要缩放的矩阵的指针

sx, sy:沿 X 轴和 Y 轴的缩放因子。 一个缩放
1.0 的因子不会导致相关的任何缩放
轴。

返回 m(更新)。

*/
fz_matrix fz_pre_scale(fz_matrix m, float sx, float sy);

/**
Scale a matrix by postmultiplication.

m: Pointer to the matrix to scale

sx, sy: Scaling factors along the X- and Y-axes. A scaling
factor of 1.0 will not cause any scaling along the relevant
axis.

Returns m (updated).

通过后乘法缩放矩阵。

m:指向要缩放的矩阵的指针

sx, sy:沿 X 轴和 Y 轴的缩放因子。 一个缩放
1.0 的因子不会导致相关的任何缩放
轴。

返回 m(更新)。

*/
fz_matrix fz_post_scale(fz_matrix m, float sx, float sy);

/**
Create a shearing matrix.

The returned matrix is of the form [ 1 sy sx 1 0 0 ].

m: pointer to place to store returned matrix

sx, sy: Shearing factors. A shearing factor of 0.0 will not
cause any shearing along the relevant axis.

Returns m.
创建剪切矩阵。

返回的矩阵的形式为 [ 1 sy sx 1 0 0 ]。

m:指向存储返回矩阵的位置的指针

sx, sy:剪切因子。 0.0 的剪切因子不会
导致沿相关轴的任何剪切。

返回 m。

*/
fz_matrix fz_shear(float sx, float sy);

/**
Premultiply a matrix with a shearing matrix.

The shearing matrix is of the form [ 1 sy sx 1 0 0 ].

m: pointer to matrix to premultiply

sx, sy: Shearing factors. A shearing factor of 0.0 will not
cause any shearing along the relevant axis.

Returns m (updated).
用剪切矩阵预乘矩阵。

剪切矩阵的形式为 [ 1 sy sx 1 0 0 ]。

m:指向要预乘的矩阵的指针

sx, sy:剪切因子。 0.0 的剪切因子不会
导致沿相关轴的任何剪切。

返回 m(更新)。

*/
fz_matrix fz_pre_shear(fz_matrix m, float sx, float sy);

/**
Create a rotation matrix.

The returned matrix is of the form
[ cos(deg) sin(deg) -sin(deg) cos(deg) 0 0 ].

m: Pointer to place to store matrix

degrees: Degrees of counter clockwise rotation. Values less
than zero and greater than 360 are handled as expected.

Returns m.

创建一个旋转矩阵。

返回的矩阵的形式为
[ cos(deg) sin(deg) -sin(deg) cos(deg) 0 0 ]。

m:指向存储矩阵的位置的指针

度数:逆时针旋转的度数。 值更少
大于零和大于 360 按预期处理。

返回 m。
*/
fz_matrix fz_rotate(float degrees);

/**
Rotate a transformation by premultiplying.

The premultiplied matrix is of the form
[ cos(deg) sin(deg) -sin(deg) cos(deg) 0 0 ].

m: Pointer to matrix to premultiply.

degrees: Degrees of counter clockwise rotation. Values less
than zero and greater than 360 are handled as expected.

Returns m (updated).

通过预乘旋转变换。

预乘矩阵的形式为
[ cos(deg) sin(deg) -sin(deg) cos(deg) 0 0 ]。

m:指向要预乘的矩阵的指针。

度数:逆时针旋转的度数。 值更少
大于零和大于 360 按预期处理。

返回 m(更新)。

*/
fz_matrix fz_pre_rotate(fz_matrix m, float degrees);

/**
Create a translation matrix.

The returned matrix is of the form [ 1 0 0 1 tx ty ].

m: A place to store the created matrix.

tx, ty: Translation distances along the X- and Y-axes. A
translation of 0 will not cause any translation along the
relevant axis.

Returns m.
创建翻译矩阵。

返回的矩阵的形式为 [ 1 0 0 1 tx ty ]。

m:存储创建的矩阵的地方。

tx, ty:沿 X 轴和 Y 轴的平移距离。 一种
0 的平移不会导致任何平移
相关轴。

返回 m。
*/
fz_matrix fz_translate(float tx, float ty);

/**
Translate a matrix by premultiplication.

m: The matrix to translate

tx, ty: Translation distances along the X- and Y-axes. A
translation of 0 will not cause any translation along the
relevant axis.

Returns m.

通过预乘转换矩阵。

m:要翻译的矩阵

tx, ty:沿 X 轴和 Y 轴的平移距离。 一种
0 的平移不会导致任何平移
相关轴。

返回 m。

*/
fz_matrix fz_pre_translate(fz_matrix m, float tx, float ty);

/**
Create transform matrix to draw page
at a given resolution and rotation. Adjusts the scaling
factors so that the page covers whole number of
pixels and adjust the page origin to be at 0,0.
创建变换矩阵以绘制页面
在给定的分辨率和旋转。 调整缩放比例
因素,使页面覆盖整数
像素并将页面原点调整为 0,0。
*/
fz_matrix fz_transform_page(fz_rect mediabox, float resolution, float rotate);

/**
Create an inverse matrix.

inverse: Place to store inverse matrix.

matrix: Matrix to invert. A degenerate matrix, where the
determinant is equal to zero, can not be inverted and the
original matrix is returned instead.

Returns inverse.
创建逆矩阵。

inverse:存放逆矩阵的地方。

矩阵:要求逆的矩阵。 一个退化矩阵,其中
行列式为零,不能求反
而是返回原始矩阵。

返回反向。

*/
fz_matrix fz_invert_matrix(fz_matrix matrix);

/**
Attempt to create an inverse matrix.

inverse: Place to store inverse matrix.

matrix: Matrix to invert. A degenerate matrix, where the
determinant is equal to zero, can not be inverted.

Returns 1 if matrix is degenerate (singular), or 0 otherwise.
尝试创建逆矩阵。

inverse:存放逆矩阵的地方。

矩阵:要求逆的矩阵。 一个退化矩阵,其中
行列式等于零,不能取反。

如果矩阵是退化的(单数),则返回 1,否则返回 0。

*/
int fz_try_invert_matrix(fz_matrix *inv, fz_matrix src);

/**
Check if a transformation is rectilinear.

Rectilinear means that no shearing is present and that any
rotations present are a multiple of 90 degrees. Usually this
is used to make sure that axis-aligned rectangles before the
transformation are still axis-aligned rectangles afterwards.
检查变换是否是直线的。

直线意味着不存在剪切并且任何
存在的旋转是 90 度的倍数。 通常这个
用于确保轴对齐的矩形之前
之后转换仍然是轴对齐的矩形。

*/
int fz_is_rectilinear(fz_matrix m);

/**
Calculate average scaling factor of matrix.
计算矩阵的平均缩放因子。
*/
float fz_matrix_expansion(fz_matrix m);

/**
Compute intersection of two rectangles.

Given two rectangles, update the first to be the smallest
axis-aligned rectangle that covers the area covered by both
given rectangles. If either rectangle is empty then the
intersection is also empty. If either rectangle is infinite
then the intersection is simply the non-infinite rectangle.
Should both rectangles be infinite, then the intersection is
also infinite.

计算两个矩形的交集。

给定两个矩形,将第一个更新为最小的
轴对齐的矩形,覆盖了两者所覆盖的区域
给定的矩形。 如果任一矩形为空,则
路口也是空的。 如果任一矩形是无限的
那么交点就是非无限矩形。
如果两个矩形都是无限的,那么交点是
也是无限的。

*/
fz_rect fz_intersect_rect(fz_rect a, fz_rect b);

/**
Compute intersection of two bounding boxes.

Similar to fz_intersect_rect but operates on two bounding
boxes instead of two rectangles.

*/
fz_irect fz_intersect_irect(fz_irect a, fz_irect b);

/**
Compute union of two rectangles.

Given two rectangles, update the first to be the smallest
axis-aligned rectangle that encompasses both given rectangles.
If either rectangle is infinite then the union is also infinite.
If either rectangle is empty then the union is simply the
non-empty rectangle. Should both rectangles be empty, then the
union is also empty.
计算两个矩形的并集。

给定两个矩形,将第一个更新为最小的
包含两个给定矩形的轴对齐矩形。
如果任一矩形是无限的,则联合也是无限的。
如果任一矩形为空,则联合就是
非空矩形。 如果两个矩形都为空,则
工会也是空的。

*/
fz_rect fz_union_rect(fz_rect a, fz_rect b);

/**
Convert a rect into the minimal bounding box
that covers the rectangle.

Coordinates in a bounding box are integers, so rounding of the
rects coordinates takes place. The top left corner is rounded
upwards and left while the bottom right corner is rounded
downwards and to the right.
将矩形转换为最小边界框
覆盖矩形。

边界框中的坐标是整数,因此四舍五入
rects 坐标发生。 左上角是圆角的
向上和向左,而右下角是圆角
向下和向右。

*/
fz_irect fz_irect_from_rect(fz_rect rect);

/**
Round rectangle coordinates.

Coordinates in a bounding box are integers, so rounding of the
rects coordinates takes place. The top left corner is rounded
upwards and left while the bottom right corner is rounded
downwards and to the right.

This differs from fz_irect_from_rect, in that fz_irect_from_rect
slavishly follows the numbers (i.e any slight over/under
calculations can cause whole extra pixels to be added).
fz_round_rect allows for a small amount of rounding error when
calculating the bbox.

*/
fz_irect fz_round_rect(fz_rect rect);

/**
Convert a bbox into a rect.

For our purposes, a rect can represent all the values we meet in
a bbox, so nothing can go wrong.

rect: A place to store the generated rectangle.

bbox: The bbox to convert.

Returns rect (updated).
将 bbox 转换为 rect。

出于我们的目的,一个 rect 可以代表我们遇到的所有值
一个 bbox,所以不会出错。

rect:存储生成的矩形的地方。

bbox:要转换的 bbox。

返回 rect(更新)。

*/
fz_rect fz_rect_from_irect(fz_irect bbox);

/**
Expand a bbox by a given amount in all directions.
*/
fz_rect fz_expand_rect(fz_rect b, float expand);
fz_irect fz_expand_irect(fz_irect a, int expand);

/**
Expand a bbox to include a given point.
To create a rectangle that encompasses a sequence of points, the
rectangle must first be set to be the empty rectangle at one of
the points before including the others.
展开 bbox 以包含给定点。
要创建一个包含一系列点的矩形,
必须首先将矩形设置为以下位置之一的空矩形
包括其他人之前的点。
*/
fz_rect fz_include_point_in_rect(fz_rect r, fz_point p);

/**
Translate bounding box.

Translate a bbox by a given x and y offset. Allows for overflow.
翻译边界框。

通过给定的 x 和 y 偏移量平移 bbox。 允许溢出。

*/
fz_rect fz_translate_rect(fz_rect a, float xoff, float yoff);
fz_irect fz_translate_irect(fz_irect a, int xoff, int yoff);

/**
Test rectangle inclusion.

Return true if a entirely contains b.
测试矩形包含。

如果 a 完全包含 b,则返回 true。

*/
int fz_contains_rect(fz_rect a, fz_rect b);

/**
Apply a transformation to a point.

transform: Transformation matrix to apply. See fz_concat,
fz_scale, fz_rotate and fz_translate for how to create a
matrix.

point: Pointer to point to update.

Returns transform (unchanged).
对点应用变换。

变换:要应用的变换矩阵。 见 fz_concat,
fz_scale、fz_rotate 和 fz_translate 了解如何创建
矩阵。

point:指向更新的指针。

返回变换(不变)。

*/
fz_point fz_transform_point(fz_point point, fz_matrix m);
fz_point fz_transform_point_xy(float x, float y, fz_matrix m);

/**
Apply a transformation to a vector.

transform: Transformation matrix to apply. See fz_concat,
fz_scale and fz_rotate for how to create a matrix. Any
translation will be ignored.

vector: Pointer to vector to update.
对向量应用变换。

变换:要应用的变换矩阵。 见 fz_concat,
fz_scale 和 fz_rotate 了解如何创建矩阵。 任何
翻译将被忽略。

向量:指向要更新的向量的指针。

*/
fz_point fz_transform_vector(fz_point vector, fz_matrix m);

/**
Apply a transform to a rectangle.

After the four corner points of the axis-aligned rectangle
have been transformed it may not longer be axis-aligned. So a
new axis-aligned rectangle is created covering at least the
area of the transformed rectangle.

transform: Transformation matrix to apply. See fz_concat,
fz_scale and fz_rotate for how to create a matrix.

rect: Rectangle to be transformed. The two special cases
fz_empty_rect and fz_infinite_rect, may be used but are
returned unchanged as expected.
对矩形应用变换。

在轴对齐矩形的四个角点之后
已转换,它可能不再是轴对齐的。 所以一个
创建新的轴对齐矩形,至少覆盖
变换矩形的面积。

变换:要应用的变换矩阵。 见 fz_concat,
fz_scale 和 fz_rotate 了解如何创建矩阵。

rect:要变换的矩形。 两种特殊情况
fz_empty_rect 和 fz_infinite_rect,可以使用但是
按预期返回不变。

*/
fz_rect fz_transform_rect(fz_rect rect, fz_matrix m);

/**
Normalize a vector to length one.
*/
fz_point fz_normalize_vector(fz_point p);

/**
Grid fit a matrix.

as_tiled = 0 => adjust the matrix so that the image of the unit
square completely covers any pixel that was touched by the
image of the unit square under the original matrix.

as_tiled = 1 => adjust the matrix so that the corners of the
image of the unit square align with the closest integer corner
of the image of the unit square under the original matrix.
网格适合矩阵。

as_tiled = 0 => 调整矩阵,使单元的图像
正方形完全覆盖了被触摸的任何像素
原始矩阵下的单位正方形的图像。

as_tiled = 1 => 调整矩阵,使
单位正方形的图像与最近的整数角对齐
原始矩阵下单位正方形的图像。

*/
fz_matrix fz_gridfit_matrix(int as_tiled, fz_matrix m);

/**
Find the largest expansion performed by this matrix.
(i.e. max(abs(m.a),abs(m.b),abs(m.c),abs(m.d))
找出此矩阵执行的最大扩展。
(即 max(abs(m.a),abs(m.b),abs(m.c),abs(m.d))
*/
float fz_matrix_max_expansion(fz_matrix m);

/**
A representation for a region defined by 4 points.

The significant difference between quads and rects is that
the edges of quads are not axis aligned.
由 4 个点定义的区域的表示。

四边形和矩形之间的显着区别在于
四边形的边缘不是轴对齐的。

*/
typedef struct
{
fz_point ul, ur, ll, lr;
} fz_quad;

/**
Inline convenience construction function.
内联便利构造函数。
*/
static inline fz_quad fz_make_quad(
float ul_x, float ul_y,
float ur_x, float ur_y,
float ll_x, float ll_y,
float lr_x, float lr_y)
{
fz_quad q = {
{ ul_x, ul_y },
{ ur_x, ur_y },
{ ll_x, ll_y },
{ lr_x, lr_y },
};
return q;
}

/**
Convert a rect to a quad (losslessly).
将反应转换为四边形(无损)。
*/
fz_quad fz_quad_from_rect(fz_rect r);

/**
Convert a quad to the smallest rect that covers it.
将四边形转换为覆盖它的最小矩形。
*/
fz_rect fz_rect_from_quad(fz_quad q);

/**
Transform a quad by a matrix.
用矩阵变换四边形。
*/
fz_quad fz_transform_quad(fz_quad q, fz_matrix m);

/**
Inclusion test for quads.
四边形的包含测试。
*/
int fz_is_point_inside_quad(fz_point p, fz_quad q);

/**
Inclusion test for rects. (Rect is assumed to be open, i.e.
top right corner is not included).
rects 的包含测试。 (假设 Rect 是开放的,即不包括右上角)。
*/
int fz_is_point_inside_rect(fz_point p, fz_rect r);

/**
Inclusion test for irects. (Rect is assumed to be open, i.e.
top right corner is not included).
直肠的包含测试。 (假设 Rect 是开放的,即
不包括右上角)。
*/
int fz_is_point_inside_irect(int x, int y, fz_irect r);

/**
Inclusion test for quad in quad.

This may break down if quads are not 'well formed'.
Quad in quad 的包含测试。

如果四边形没有“良好形成”,这可能会崩溃。

*/
int fz_is_quad_inside_quad(fz_quad needle, fz_quad haystack);

/**
Intersection test for quads.

This may break down if quads are not 'well formed'.
四边形的相交测试。
如果四边形没有“良好形成”,这可能会崩溃。

*/
int fz_is_quad_intersecting_quad(fz_quad a, fz_quad b);

#endif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值