27template <
typename Po
intType>
54 return ((
x == point.
x) && (
y == point.
y));
59 return ((
x == point.
x) && (
y == point.
y));
64 return !(*
this == point);
84 return hypot(pt.
x -
x, pt.
y -
y);
91template <
typename Po
intType>
96template <
typename Po
intType>
109template <
typename Po
intType>
114 x(0),
y(0),
dX(-1),
dY(-1)
117 RectTmpl(PointType ax, PointType ay, PointType adX, PointType adY) :
118 x(ax),
y(ay),
dX(adX),
dY(adY)
140 return (
dX < (PointType)0 ||
dY < (PointType)0);
145 return ((
x == rect.
x) && (
y == rect.
y) &&
146 (
dX == rect.
dX) && (
dY == rect.
dY));
151 return ((
x == rect.
x) && (
y == rect.
y) &&
152 (
dX == rect.
dX) && (
dY == rect.
dY));
157 return !(*
this == rect);
162 return (fabs(
x - rect.
x) < epsilon &&
163 fabs(
y - rect.
y) < epsilon &&
164 fabs(
dX - rect.
dX) < epsilon &&
165 fabs(
dY - rect.
dY) < epsilon);
219 x = point.
x;
y = point.
y;
237 if (point.
x >
x +
dX)
242 if (point.
y >
y +
dY)
258 PointType llX = std::max<PointType>(
x, rect.
x);
259 PointType urX = std::min<PointType>(
x +
dX, rect.
x + rect.
dX);
260 PointType llY = std::max<PointType>(
y, rect.
y);
261 PointType urY = std::min<PointType>(
y +
dY, rect.
y + rect.
dY);
262 x = llX;
y = llY;
dX = urX -
x;
dY = urY -
y;
281 PointType llX = std::min<PointType>(
x, rect.
x);
282 PointType urX = std::max<PointType>(
x +
dX, rect.
x + rect.
dX);
283 PointType llY = std::min<PointType>(
y, rect.
y);
284 PointType urY = std::max<PointType>(
y +
dY, rect.
y + rect.
dY);
285 x = llX;
y = llY;
dX = urX -
x;
dY = urY -
y;
311 (
x +
dX) >= (rect.
x + rect.
dX) &&
312 (
y +
dY) >= (rect.
y + rect.
dY))
348template <
typename Po
intType>
355 BoxTmpl(PointType _left, PointType _bottom, PointType _right, PointType _top) :
399 PointType tmp =
left;
446template <
typename TItem>
480 set(_xx, _xy, _yx, _yy, _dx, _dy);;
520 if (sourceRect.
dX > 0 && destRect.
dX > 0 && sourceRect.
dY > 0 && destRect.
dY > 0)
522 m_xx = destRect.
dX / sourceRect.
dX;
523 m_yy = destRect.
dY / sourceRect.
dY;
524 m_dx = destRect.
x - sourceRect.
x * m_xx;
525 m_dy = destRect.
y - sourceRect.
y * m_yy;
539 void set(TItem _xx = 1, TItem _xy = 0, TItem _yx = 0, TItem _yy = 1, TItem _dx = 0, TItem _dy = 0)
541 m_xx = _xx; m_xy = _xy; m_yx = _yx; m_yy = _yy; m_dx = _dx; m_dy = _dy;
548 TItem
xx()
const {
return m_xx; }
554 TItem
xy()
const {
return m_xy; }
560 TItem
yx()
const {
return m_yx; }
566 TItem
yy()
const {
return m_yy; }
572 TItem
dx()
const {
return m_dx; }
578 TItem
dy()
const {
return m_dy; }
624 return (m_xx == matrix.
xx()) &&
625 (m_xy == matrix.
xy()) &&
626 (m_yx == matrix.
yx()) &&
627 (m_yy == matrix.
yy()) &&
629 (m_dx == matrix.
dx()) &&
630 (m_dy == matrix.
dy())));
640 return (m_xx == 1.0) &&
655 TItem a = matrix.
xx() * m_xx + matrix.
xy() * m_yx;
656 TItem b = matrix.
xx() * m_xy + matrix.
xy() * m_yy;
657 TItem c = matrix.
yx() * m_xx + matrix.
yy() * m_yx;
658 TItem d = matrix.
yx() * m_xy + matrix.
yy() * m_yy;
659 TItem e = matrix.
dx() * m_xx + matrix.
dy() * m_yx + m_dx;
660 TItem f = matrix.
dx() * m_xy + matrix.
dy() * m_yy + m_dy;
661 m_xx = a; m_xy = b; m_yx = c; m_yy = d; m_dx = e; m_dy = f;
671 TItem a = m_xx * matrix.
xx() + m_xy * matrix.
yx();
672 TItem b = m_xx * matrix.
xy() + m_xy * matrix.
yy();
673 TItem c = m_yx * matrix.
xx() + m_yy * matrix.
yx();
674 TItem d = m_yx * matrix.
xy() + m_yy * matrix.
yy();
675 TItem e = m_dx * matrix.
xx() + m_dy * matrix.
yx() + matrix.
dx();
676 TItem f = m_dx * matrix.
xy() + m_dy * matrix.
yy() + matrix.
dy();
677 m_xx = a; m_xy = b; m_yx = c; m_yy = d; m_dx = e; m_dy = f;
687 TItem det = m_xx * m_yy - m_yx * m_xy;
701 det = m_xx * m_yy - m_yx * m_xy;
708 TItem a = m_yy / det;
709 TItem b = -m_xy / det;
710 TItem c = -m_yx / det;
711 TItem d = m_xx / det;
712 TItem e = -(m_dx * m_yy - m_dy * m_yx) / det;
713 TItem f = (m_dx * m_xy - m_dy * m_xx) / det;
714 m_xx = a; m_xy = b; m_yx = c; m_yy = d; m_dx = e; m_dy = f;
727 TItem x = point.
x * m_xx + point.
y * m_yx;
728 TItem y = point.
x * m_xy + point.
y * m_yy;
748 TItem x = point.
x * m_xx + point.
y * m_yx;
749 TItem y = point.
x * m_xy + point.
y * m_yy;
770 TItem det = m_xx * m_yy - m_yx * m_xy;
776 TItem iDet = 1 / det;
786 result.
x = ((x * m_yy - y * m_yx) * iDet);
787 result.
y = ((-x * m_xy + y * m_xx) * iDet);
802 TItem det = m_xx * m_yy - m_yx * m_xy;
806 return std::pair<bool, PointTmpl<TItem> >(
false, result);
808 TItem iDet = 1 / det;
818 result.
x = ((x * m_yy - y * m_yx) * iDet);
819 result.
y = ((-x * m_xy + y * m_xx) * iDet);
821 return std::pair<bool, PointTmpl<TItem> >(
true, result);
830 constexpr double rad_90 =
PI / 2.0;
831 constexpr double rad_180 =
PI;
832 constexpr double rad_270 = 3.0 *
PI / 2.0;
833 constexpr double rad_360 = 2.0 *
PI;
834 constexpr double eps = 1.0e-6;
837 while (radians >= rad_360)
839 while (radians < 0.0)
844 if (fabs(radians) < 1.0e-6);
845 else if (fabs(radians - rad_90) < eps)
847 else if (fabs(radians - rad_180) < eps)
849 else if (fabs(radians - rad_270) < eps)
862 void scale(TItem xscale, TItem yscale)
885 return m_xx * m_yy - m_yx * m_xy;
896 TItem llX, llY, urX, urY;
901#define EDLTMIN(a, b) (a) < (b) ? (a) : (b)
902#define EDLTMAX(a, b) (a) < (b) ? (b) : (a)
907 transform(transformedPoint, point, ignoreDXDY);
908 llX = urX = transformedPoint.
x;
909 llY = urY = transformedPoint.
y;
910 point.
x = rect.
x + rect.
dX;
911 transform(transformedPoint, point, ignoreDXDY);
912 llX =
EDLTMIN(llX, transformedPoint.
x);
913 llY =
EDLTMIN(llY, transformedPoint.
y);
914 urX =
EDLTMAX(urX, transformedPoint.
x);
915 urY =
EDLTMAX(urY, transformedPoint.
y);
916 point.
y = rect.
y + rect.
dY;
917 transform(transformedPoint, point, ignoreDXDY);
918 llX =
EDLTMIN(llX, transformedPoint.
x);
919 llY =
EDLTMIN(llY, transformedPoint.
y);
920 urX =
EDLTMAX(urX, transformedPoint.
x);
921 urY =
EDLTMAX(urY, transformedPoint.
y);
923 transform(transformedPoint, point, ignoreDXDY);
924 llX =
EDLTMIN(llX, transformedPoint.
x);
925 llY =
EDLTMIN(llY, transformedPoint.
y);
926 urX =
EDLTMAX(urX, transformedPoint.
x);
927 urY =
EDLTMAX(urY, transformedPoint.
y);
930 rect.
x = llX; rect.
y = llY; rect.
dX = urX - llX; rect.
dY = urY - llY;
939 uint32 operationFlags = 0;
941 if ((m_dx != 0.0) || (m_dy != 0))
944 if ((m_xy == 0) && (m_yx == 0))
947 if ((m_xx == m_yy) && (m_xy == -m_yx)) {
950 double det = m_xx * m_yy - m_yx * m_xy;
951 double eps = 1.0e-06;
953 if (fabs(det - 1.0) > eps)
963 return operationFlags;
992 double AdotB = a * b + c * d;
993 double ModA = ::sqrt(a * a + c * c);
994 double ModB = ::sqrt(b * b + d * d);
996 double Shear = (pi / 2 - ::acos(AdotB / (ModB * ModA)));
1003 if ((b == 0) || (c == 0))
1006 rotationAngle = ::atan2(c, a);
1007 if (fabs(rotationAngle) < eps)
1008 rotationAngle = 0.0;
1012 scale.x = ((a != 0) && (a > 0)) || ((a == 0) && (c * b <= 0)) ? ModA : -ModA;
1013 scale.y = ((d != 0) && (d > 0)) || ((d == 0) && (c * b <= 0)) ? ModB : -ModB;
1016 if (fabs(Shear) < eps) {
1026 shear.
x = -tan(Shear);
1052 decompose(info.translate, info.scale, info.shear, info.rotationAngle, eps);
1064 double AxB = a * d - b * c;
1065 double ModA = ::sqrt(a * a + c * c);
1067 return ::fabs(AxB / ModA);
1072 bool isSimple = ((m_xx == m_yy) && (m_xy == 0) && (m_yx == 0));
1086 return std::pair<bool, TItem>(val,
scale);
1122 rotationAngle = atan2(point.
y, point.
x);
1125 rotate.rotate(-rotationAngle);
1133 shearAngle = (
PI / 2.0) - atan2(point.
y, point.
x);
1134 if (shearAngle < -(
PI / 2.0))
1138 else if (shearAngle > (
PI / 2.0))
1173 if (shearAngle < -(
PI / 2.0) || shearAngle >(
PI / 2.0))
1177 double shearAmount = tan(shearAngle);
1182 scale((TItem)scaleAmount.
x, (TItem)scaleAmount.
y);
1189 template <
typename AType>
1196 array[0] = (AType)m_xx;
1197 array[1] = (AType)m_xy;
1198 array[2] = (AType)m_yx;
1199 array[3] = (AType)m_yy;
1200 array[4] = (AType)m_dx;
1201 array[5] = (AType)m_dy;
1205 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:350
void scale(PointType s)
Definition edlgeom.h:419
void normalize()
Definition edlgeom.h:395
void offset(PointType x, PointType y)
Definition edlgeom.h:411
bool equal(const BoxTmpl< PointType > &other) const
Definition edlgeom.h:427
double top
Definition edlgeom.h:437
BoxTmpl(const RectTmpl< PointType > &rect)
Definition edlgeom.h:363
BoxTmpl(BoxTmpl< PointType > &&p)=default
RectTmpl< PointType > asRect()
Definition edlgeom.h:385
BoxTmpl()
Definition edlgeom.h:352
double bottom
Definition edlgeom.h:436
BoxTmpl(PointType _left, PointType _bottom, PointType _right, PointType _top)
Definition edlgeom.h:355
BoxTmpl(const BoxTmpl< PointType > &b)
Definition edlgeom.h:359
double right
Definition edlgeom.h:438
BoxTmpl< PointType > & operator=(const BoxTmpl< PointType > &other)=default
double left
Definition edlgeom.h:435
Definition edlvector.h:30
Geometry primitives including: point, rectangle and matrix types supporting both integer and floating...
Definition edlgeom.h:29
double y
Definition edlgeom.h:88
PointTmpl< PointType > & operator+=(const PointTmpl< PointType > &pt)
Definition edlgeom.h:45
PointTmpl(PointType ax, PointType ay)
Definition edlgeom.h:35
PointTmpl()
Definition edlgeom.h:31
bool operator!=(const PointTmpl &point) const
Definition edlgeom.h:62
double x
Definition edlgeom.h:87
bool operator==(const PointTmpl &point) const
Definition edlgeom.h:57
PointTmpl< PointType > & operator=(const PointTmpl< PointType > &other)=default
bool equal(const PointTmpl &point) const
Definition edlgeom.h:52
PointTmpl< PointType > getMidPoint(const PointTmpl< PointType > &pt) const
Find the mid-point between this and another point.
Definition edlgeom.h:72
PointTmpl(const PointTmpl< PointType > &p)=default
double getDistance(const PointTmpl< PointType > &pt) const
Find the distance to another point.
Definition edlgeom.h:82
PointTmpl(PointTmpl< PointType > &&p)=default
void setEmpty()
Definition edlgeom.h:132
RectTmpl(RectTmpl< PointType > &&p)=default
double dX
Definition edlgeom.h:129
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:254
double y
Definition edlgeom.h:128
RectTmpl(const RectTmpl< PointType > &r)=default
RectTmpl & offset(PointType offX, PointType offY)
Definition edlgeom.h:168
void unionRect(const RectTmpl< PointType > &rect)
Unite this rect with another rect.
Definition edlgeom.h:271
bool similar(const RectTmpl &rect, float epsilon) const
Definition edlgeom.h:160
RectTmpl< PointType > & operator=(const RectTmpl< PointType > &other)=default
bool isEmpty() const
Definition edlgeom.h:138
bool containsPoint(PointType px, PointType py) const
Definition edlgeom.h:322
PointType getBottom() const
Definition edlgeom.h:332
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:182
double dY
Definition edlgeom.h:130
PointType getRight() const
Definition edlgeom.h:327
bool operator==(const RectTmpl &rect) const
Definition edlgeom.h:149
bool equal(const RectTmpl &rect) const
Definition edlgeom.h:143
RectTmpl()
Definition edlgeom.h:113
RectTmpl(PointType ax, PointType ay, PointType adX, PointType adY)
Definition edlgeom.h:117
bool operator!=(const RectTmpl &rect) const
Definition edlgeom.h:155
bool expandToPoint(const PointTmpl< PointType > &point)
Expand this rect if necessary to include point.
Definition edlgeom.h:214
bool intersectsWithRect(const RectTmpl< PointType > &rect) const
Does this rect intersect with another rect?
Definition edlgeom.h:295
double x
Definition edlgeom.h:127
bool containsRect(const RectTmpl< PointType > &rect) const
Does this rectangle completely contain the given rect?
Definition edlgeom.h:303
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:97
PointTmpl< double > FPoint
Definition edlgeom.h:102
CTransformMatrix< double > FMatrix
Definition edlgeom.h:1208
BoxTmpl< double > FBox
Definition edlgeom.h:441
RectTmpl< double > FRect
Definition edlgeom.h:338
RectTmpl< int64 > Int64Rect
Definition edlgeom.h:340
RectTmpl< int32 > IntRect
Definition edlgeom.h:339
const PointTmpl< PointType > operator+(const PointTmpl< PointType > &lhp, const PointTmpl< PointType > &rhp)
Definition edlgeom.h:92
BoxTmpl< int32 > IntBox
Definition edlgeom.h:442
CEDLVector< FPoint > CFPointVect
Definition edlgeom.h:106
PointTmpl< int32 > IntPoint
Definition edlgeom.h:103
PointTmpl< uint32 > UIntPoint
Definition edlgeom.h:104
PointTmpl< int64 > Int64Point
Definition edlgeom.h:105
BoxTmpl< int64 > Int64Box
Definition edlgeom.h:443
(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:42
eOperationTypes
Classification of operation type flags of the transform.
Definition edlgeom.h:454
@ eIsComplex
Definition edlgeom.h:458
@ eDoesScale
Definition edlgeom.h:456
@ eDoesTranslate
Definition edlgeom.h:455
@ eDoesRotate
Definition edlgeom.h:457