29template <
typename Po
intType>
56 return ((
x == point.
x) && (
y == point.
y));
61 return ((
x == point.
x) && (
y == point.
y));
66 return !(*
this == point);
86 return hypot(pt.
x -
x, pt.
y -
y);
93template <
typename Po
intType>
98template <
typename Po
intType>
111template <
typename Po
intType>
116 x(0),
y(0),
dX(-1),
dY(-1)
119 RectTmpl(PointType ax, PointType ay, PointType adX, PointType adY) :
120 x(ax),
y(ay),
dX(adX),
dY(adY)
142 return (
dX < (PointType)0 ||
dY < (PointType)0);
147 return ((
x == rect.
x) && (
y == rect.
y) &&
148 (
dX == rect.
dX) && (
dY == rect.
dY));
153 return ((
x == rect.
x) && (
y == rect.
y) &&
154 (
dX == rect.
dX) && (
dY == rect.
dY));
159 return !(*
this == rect);
164 return (fabs(
x - rect.
x) < epsilon &&
165 fabs(
y - rect.
y) < epsilon &&
166 fabs(
dX - rect.
dX) < epsilon &&
167 fabs(
dY - rect.
dY) < epsilon);
221 x = point.
x;
y = point.
y;
239 if (point.
x >
x +
dX)
244 if (point.
y >
y +
dY)
260 PointType llX = std::max<PointType>(
x, rect.
x);
261 PointType urX = std::min<PointType>(
x +
dX, rect.
x + rect.
dX);
262 PointType llY = std::max<PointType>(
y, rect.
y);
263 PointType urY = std::min<PointType>(
y +
dY, rect.
y + rect.
dY);
264 x = llX;
y = llY;
dX = urX -
x;
dY = urY -
y;
283 PointType llX = std::min<PointType>(
x, rect.
x);
284 PointType urX = std::max<PointType>(
x +
dX, rect.
x + rect.
dX);
285 PointType llY = std::min<PointType>(
y, rect.
y);
286 PointType urY = std::max<PointType>(
y +
dY, rect.
y + rect.
dY);
287 x = llX;
y = llY;
dX = urX -
x;
dY = urY -
y;
313 (
x +
dX) >= (rect.
x + rect.
dX) &&
314 (
y +
dY) >= (rect.
y + rect.
dY))
350template <
typename Po
intType>
357 BoxTmpl(PointType _left, PointType _bottom, PointType _right, PointType _top) :
401 PointType tmp =
left;
448template <
typename TItem>
483 set(_xx, _xy, _yx, _yy, _dx, _dy);
523 if (sourceRect.
dX > 0 && destRect.
dX > 0 && sourceRect.
dY > 0 && destRect.
dY > 0)
525 m_xx = destRect.
dX / sourceRect.
dX;
526 m_yy = destRect.
dY / sourceRect.
dY;
527 m_dx = destRect.
x - sourceRect.
x * m_xx;
528 m_dy = destRect.
y - sourceRect.
y * m_yy;
542 void set(TItem _xx = 1, TItem _xy = 0, TItem _yx = 0, TItem _yy = 1, TItem _dx = 0, TItem _dy = 0)
544 m_xx = _xx; m_xy = _xy; m_yx = _yx; m_yy = _yy; m_dx = _dx; m_dy = _dy;
551 TItem
xx()
const {
return m_xx; }
557 TItem
xy()
const {
return m_xy; }
563 TItem
yx()
const {
return m_yx; }
569 TItem
yy()
const {
return m_yy; }
575 TItem
dx()
const {
return m_dx; }
581 TItem
dy()
const {
return m_dy; }
627 return (m_xx == matrix.
xx()) &&
628 (m_xy == matrix.
xy()) &&
629 (m_yx == matrix.
yx()) &&
630 (m_yy == matrix.
yy()) &&
632 (m_dx == matrix.
dx()) &&
633 (m_dy == matrix.
dy())));
643 return (m_xx == 1.0) &&
664 if (m_xy == 0 && m_yx == 0)
668 else if (m_xx == 0 && m_yy == 0)
686 TItem a = matrix.
xx() * m_xx + matrix.
xy() * m_yx;
687 TItem b = matrix.
xx() * m_xy + matrix.
xy() * m_yy;
688 TItem c = matrix.
yx() * m_xx + matrix.
yy() * m_yx;
689 TItem d = matrix.
yx() * m_xy + matrix.
yy() * m_yy;
690 TItem e = matrix.
dx() * m_xx + matrix.
dy() * m_yx + m_dx;
691 TItem f = matrix.
dx() * m_xy + matrix.
dy() * m_yy + m_dy;
692 m_xx = a; m_xy = b; m_yx = c; m_yy = d; m_dx = e; m_dy = f;
702 TItem a = m_xx * matrix.
xx() + m_xy * matrix.
yx();
703 TItem b = m_xx * matrix.
xy() + m_xy * matrix.
yy();
704 TItem c = m_yx * matrix.
xx() + m_yy * matrix.
yx();
705 TItem d = m_yx * matrix.
xy() + m_yy * matrix.
yy();
706 TItem e = m_dx * matrix.
xx() + m_dy * matrix.
yx() + matrix.
dx();
707 TItem f = m_dx * matrix.
xy() + m_dy * matrix.
yy() + matrix.
dy();
708 m_xx = a; m_xy = b; m_yx = c; m_yy = d; m_dx = e; m_dy = f;
719 TItem det = m_xx * m_yy - m_yx * m_xy;
734 det = m_xx * m_yy - m_yx * m_xy;
741 TItem a = m_yy / det;
742 TItem b = -m_xy / det;
743 TItem c = -m_yx / det;
744 TItem d = m_xx / det;
745 TItem e = -(m_dx * m_yy - m_dy * m_yx) / det;
746 TItem f = (m_dx * m_xy - m_dy * m_xx) / det;
747 m_xx = a; m_xy = b; m_yx = c; m_yy = d; m_dx = e; m_dy = f;
760 TItem x = point.
x * m_xx + point.
y * m_yx;
761 TItem y = point.
x * m_xy + point.
y * m_yy;
781 TItem x = point.
x * m_xx + point.
y * m_yx;
782 TItem y = point.
x * m_xy + point.
y * m_yy;
803 TItem det = m_xx * m_yy - m_yx * m_xy;
809 TItem iDet = 1 / det;
819 result.
x = ((x * m_yy - y * m_yx) * iDet);
820 result.
y = ((-x * m_xy + y * m_xx) * iDet);
836 TItem det = m_xx * m_yy - m_yx * m_xy;
840 return std::pair<bool, PointTmpl<TItem> >(
false, result);
842 TItem iDet = 1 / det;
852 result.
x = ((x * m_yy - y * m_yx) * iDet);
853 result.
y = ((-x * m_xy + y * m_xx) * iDet);
855 return std::pair<bool, PointTmpl<TItem> >(
true, result);
864 constexpr double rad_90 =
PI / 2.0;
865 constexpr double rad_180 =
PI;
866 constexpr double rad_270 = 3.0 *
PI / 2.0;
867 constexpr double rad_360 = 2.0 *
PI;
868 constexpr double eps = 1.0e-6;
871 while (radians >= rad_360)
873 while (radians < 0.0)
878 if (fabs(radians) < 1.0e-6);
879 else if (fabs(radians - rad_90) < eps)
881 else if (fabs(radians - rad_180) < eps)
883 else if (fabs(radians - rad_270) < eps)
896 void scale(TItem xscale, TItem yscale)
919 return m_xx * m_yy - m_yx * m_xy;
929 TItem llX, llY, urX, urY;
934#define EDLTMIN(a, b) (a) < (b) ? (a) : (b)
935#define EDLTMAX(a, b) (a) < (b) ? (b) : (a)
940 transform(transformedPoint, point, ignoreDXDY);
941 llX = urX = transformedPoint.
x;
942 llY = urY = transformedPoint.
y;
943 point.
x = rect.
x + rect.
dX;
944 transform(transformedPoint, point, ignoreDXDY);
945 llX =
EDLTMIN(llX, transformedPoint.
x);
946 llY =
EDLTMIN(llY, transformedPoint.
y);
947 urX =
EDLTMAX(urX, transformedPoint.
x);
948 urY =
EDLTMAX(urY, transformedPoint.
y);
949 point.
y = rect.
y + rect.
dY;
950 transform(transformedPoint, point, ignoreDXDY);
951 llX =
EDLTMIN(llX, transformedPoint.
x);
952 llY =
EDLTMIN(llY, transformedPoint.
y);
953 urX =
EDLTMAX(urX, transformedPoint.
x);
954 urY =
EDLTMAX(urY, transformedPoint.
y);
956 transform(transformedPoint, point, ignoreDXDY);
957 llX =
EDLTMIN(llX, transformedPoint.
x);
958 llY =
EDLTMIN(llY, transformedPoint.
y);
959 urX =
EDLTMAX(urX, transformedPoint.
x);
960 urY =
EDLTMAX(urY, transformedPoint.
y);
963 rect.
x = llX; rect.
y = llY; rect.
dX = urX - llX; rect.
dY = urY - llY;
972 uint32 operationFlags = 0;
974 if ((m_dx != 0.0) || (m_dy != 0))
977 if ((m_xy == 0) && (m_yx == 0))
980 if ((m_xx == m_yy) && (m_xy == -m_yx)) {
983 double det = m_xx * m_yy - m_yx * m_xy;
984 double eps = 1.0e-06;
986 if (fabs(det - 1.0) > eps)
996 return operationFlags;
1032 double AdotB = a * b + c * d;
1033 double ModA = ::sqrt(a * a + c * c);
1034 double ModB = ::sqrt(b * b + d * d);
1036 double Shear = (pi / 2 - ::acos(AdotB / (ModB * ModA)));
1043 if ((b == 0) || (c == 0))
1046 rotationAngle = ::atan2(c, a);
1047 if (fabs(rotationAngle) < eps)
1048 rotationAngle = 0.0;
1052 scale.x = ((a != 0) && (a > 0)) || ((a == 0) && (c * b <= 0)) ? ModA : -ModA;
1053 scale.y = ((d != 0) && (d > 0)) || ((d == 0) && (c * b <= 0)) ? ModB : -ModB;
1056 if (fabs(Shear) < eps) {
1066 shear.
x = -tan(Shear);
1099 decompose(info.translate, info.scale, info.shear, info.rotationAngle, eps);
1115 double AxB = a * d - b * c;
1116 double ModA = ::sqrt(a * a + c * c);
1118 return ::fabs(AxB / ModA);
1128 bool isSimple = ((m_xx == m_yy) && (m_xy == 0) && (m_yx == 0));
1146 return std::pair<bool, TItem>(val,
scale);
1182 rotationAngle = atan2(point.
y, point.
x);
1185 rotate.rotate(-rotationAngle);
1193 shearAngle = (
PI / 2.0) - atan2(point.
y, point.
x);
1194 if (shearAngle < -(
PI / 2.0))
1198 else if (shearAngle > (
PI / 2.0))
1233 if (shearAngle < -(
PI / 2.0) || shearAngle >(
PI / 2.0))
1237 double shearAmount = tan(shearAngle);
1242 scale((TItem)scaleAmount.
x, (TItem)scaleAmount.
y);
1249 template <
typename AType>
1256 array[0] = (AType)m_xx;
1257 array[1] = (AType)m_xy;
1258 array[2] = (AType)m_yx;
1259 array[3] = (AType)m_yy;
1260 array[4] = (AType)m_dx;
1261 array[5] = (AType)m_dy;
1265 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:352
void scale(PointType s)
Definition edlgeom.h:421
void normalize()
Definition edlgeom.h:397
void offset(PointType x, PointType y)
Definition edlgeom.h:413
bool equal(const BoxTmpl< PointType > &other) const
Definition edlgeom.h:429
double top
Definition edlgeom.h:439
BoxTmpl(const RectTmpl< PointType > &rect)
Definition edlgeom.h:365
BoxTmpl(BoxTmpl< PointType > &&p)=default
RectTmpl< PointType > asRect() const
Definition edlgeom.h:387
BoxTmpl()
Definition edlgeom.h:354
double bottom
Definition edlgeom.h:438
BoxTmpl(PointType _left, PointType _bottom, PointType _right, PointType _top)
Definition edlgeom.h:357
BoxTmpl(const BoxTmpl< PointType > &b)
Definition edlgeom.h:361
double right
Definition edlgeom.h:440
BoxTmpl< PointType > & operator=(const BoxTmpl< PointType > &other)=default
double left
Definition edlgeom.h:437
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:90
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:64
double x
Definition edlgeom.h:89
bool operator==(const PointTmpl &point) const
Definition edlgeom.h:59
PointTmpl< PointType > & operator=(const PointTmpl< PointType > &other)=default
bool equal(const PointTmpl &point) const
Definition edlgeom.h:54
PointTmpl< PointType > getMidPoint(const PointTmpl< PointType > &pt) const
Find the mid-point between this and another point.
Definition edlgeom.h:74
PointTmpl(const PointTmpl< PointType > &p)=default
double getDistance(const PointTmpl< PointType > &pt) const
Find the distance to another point.
Definition edlgeom.h:84
PointTmpl(PointTmpl< PointType > &&p)=default
void setEmpty()
Definition edlgeom.h:134
RectTmpl(RectTmpl< PointType > &&p)=default
double dX
Definition edlgeom.h:131
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:256
double y
Definition edlgeom.h:130
RectTmpl(const RectTmpl< PointType > &r)=default
RectTmpl & offset(PointType offX, PointType offY)
Definition edlgeom.h:170
void unionRect(const RectTmpl< PointType > &rect)
Unite this rect with another rect.
Definition edlgeom.h:273
bool similar(const RectTmpl &rect, float epsilon) const
Definition edlgeom.h:162
RectTmpl< PointType > & operator=(const RectTmpl< PointType > &other)=default
bool isEmpty() const
Definition edlgeom.h:140
bool containsPoint(PointType px, PointType py) const
Definition edlgeom.h:324
PointType getBottom() const
Definition edlgeom.h:334
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:184
double dY
Definition edlgeom.h:132
PointType getRight() const
Definition edlgeom.h:329
bool operator==(const RectTmpl &rect) const
Definition edlgeom.h:151
bool equal(const RectTmpl &rect) const
Definition edlgeom.h:145
RectTmpl()
Definition edlgeom.h:115
RectTmpl(PointType ax, PointType ay, PointType adX, PointType adY)
Definition edlgeom.h:119
bool operator!=(const RectTmpl &rect) const
Definition edlgeom.h:157
bool expandToPoint(const PointTmpl< PointType > &point)
Expand this rect if necessary to include point.
Definition edlgeom.h:216
bool intersectsWithRect(const RectTmpl< PointType > &rect) const
Does this rect intersect with another rect?
Definition edlgeom.h:297
double x
Definition edlgeom.h:129
bool containsRect(const RectTmpl< PointType > &rect) const
Does this rectangle completely contain the given rect?
Definition edlgeom.h:305
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:99
PointTmpl< double > FPoint
Definition edlgeom.h:104
CTransformMatrix< double > FMatrix
Definition edlgeom.h:1268
BoxTmpl< double > FBox
Definition edlgeom.h:443
RectTmpl< double > FRect
Definition edlgeom.h:340
RectTmpl< int64 > Int64Rect
Definition edlgeom.h:342
RectTmpl< int32 > IntRect
Definition edlgeom.h:341
const PointTmpl< PointType > operator+(const PointTmpl< PointType > &lhp, const PointTmpl< PointType > &rhp)
Definition edlgeom.h:94
BoxTmpl< int32 > IntBox
Definition edlgeom.h:444
CEDLVector< FPoint > CFPointVect
Definition edlgeom.h:108
PointTmpl< int32 > IntPoint
Definition edlgeom.h:105
PointTmpl< uint32 > UIntPoint
Definition edlgeom.h:106
PointTmpl< int64 > Int64Point
Definition edlgeom.h:107
BoxTmpl< int64 > Int64Box
Definition edlgeom.h:445
(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:456
@ eIsComplex
Definition edlgeom.h:460
@ eDoesScale
Definition edlgeom.h:458
@ eDoesTranslate
Definition edlgeom.h:457
@ eDoesRotate
Definition edlgeom.h:459