29template <
typename Po
intType>
63 return ((
x == point.
x) && (
y == point.
y));
68 return ((
x == point.
x) && (
y == point.
y));
73 return !(*
this == point);
93 return hypot(pt.
x -
x, pt.
y -
y);
100template <
typename Po
intType>
105template <
typename Po
intType>
118template <
typename Po
intType>
123 x(0),
y(0),
dX(-1),
dY(-1)
126 RectTmpl(PointType ax, PointType ay, PointType adX, PointType adY) :
127 x(ax),
y(ay),
dX(adX),
dY(adY)
149 return (
dX < (PointType)0 ||
dY < (PointType)0);
154 return ((
x == rect.
x) && (
y == rect.
y) &&
155 (
dX == rect.
dX) && (
dY == rect.
dY));
160 return ((
x == rect.
x) && (
y == rect.
y) &&
161 (
dX == rect.
dX) && (
dY == rect.
dY));
166 return !(*
this == rect);
171 return (fabs(
x - rect.
x) < epsilon &&
172 fabs(
y - rect.
y) < epsilon &&
173 fabs(
dX - rect.
dX) < epsilon &&
174 fabs(
dY - rect.
dY) < epsilon);
228 x = point.
x;
y = point.
y;
246 if (point.
x >
x +
dX)
251 if (point.
y >
y +
dY)
267 PointType llX = std::max<PointType>(
x, rect.
x);
268 PointType urX = std::min<PointType>(
x +
dX, rect.
x + rect.
dX);
269 PointType llY = std::max<PointType>(
y, rect.
y);
270 PointType urY = std::min<PointType>(
y +
dY, rect.
y + rect.
dY);
271 x = llX;
y = llY;
dX = urX -
x;
dY = urY -
y;
290 PointType llX = std::min<PointType>(
x, rect.
x);
291 PointType urX = std::max<PointType>(
x +
dX, rect.
x + rect.
dX);
292 PointType llY = std::min<PointType>(
y, rect.
y);
293 PointType urY = std::max<PointType>(
y +
dY, rect.
y + rect.
dY);
294 x = llX;
y = llY;
dX = urX -
x;
dY = urY -
y;
320 (
x +
dX) >= (rect.
x + rect.
dX) &&
321 (
y +
dY) >= (rect.
y + rect.
dY))
357template <
typename Po
intType>
364 BoxTmpl(PointType _left, PointType _bottom, PointType _right, PointType _top) :
408 PointType tmp =
left;
455template <
typename TItem>
490 set(_xx, _xy, _yx, _yy, _dx, _dy);
533 if (sourceRect.
dX > 0 && destRect.
dX > 0 && sourceRect.
dY > 0 && destRect.
dY > 0)
535 m_xx = destRect.
dX / sourceRect.
dX;
536 m_yy = destRect.
dY / sourceRect.
dY;
537 m_dx = destRect.
x - sourceRect.
x * m_xx;
538 m_dy = destRect.
y - sourceRect.
y * m_yy;
540 else if (allowZeroWidthRect &&
541 sourceRect.
dX > 0 && destRect.
dX > 0 && sourceRect.
dY == 0 && destRect.
dY == 0)
543 m_xx = destRect.
dX / sourceRect.
dX;
545 m_dx = destRect.
x - sourceRect.
x * m_xx;
546 m_dy = destRect.
y - sourceRect.
y * m_yy;
548 else if (allowZeroWidthRect &&
549 sourceRect.
dX == 0 && destRect.
dX == 0 && sourceRect.
dY > 0 && destRect.
dY > 0)
552 m_yy = destRect.
dY / sourceRect.
dY;
553 m_dx = destRect.
x - sourceRect.
x * m_xx;
554 m_dy = destRect.
y - sourceRect.
y * m_yy;
568 void set(TItem _xx = 1, TItem _xy = 0, TItem _yx = 0, TItem _yy = 1, TItem _dx = 0, TItem _dy = 0)
570 m_xx = _xx; m_xy = _xy; m_yx = _yx; m_yy = _yy; m_dx = _dx; m_dy = _dy;
577 TItem
xx()
const {
return m_xx; }
583 TItem
xy()
const {
return m_xy; }
589 TItem
yx()
const {
return m_yx; }
595 TItem
yy()
const {
return m_yy; }
601 TItem
dx()
const {
return m_dx; }
607 TItem
dy()
const {
return m_dy; }
653 return (m_xx == matrix.
xx()) &&
654 (m_xy == matrix.
xy()) &&
655 (m_yx == matrix.
yx()) &&
656 (m_yy == matrix.
yy()) &&
658 (m_dx == matrix.
dx()) &&
659 (m_dy == matrix.
dy())));
669 return (m_xx == 1.0) &&
690 if (m_xy == 0 && m_yx == 0)
694 else if (m_xx == 0 && m_yy == 0)
712 TItem a = matrix.
xx() * m_xx + matrix.
xy() * m_yx;
713 TItem b = matrix.
xx() * m_xy + matrix.
xy() * m_yy;
714 TItem c = matrix.
yx() * m_xx + matrix.
yy() * m_yx;
715 TItem d = matrix.
yx() * m_xy + matrix.
yy() * m_yy;
716 TItem e = matrix.
dx() * m_xx + matrix.
dy() * m_yx + m_dx;
717 TItem f = matrix.
dx() * m_xy + matrix.
dy() * m_yy + m_dy;
718 m_xx = a; m_xy = b; m_yx = c; m_yy = d; m_dx = e; m_dy = f;
728 TItem a = m_xx * matrix.
xx() + m_xy * matrix.
yx();
729 TItem b = m_xx * matrix.
xy() + m_xy * matrix.
yy();
730 TItem c = m_yx * matrix.
xx() + m_yy * matrix.
yx();
731 TItem d = m_yx * matrix.
xy() + m_yy * matrix.
yy();
732 TItem e = m_dx * matrix.
xx() + m_dy * matrix.
yx() + matrix.
dx();
733 TItem f = m_dx * matrix.
xy() + m_dy * matrix.
yy() + matrix.
dy();
734 m_xx = a; m_xy = b; m_yx = c; m_yy = d; m_dx = e; m_dy = f;
745 TItem det = m_xx * m_yy - m_yx * m_xy;
760 det = m_xx * m_yy - m_yx * m_xy;
767 TItem a = m_yy / det;
768 TItem b = -m_xy / det;
769 TItem c = -m_yx / det;
770 TItem d = m_xx / det;
771 TItem e = -(m_dx * m_yy - m_dy * m_yx) / det;
772 TItem f = (m_dx * m_xy - m_dy * m_xx) / det;
773 m_xx = a; m_xy = b; m_yx = c; m_yy = d; m_dx = e; m_dy = f;
786 TItem x = point.
x * m_xx + point.
y * m_yx;
787 TItem y = point.
x * m_xy + point.
y * m_yy;
807 TItem x = point.
x * m_xx + point.
y * m_yx;
808 TItem y = point.
x * m_xy + point.
y * m_yy;
829 TItem det = m_xx * m_yy - m_yx * m_xy;
835 TItem iDet = 1 / det;
845 result.
x = ((x * m_yy - y * m_yx) * iDet);
846 result.
y = ((-x * m_xy + y * m_xx) * iDet);
862 TItem det = m_xx * m_yy - m_yx * m_xy;
866 return std::pair<bool, PointTmpl<TItem> >(
false, result);
868 TItem iDet = 1 / det;
878 result.
x = ((x * m_yy - y * m_yx) * iDet);
879 result.
y = ((-x * m_xy + y * m_xx) * iDet);
881 return std::pair<bool, PointTmpl<TItem> >(
true, result);
890 constexpr double rad_90 =
PI / 2.0;
891 constexpr double rad_180 =
PI;
892 constexpr double rad_270 = 3.0 *
PI / 2.0;
893 constexpr double rad_360 = 2.0 *
PI;
894 constexpr double eps = 1.0e-6;
897 while (radians >= rad_360)
899 while (radians < 0.0)
904 if (fabs(radians) < 1.0e-6);
905 else if (fabs(radians - rad_90) < eps)
907 else if (fabs(radians - rad_180) < eps)
909 else if (fabs(radians - rad_270) < eps)
922 void scale(TItem xscale, TItem yscale)
945 return m_xx * m_yy - m_yx * m_xy;
955 TItem llX, llY, urX, urY;
960#define EDLTMIN(a, b) (a) < (b) ? (a) : (b)
961#define EDLTMAX(a, b) (a) < (b) ? (b) : (a)
966 transform(transformedPoint, point, ignoreDXDY);
967 llX = urX = transformedPoint.
x;
968 llY = urY = transformedPoint.
y;
969 point.
x = rect.
x + rect.
dX;
970 transform(transformedPoint, point, ignoreDXDY);
971 llX =
EDLTMIN(llX, transformedPoint.
x);
972 llY =
EDLTMIN(llY, transformedPoint.
y);
973 urX =
EDLTMAX(urX, transformedPoint.
x);
974 urY =
EDLTMAX(urY, transformedPoint.
y);
975 point.
y = rect.
y + rect.
dY;
976 transform(transformedPoint, point, ignoreDXDY);
977 llX =
EDLTMIN(llX, transformedPoint.
x);
978 llY =
EDLTMIN(llY, transformedPoint.
y);
979 urX =
EDLTMAX(urX, transformedPoint.
x);
980 urY =
EDLTMAX(urY, transformedPoint.
y);
982 transform(transformedPoint, point, ignoreDXDY);
983 llX =
EDLTMIN(llX, transformedPoint.
x);
984 llY =
EDLTMIN(llY, transformedPoint.
y);
985 urX =
EDLTMAX(urX, transformedPoint.
x);
986 urY =
EDLTMAX(urY, transformedPoint.
y);
989 rect.
x = llX; rect.
y = llY; rect.
dX = urX - llX; rect.
dY = urY - llY;
998 uint32 operationFlags = 0;
1000 if ((m_dx != 0.0) || (m_dy != 0))
1003 if ((m_xy == 0) && (m_yx == 0))
1006 if ((m_xx == m_yy) && (m_xy == -m_yx)) {
1009 double det = m_xx * m_yy - m_yx * m_xy;
1010 double eps = 1.0e-06;
1012 if (fabs(det - 1.0) > eps)
1022 return operationFlags;
1058 double AdotB = a * b + c * d;
1059 double ModA = ::sqrt(a * a + c * c);
1060 double ModB = ::sqrt(b * b + d * d);
1062 double Shear = (pi / 2 - ::acos(AdotB / (ModB * ModA)));
1069 if ((b == 0) || (c == 0))
1072 rotationAngle = ::atan2(c, a);
1073 if (fabs(rotationAngle) < eps)
1074 rotationAngle = 0.0;
1078 scale.x = ((a != 0) && (a > 0)) || ((a == 0) && (c * b <= 0)) ? ModA : -ModA;
1079 scale.y = ((d != 0) && (d > 0)) || ((d == 0) && (c * b <= 0)) ? ModB : -ModB;
1082 if (fabs(Shear) < eps) {
1092 shear.
x = -tan(Shear);
1125 decompose(info.translate, info.scale, info.shear, info.rotationAngle, eps);
1141 double AxB = a * d - b * c;
1142 double ModA = ::sqrt(a * a + c * c);
1144 return ::fabs(AxB / ModA);
1154 bool isSimple = ((m_xx == m_yy) && (m_xy == 0) && (m_yx == 0));
1172 return std::pair<bool, TItem>(val,
scale);
1208 rotationAngle = atan2(point.
y, point.
x);
1211 rotate.rotate(-rotationAngle);
1219 shearAngle = (
PI / 2.0) - atan2(point.
y, point.
x);
1220 if (shearAngle < -(
PI / 2.0))
1224 else if (shearAngle > (
PI / 2.0))
1259 if (shearAngle < -(
PI / 2.0) || shearAngle >(
PI / 2.0))
1263 double shearAmount = tan(shearAngle);
1268 scale((TItem)scaleAmount.
x, (TItem)scaleAmount.
y);
1275 template <
typename AType>
1282 array[0] = (AType)m_xx;
1283 array[1] = (AType)m_xy;
1284 array[2] = (AType)m_yx;
1285 array[3] = (AType)m_yy;
1286 array[4] = (AType)m_dx;
1287 array[5] = (AType)m_dy;
1291 TItem m_xx, m_xy, m_yx, m_yy, m_dx, m_dy;
Template for a PDF-style box. Similar to a rectangle but specified using a left, bottom,...
Definition edlgeom.h:359
void scale(PointType s)
Definition edlgeom.h:428
void normalize()
Definition edlgeom.h:404
void offset(PointType x, PointType y)
Definition edlgeom.h:420
bool equal(const BoxTmpl< PointType > &other) const
Definition edlgeom.h:436
double top
Definition edlgeom.h:446
BoxTmpl(const RectTmpl< PointType > &rect)
Definition edlgeom.h:372
BoxTmpl(BoxTmpl< PointType > &&p)=default
RectTmpl< PointType > asRect() const
Definition edlgeom.h:394
BoxTmpl()
Definition edlgeom.h:361
double bottom
Definition edlgeom.h:445
BoxTmpl(PointType _left, PointType _bottom, PointType _right, PointType _top)
Definition edlgeom.h:364
BoxTmpl(const BoxTmpl< PointType > &b)
Definition edlgeom.h:368
double right
Definition edlgeom.h:447
BoxTmpl< PointType > & operator=(const BoxTmpl< PointType > &other)=default
double left
Definition edlgeom.h:444
Definition edlvector.h:30
Geometry primitives including: point, rectangle and matrix types supporting both integer and floating...
Definition edlgeom.h:31
double y
Definition edlgeom.h:97
PointTmpl< PointType > & operator-=(const PointTmpl< PointType > &pt)
Definition edlgeom.h:54
PointTmpl< PointType > & operator+=(const PointTmpl< PointType > &pt)
Definition edlgeom.h:47
PointTmpl(PointType ax, PointType ay)
Definition edlgeom.h:37
PointTmpl()
Definition edlgeom.h:33
bool operator!=(const PointTmpl &point) const
Definition edlgeom.h:71
double x
Definition edlgeom.h:96
bool operator==(const PointTmpl &point) const
Definition edlgeom.h:66
PointTmpl< PointType > & operator=(const PointTmpl< PointType > &other)=default
bool equal(const PointTmpl &point) const
Definition edlgeom.h:61
PointTmpl< PointType > getMidPoint(const PointTmpl< PointType > &pt) const
Find the mid-point between this and another point.
Definition edlgeom.h:81
PointTmpl(const PointTmpl< PointType > &p)=default
double getDistance(const PointTmpl< PointType > &pt) const
Find the distance to another point.
Definition edlgeom.h:91
PointTmpl(PointTmpl< PointType > &&p)=default
void setEmpty()
Definition edlgeom.h:141
RectTmpl(RectTmpl< PointType > &&p)=default
double dX
Definition edlgeom.h:138
void intersectRect(const RectTmpl< PointType > &rect)
Intersect this rect with another rect. If the rects do not intersect, the result is an empty rect.
Definition edlgeom.h:263
double y
Definition edlgeom.h:137
RectTmpl(const RectTmpl< PointType > &r)=default
RectTmpl & offset(PointType offX, PointType offY)
Definition edlgeom.h:177
void unionRect(const RectTmpl< PointType > &rect)
Unite this rect with another rect.
Definition edlgeom.h:280
bool similar(const RectTmpl &rect, float epsilon) const
Definition edlgeom.h:169
RectTmpl< PointType > & operator=(const RectTmpl< PointType > &other)=default
bool isEmpty() const
Definition edlgeom.h:147
bool containsPoint(PointType px, PointType py) const
Definition edlgeom.h:331
PointType getBottom() const
Definition edlgeom.h:341
RectTmpl & inset(PointType insetX, PointType insetY)
Inset a rectangle by the given values. Will collapse to a point if the rectangle is not enough to ser...
Definition edlgeom.h:191
double dY
Definition edlgeom.h:139
PointType getRight() const
Definition edlgeom.h:336
bool operator==(const RectTmpl &rect) const
Definition edlgeom.h:158
bool equal(const RectTmpl &rect) const
Definition edlgeom.h:152
RectTmpl()
Definition edlgeom.h:122
RectTmpl(PointType ax, PointType ay, PointType adX, PointType adY)
Definition edlgeom.h:126
bool operator!=(const RectTmpl &rect) const
Definition edlgeom.h:164
bool expandToPoint(const PointTmpl< PointType > &point)
Expand this rect if necessary to include point.
Definition edlgeom.h:223
bool intersectsWithRect(const RectTmpl< PointType > &rect) const
Does this rect intersect with another rect?
Definition edlgeom.h:304
double x
Definition edlgeom.h:136
bool containsRect(const RectTmpl< PointType > &rect) const
Does this rectangle completely contain the given rect?
Definition edlgeom.h:312
EDL_API void throwEDLError(uint32 errorcode)
Utility - Throw an IEDLError exception with the given error code.
const PointTmpl< PointType > operator-(const PointTmpl< PointType > &lhp, const PointTmpl< PointType > &rhp)
Definition edlgeom.h:106
PointTmpl< double > FPoint
Definition edlgeom.h:111
CTransformMatrix< double > FMatrix
Definition edlgeom.h:1294
BoxTmpl< double > FBox
Definition edlgeom.h:450
RectTmpl< double > FRect
Definition edlgeom.h:347
RectTmpl< int64 > Int64Rect
Definition edlgeom.h:349
RectTmpl< int32 > IntRect
Definition edlgeom.h:348
const PointTmpl< PointType > operator+(const PointTmpl< PointType > &lhp, const PointTmpl< PointType > &rhp)
Definition edlgeom.h:101
BoxTmpl< int32 > IntBox
Definition edlgeom.h:451
CEDLVector< FPoint > CFPointVect
Definition edlgeom.h:115
PointTmpl< int32 > IntPoint
Definition edlgeom.h:112
PointTmpl< uint32 > UIntPoint
Definition edlgeom.h:113
PointTmpl< int64 > Int64Point
Definition edlgeom.h:114
BoxTmpl< int64 > Int64Box
Definition edlgeom.h:452
(very thin) portability layer around operating system provided math functionality but also includes a...
#define PI
Local definition of PI to 20 decimal places.
Definition edlmath.h:25
#define _BEGIN_EDL_NAMESPACE
Definition edlnamespaces.h:75
#define _END_EDL_NAMESPACE
Definition edlnamespaces.h:76
EDL "standard" types including known bit-length signed and unsigned integer type[def]s and definition...
unsigned int uint32
Definition edltypes.h:34
Simple template vector class for general use.
@ EDL_ERR_BAD_ARGUMENTS
General error for bad arguments passed to an API function.
Definition edlerrors.h:44
eOperationTypes
Classification of operation type flags of the transform.
Definition edlgeom.h:463
@ eIsComplex
Definition edlgeom.h:467
@ eDoesScale
Definition edlgeom.h:465
@ eDoesTranslate
Definition edlgeom.h:464
@ eDoesRotate
Definition edlgeom.h:466