1 #ifndef SDK_GEOMETRY_BASE_TYPES_H_
10 #define SDK_GEOMETRY_BASE_TYPES_H_
14 #include <base/inc/float_util.h>
21 #pragma push_macro("min")
22 #pragma push_macro("max")
37 #if defined(__cplusplus)
39 typedef float coordinate_type;
40 enum DimensionCount_ { dimension_count = 2 };
42 static coordinate_type bad_coordinate() {
43 return IEEE754_2008::flt_NaN();
50 coordinate_type get()
const {
55 if (1 /
int(K < dimension_count)) {
68 void set(coordinate_type
const v) {
69 if (1 /
int(K < dimension_count)) {
78 friend coordinate_type get(
const MyType& p) {
83 friend void set(
const MyType& p, coordinate_type
const v) {
87 double Length(
const MyType& p)
const noexcept {
88 return Length(p.x, p.y);
91 double Length(
double x2,
double y2)
const noexcept {
94 return sqrt(x2*x2 + y2*y2);
106 #if defined(__cplusplus)
108 typedef float coordinate_type;
109 enum DimensionCount_ { dimension_count = 3 };
111 static coordinate_type bad_coordinate() {
112 return IEEE754_2008::flt_NaN();
119 coordinate_type get()
const {
120 if (1 /
int(K < dimension_count)) {
135 void set(coordinate_type
const v) {
136 if (1 /
int(K < dimension_count)) {
147 friend coordinate_type get(
const MyType& p) {
152 friend void set(
const MyType& p, coordinate_type
const v) {
156 double Length(
const MyType& p)
const noexcept {
157 return Length(p.x, p.y, p.z);
160 double Length(
double x2,
double y2,
double z2)
const noexcept {
161 x2 -= x; y2 -= y; z2 -= z;
163 return sqrt(x2*x2 + y2*y2 + z2*z2);
182 #if defined(__cplusplus)
184 typedef SDKInt32 coordinate_type;
185 enum DimensionCount_ { dimension_count = 2 };
187 static coordinate_type bad_coordinate() {
195 coordinate_type get()
const {
196 if (1 /
int(K < dimension_count)) {
209 void set(coordinate_type
const v) {
210 if (1 /
int(K < dimension_count)) {
219 friend coordinate_type get(
const MyType& p) {
224 friend void set(
const MyType& p, coordinate_type
const v) {
228 double Length(
const MyType& p)
const noexcept {
229 return Length(p.x, p.y);
232 double Length(
double x2,
double y2)
const noexcept {
235 return sqrt(x2*x2 + y2*y2);
246 #if defined(__cplusplus)
248 typedef double coordinate_type;
249 enum DimensionCount_ { dimension_count = 2 };
251 static coordinate_type bad_coordinate() {
252 return IEEE754_2008::dbl_NaN();
259 coordinate_type get()
const {
260 if (1 /
int(K < dimension_count)) {
273 void set(coordinate_type
const v) {
274 if (1 /
int(K < dimension_count)) {
283 friend coordinate_type get(
const MyType& p) {
288 friend void set(
const MyType& p, coordinate_type
const v) {
292 double Length(
const MyType& p)
const noexcept {
293 return Length(p.x, p.y);
296 double Length(
double x2,
double y2)
const noexcept {
299 return sqrt(x2*x2 + y2*y2);
311 #if defined(__cplusplus)
313 typedef double coordinate_type;
314 enum DimensionCount_ { dimension_count = 3 };
316 static coordinate_type bad_coordinate() {
317 return IEEE754_2008::dbl_NaN();
324 coordinate_type get()
const {
325 if (1 /
int(K < dimension_count)) {
340 void set(coordinate_type
const v) {
341 if (1 /
int(K < dimension_count)) {
352 friend coordinate_type get(
const MyType& p) {
357 friend void set(
const MyType& p, coordinate_type
const v) {
361 double Length(
const MyType& p)
const noexcept {
362 return Length(p.x, p.y, p.z);
365 double Length(
double x2,
double y2,
double z2)
const noexcept {
366 x2 -= x; y2 -= y; z2 -= z;
368 return sqrt(x2*x2 + y2*y2 + z2*z2);
392 #if defined(__cplusplus)
397 : xmin(0), ymin(0), xmax(0), ymax(0) {
401 point_type
const& _min_corner,
402 point_type
const& _max_corner) noexcept
403 : xmin(_min_corner.x), ymin(_min_corner.y), xmax(_max_corner.x),
404 ymax(_max_corner.y) {
408 point_type::coordinate_type _xmin,
409 point_type::coordinate_type _ymin,
410 point_type::coordinate_type _xmax,
411 point_type::coordinate_type _ymax) noexcept
412 : xmin(_xmin), ymin(_ymin), xmax(_xmax), ymax(_ymax) {
416 bool IsEmpty()
const noexcept {
417 return xmin == 0 && ymin == 0 &&
418 xmax == 0 && ymax == 0;
423 point_type
const& corner()
const noexcept {
424 if (!(1 /
int(C < 2)))
433 point_type& corner() noexcept {
434 if (!(1 /
int(C < 2)))
442 point_type
const& min_corner()
const noexcept {
445 point_type& min_corner() noexcept {
448 point_type
const& max_corner()
const noexcept {
451 point_type& max_corner() noexcept {
476 #if defined(__cplusplus)
481 : xmin(0), ymin(0), xmax(0), ymax(0) {
485 point_type
const& _min_corner,
486 point_type
const& _max_corner) noexcept
487 : xmin(_min_corner.x), ymin(_min_corner.y), xmax(_max_corner.x),
488 ymax(_max_corner.y) {
492 point_type::coordinate_type _xmin,
493 point_type::coordinate_type _ymin,
494 point_type::coordinate_type _xmax,
495 point_type::coordinate_type _ymax) noexcept
496 : xmin(_xmin), ymin(_ymin), xmax(_xmax), ymax(_ymax) {
500 bool IsEmpty()
const noexcept {
501 return xmin == 0 && ymin == 0 &&
502 xmax == 0 && ymax == 0;
507 point_type
const& corner()
const noexcept {
508 if (!(1 /
int(C < 2)))
517 point_type& corner() noexcept {
518 if (!(1 /
int(C < 2)))
526 point_type
const& min_corner()
const noexcept {
529 point_type& min_corner() noexcept {
532 point_type
const& max_corner()
const noexcept {
535 point_type& max_corner() noexcept {
562 #if defined(__cplusplus)
567 : xmin(0), ymin(0), zmin(0), xmax(0), ymax(0), zmax(0) {
571 point_type
const& _min_corner,
572 point_type
const& _max_corner) noexcept
573 : xmin(_min_corner.x), ymin(_min_corner.y), zmin(_min_corner.z),
574 xmax(_max_corner.x), ymax(_max_corner.y), zmax(_max_corner.z) {
578 point_type::coordinate_type _xmin,
579 point_type::coordinate_type _ymin,
580 point_type::coordinate_type _zmin,
581 point_type::coordinate_type _xmax,
582 point_type::coordinate_type _ymax,
583 point_type::coordinate_type _zmax) noexcept
584 : xmin(_xmin), ymin(_ymin), zmin(_zmin), xmax(_xmax), ymax(_ymax),
589 bool IsEmpty()
const noexcept {
590 return xmin == 0 && ymin == 0 &&
591 xmax == 0 && ymax == 0 &&
592 zmin == 0 && zmax == 0;
605 point_type
const& corner()
const noexcept {
606 if (!(1 /
int(C < 2)))
615 point_type& corner() noexcept {
616 if (!(1 /
int(C < 2)))
624 point_type
const& min_corner()
const noexcept {
627 point_type& min_corner() noexcept {
630 point_type
const& max_corner()
const noexcept {
633 point_type& max_corner() noexcept {
658 #if defined(__cplusplus)
661 bool IsEmpty()
const noexcept {
662 return xmin == 0 && ymin == 0
663 && xmax == 0 && ymax == 0;
668 point_type
const& corner()
const noexcept {
669 if (!(1 /
int(C < 2)))
678 point_type& corner() noexcept {
679 if (!(1 /
int(C < 2)))
687 point_type
const& min_corner()
const noexcept {
690 point_type& min_corner() noexcept {
693 point_type
const& max_corner()
const noexcept {
696 point_type& max_corner() noexcept {
723 #if defined(__cplusplus)
726 bool IsEmpty()
const noexcept {
727 return xmin == 0 && ymin == 0
728 && xmax == 0 && ymax == 0
729 && zmin == 0 && zmax == 0;
734 point_type
const& corner()
const noexcept {
735 if (!(1 /
int(C < 2)))
745 point_type& corner() noexcept {
746 if (!(1 /
int(C < 2)))
755 point_type
const& min_corner()
const noexcept {
758 point_type& min_corner() noexcept {
761 point_type
const& max_corner()
const noexcept {
764 point_type& max_corner() noexcept {
770 #if defined(__cplusplus) && 0
774 struct GenGeometryPointTag {};
775 struct GenGeometryBoxTag {};
776 struct GenGeometryXYWHRectTag {};
778 template <
typename Geometry>
779 struct GenGeometryTag {
782 template <
typename Geometry>
783 struct GenGeometryPointType {
784 typedef typename Geometry::point_type type;
787 template <
typename Po
int,
size_t D = 0>
788 struct GenGeometryCoordinateType {
789 typedef typename Point::coordinate_type type;
792 template <
typename Po
int>
793 struct GenGeometryDimension {
794 enum _Dimension { value = Point::dimension_count };
797 template <
typename Point,
size_t D,
798 bool IsActualDimension = (D < size_t(GenGeometryDimension<Point>::value)) >
799 struct GenGeometryPointAccess;
801 template <
typename Po
int,
size_t D>
802 struct GenGeometryPointAccess<Point,D,true> {
803 typedef typename GenGeometryCoordinateType<Point,D>::type coordinate_type;
804 static void set(Point& p, coordinate_type v) {
805 return p.template set<D>(v);
807 static coordinate_type get(
const Point& p) {
808 return p.template get<D>();
812 template <
class Po
int,
size_t D>
813 struct GenGeometryPointAccess<Point,D,false> {
814 typedef typename Point::coordinate_type coordinate_type;
816 template <
typename IgnoreIt>
817 static void set(Point&,
const IgnoreIt&) {
819 static coordinate_type get(
const Point&) {
820 return Point::bad_coordinate();
824 template <
class XYWHRect,
size_t I,
typename Enable=
void>
827 template <
class XYWHRect,
typename Enable>
828 class CornerType<XYWHRect,0,Enable> {
830 typedef CornerType<XYWHRect,0,Enable> MyType;
831 typedef XYWHRect Rect;
832 typedef typename GenGeometryPointType<Rect>::type point_type;
833 typedef const point_type const_point_type;
834 typedef typename GenGeometryCoordinateType<point_type>::type coordinate_type;
837 CornerType(
const Rect& rect) noexcept
838 : m_rect(
const_cast<Rect&
>(rect)) {
843 typename GenGeometryCoordinateType<point_type,D>::type get() const noexcept {
850 void set(
typename GenGeometryCoordinateType<point_type,D>::type v)
const noexcept {
856 template <
class Po
int>
857 const MyType& operator=(
const Point& pnt)
const {
858 m_rect.x = GenGeometryPointAccess<point_type,0>::get(pnt);
859 m_rect.y = GenGeometryPointAccess<point_type,1>::get(pnt);
862 operator const_point_type()
const {
864 GenGeometryPointAccess<point_type,0>::set(pnt, m_rect.x);
865 GenGeometryPointAccess<point_type,1>::set(pnt, m_rect.y);
870 template <
class XYWHRect,
typename Enable>
871 class CornerType<XYWHRect,1,Enable> {
873 typedef CornerType<XYWHRect,1,Enable> MyType;
874 typedef XYWHRect Rect;
875 typedef typename GenGeometryPointType<Rect>::type point_type;
876 typedef const point_type const_point_type;
877 typedef typename GenGeometryCoordinateType<point_type>::type coordinate_type;
880 CornerType(
const Rect& rect) noexcept
881 : m_rect(
const_cast<Rect&
>(rect)) {
886 typename GenGeometryCoordinateType<point_type,D>::type get() const noexcept {
888 return m_rect.x + m_rect.width;
890 return m_rect.y + m_rect.height;
893 void set(
typename GenGeometryCoordinateType<point_type,D>::type v)
const noexcept {
895 m_rect.width = v - m_rect.x;
897 m_rect.height = v - m_rect.y;
899 template <
class Po
int>
900 const MyType& operator=(
const Point& pnt)
const {
901 m_rect.width = GenGeometryPointAccess<point_type,0>::get(pnt) - m_rect.x;
902 m_rect.height = GenGeometryPointAccess<point_type,1>::get(pnt) - m_rect.y;
905 operator const_point_type()
const {
907 GenGeometryPointAccess<point_type,0>::set(pnt, m_rect.x + m_rect.width);
908 GenGeometryPointAccess<point_type,1>::set(pnt, m_rect.y + m_rect.height);
913 template <
class Box,
size_t I,
size_t D,
914 class GenGeometryBoxTag =
typename geometry::GenGeometryTag<Box>::type,
915 bool IsActualIndex = (I < 2)>
916 struct GenGeometryIndexedAccess;
918 template <
class Box,
size_t I,
size_t D>
919 struct GenGeometryIndexedAccess<Box,I,D,geometry::GenGeometryBoxTag,true> {
920 typedef typename GenGeometryPointType<Box>::type point_type;
921 typedef typename GenGeometryCoordinateType<point_type,D>::type coordinate_type;
923 static void set(Box& box, coordinate_type v) {
924 return GenGeometryPointAccess<point_type,D>::set(box.template corner<I>(), v);
926 static coordinate_type get(
const Box& box) {
927 return GenGeometryPointAccess<point_type,D>::get(box.template corner<I>());
932 struct GenGeometryIndexedAccess<Box,0,0,geometry::GenGeometryXYWHRectTag,true> {
933 typedef typename GenGeometryPointType<Box>::type point_type;
934 typedef typename GenGeometryCoordinateType<point_type,0>::type coordinate_type;
935 static void set(Box& box, coordinate_type v) { box.x = v; }
936 static coordinate_type get(
const Box& box) {
return box.x; }
940 struct GenGeometryIndexedAccess<Box,0,1,geometry::GenGeometryXYWHRectTag,true> {
941 typedef typename GenGeometryPointType<Box>::type point_type;
942 typedef typename GenGeometryCoordinateType<point_type,1>::type coordinate_type;
943 static void set(Box& box, coordinate_type v) { box.y = v; }
944 static coordinate_type get(
const Box& box) {
return box.y; }
948 struct GenGeometryIndexedAccess<Box,1,0,geometry::GenGeometryXYWHRectTag,true> {
949 typedef typename GenGeometryPointType<Box>::type point_type;
950 typedef typename GenGeometryCoordinateType<point_type,0>::type coordinate_type;
951 static void set(Box& box, coordinate_type v) { box.width = v - box.x; }
952 static coordinate_type get(
const Box& box) {
return box.x + box.width; }
956 struct GenGeometryIndexedAccess<Box,1,1,geometry::GenGeometryXYWHRectTag,true> {
957 typedef typename GenGeometryPointType<Box>::type point_type;
958 typedef typename GenGeometryCoordinateType<point_type,1>::type coordinate_type;
959 static void set(Box& box, coordinate_type v) { box.height = v - box.y; }
960 static coordinate_type get(
const Box& box) {
return box.y + box.height; }
963 template <
class Box,
size_t I,
size_t D,
class GenGeometryBoxTag>
964 struct GenGeometryIndexedAccess<Box,I,D,GenGeometryBoxTag,false> {
965 typedef typename GenGeometryPointType<Box>::type point_type;
966 typedef typename GenGeometryCoordinateType<point_type,D>::type coordinate_type;
968 static void set(Box& box, coordinate_type v) {
970 static coordinate_type get(
const Box& box) {
971 return point_type::bad_coordinate();
975 template <
typename _PODEnvelope>
976 struct EnvelopeT :
public _PODEnvelope {
978 typedef _PODEnvelope MyBase;
979 typedef EnvelopeT<_PODEnvelope> MyType;
982 typedef typename GenGeometryPointType<MyBase>::type point_type;
983 typedef typename GenGeometryCoordinateType<point_type>::type coordinate_type;
984 enum Dimension_ { dimension_count = GenGeometryDimension<point_type>::value };
992 explicit EnvelopeT(
const MyBase& _rhs) noexcept
996 MyType& operator=(
const MyBase& _rhs) noexcept {
997 static_cast<MyBase&
>(*this) = _rhs;
1001 template <
size_t I,
size_t D>
1002 void set(coordinate_type v) {
1003 return geometry::GenGeometryIndexedAccess<_PODEnvelope,I,D>::set(*
this,v);
1006 template <
size_t I,
size_t D>
1007 coordinate_type get()
const {
1008 return geometry::GenGeometryIndexedAccess<_PODEnvelope,I,D>::get(*
this);
1011 template <
size_t I,
size_t D,
typename _E>
1012 void _assign(
const EnvelopeT<_E>& _rhs) {
1013 return this->set<I,D>(coordinate_type(_rhs.template get<I,D>()));
1017 void assign(
const EnvelopeT<_E>& _rhs) {
1027 explicit EnvelopeT(
const EnvelopeT<_E>& _rhs) noexcept
1033 MyType& operator=(
const EnvelopeT<_E>& _rhs) noexcept {
1039 explicit EnvelopeT(
const _E& _rhs) noexcept
1041 assign(
static_cast<const EnvelopeT<_E>&
>(_rhs));
1045 MyType& operator=(
const _E& _rhs) noexcept {
1046 assign(
static_cast<const EnvelopeT<_E>&
>(_rhs));
1051 point_type
const& _min_corner,
1052 point_type
const& _max_corner) noexcept {
1053 this->
template corner<0>() = _min_corner;
1054 this->
template corner<1>() = _max_corner;
1058 coordinate_type _xmin,
1059 coordinate_type _ymin,
1060 coordinate_type _xmax,
1061 coordinate_type _ymax) noexcept
1070 coordinate_type _xmin,
1071 coordinate_type _ymin,
1072 coordinate_type _zmin,
1073 coordinate_type _xmax,
1074 coordinate_type _ymax,
1075 coordinate_type _zmax) noexcept
1088 typedef geometry::EnvelopeT<SDKEnvelopeF2D> EnvelopeF2D;
1089 typedef geometry::EnvelopeT<SDKEnvelopeF3D> EnvelopeF3D;
1090 typedef geometry::EnvelopeT<SDKEnvelopeD2D> EnvelopeD2D;
1091 typedef geometry::EnvelopeT<SDKEnvelopeD3D> EnvelopeD3D;
1092 typedef geometry::EnvelopeT<SDKEnvelopeI2D> EnvelopeI2D;
1096 typedef SDK_NAMESPACE::EnvelopeF2D SDKEnvelope2DF;
1097 typedef SDK_NAMESPACE::EnvelopeD2D SDKEnvelope2D;
1098 typedef SDK_NAMESPACE::EnvelopeI2D SDKEnvelope2DI;
1099 typedef SDK_NAMESPACE::EnvelopeF3D SDKEnvelope3DF;
1100 typedef SDK_NAMESPACE::EnvelopeD3D SDKEnvelope3D;
1115 #if defined(__cplusplus)
1117 typedef float coordinate_type;
1118 enum DimensionCount_ { dimension_count = 2 };
1124 coordinate_type get()
const {
1125 if (1 /
int(K < dimension_count)) {
1129 return this->height;
1138 void set(coordinate_type
const v) {
1139 if (1 /
int(K < dimension_count)) {
1148 friend coordinate_type get(
const MyType& p) {
1153 friend void set(
const MyType& p, coordinate_type
const v) {
1158 bool IsNull()
const noexcept {
1159 return width == 0 && height == 0;
1163 bool IsEqual(
const MyType& s)
const noexcept {
1165 fabsf(width - s.width) <= FLT_EPSILON &&
1166 fabsf(height - s.height) <= FLT_EPSILON;
1177 #if defined(__cplusplus)
1179 typedef double coordinate_type;
1180 enum DimensionCount_ { dimension_count = 2 };
1186 coordinate_type get()
const {
1187 if (1 /
int(K < dimension_count)) {
1191 return this->height;
1200 void set(coordinate_type
const v) {
1201 if (1 /
int(K < dimension_count)) {
1210 friend coordinate_type get(
const MyType& p) {
1215 friend void set(
const MyType& p, coordinate_type
const v) {
1220 bool IsNull()
const noexcept {
1221 return width == 0 && height == 0;
1225 bool IsEqual(
const MyType& s)
const noexcept {
1227 fabs(width - s.width) <= DBL_EPSILON &&
1228 fabs(height - s.height) <= DBL_EPSILON;
1239 #if defined(__cplusplus)
1241 typedef SDKUInt32 coordinate_type;
1242 enum DimensionCount_ { dimension_count = 2 };
1248 coordinate_type get()
const {
1249 if (1 /
int(K < dimension_count)) {
1253 return this->height;
1262 void set(coordinate_type
const v) {
1263 if (1 /
int(K < dimension_count)) {
1272 friend coordinate_type get(
const MyType& p) {
1277 friend void set(
const MyType& p, coordinate_type
const v) {
1282 bool IsNull()
const noexcept {
1283 return width == 0 && height == 0;
1287 bool IsEqual(
const MyType& s)
const noexcept {
1288 return width == s.width && height == s.height;
1301 #if defined(__cplusplus)
1306 typedef sdk::geometry::CornerType<MyType,0> min_corner_type;
1307 typedef sdk::geometry::CornerType<MyType,1> max_corner_type;
1310 const sdk::geometry::CornerType<MyType,I> corner()
const noexcept {
1311 return sdk::geometry::CornerType<MyType,I>(*
this);
1314 const min_corner_type min_corner()
const noexcept {
1315 return min_corner_type(*
this);
1318 const max_corner_type max_corner()
const noexcept {
1319 return max_corner_type(*
this);
1322 point_type min_corner()
const noexcept {
1323 point_type ret = {x, y};
1326 point_type max_corner()
const noexcept {
1327 point_type ret = {x + width, y + height};
1333 bool IsEmpty()
const noexcept {
1334 return width == 0 && height == 0;
1338 bool IsNull()
const noexcept {
1339 return x == 0 && y == 0 && width == 0 && height == 0;
1343 bool IsEqual(
const MyType& r)
const noexcept {
1344 return x == r.x && y == r.y && width == r.width && height == r.height;
1347 const point_type Center()
const noexcept {
1348 point_type ret = {x + width / 2, y + height / 2};
1362 #if defined(__cplusplus)
1367 typedef sdk::geometry::CornerType<MyType,0> min_corner_type;
1368 typedef sdk::geometry::CornerType<MyType,1> max_corner_type;
1371 const sdk::geometry::CornerType<MyType,I> corner()
const noexcept {
1372 return sdk::geometry::CornerType<MyType,I>(*
this);
1375 const min_corner_type min_corner()
const noexcept {
1376 return min_corner_type(*
this);
1379 const max_corner_type max_corner()
const noexcept {
1380 return max_corner_type(*
this);
1383 point_type min_corner()
const noexcept {
1384 point_type ret = {x, y};
1387 point_type max_corner()
const noexcept {
1388 point_type ret = {x + width, y + height};
1394 bool IsEmpty()
const noexcept {
1395 return width == 0 && height == 0;
1399 bool IsNull()
const noexcept {
1400 return x == 0 && y == 0 && width == 0 && height == 0;
1404 bool IsEqual(
const MyType& r)
const noexcept {
1405 return x == r.x && y == r.y && width == r.width && height == r.height;
1408 const point_type Center()
const noexcept {
1409 point_type ret = {x + width / 2, y + height / 2};
1423 #if defined(__cplusplus)
1428 typedef sdk::geometry::CornerType<MyType,0> min_corner_type;
1429 typedef sdk::geometry::CornerType<MyType,1> max_corner_type;
1432 const sdk::geometry::CornerType<MyType,I> corner()
const noexcept {
1433 return sdk::geometry::CornerType<MyType,I>(*
this);
1436 const min_corner_type min_corner()
const noexcept {
1437 return min_corner_type(*
this);
1440 const max_corner_type max_corner()
const noexcept {
1441 return max_corner_type(*
this);
1444 point_type min_corner()
const noexcept {
1445 point_type ret = {x, y};
1448 point_type max_corner()
const noexcept {
1449 point_type ret = {
static_cast<SDKInt32
>(x + width),
1450 static_cast<SDKInt32
>(y + height)};
1456 bool IsEmpty()
const noexcept {
1457 return width == 0 && height == 0;
1461 bool IsNull()
const noexcept {
1462 return x == 0 && y == 0 && width == 0 && height == 0;
1466 bool IsEqual(
const MyType& r)
const noexcept {
1467 return x == r.x && y == r.y && width == r.width && height == r.height;
1470 const point_type Center()
const noexcept {
1471 point_type ret = {SDKInt32(x + width / 2), SDKInt32(y + height / 2)};
1511 typedef SDKInt32 GeoInt;
1512 typedef SDKUInt32 SDKGeoIntDistance;
1513 typedef SDKUInt32 GeoIntDistance;
1567 enum DimensionCount_ { dimension_count = 2 };
1569 static coordinate_type bad_coordinate() {
1577 coordinate_type get()
const {
1578 if (1 /
int(K < dimension_count)) {
1591 void set(coordinate_type
const v) {
1592 if (1 /
int(K < dimension_count)) {
1600 bool IsValid()
const {
1601 return (x != bad_coordinate() && y != bad_coordinate()) ? true :
false;
1622 enum DimensionCount_ { dimension_count = 3 };
1629 _RetType(
const void *p) : m_p(p) {}
1632 operator const coordinate_type&()
const {
1633 return *(
const coordinate_type*)m_p;
1635 operator const double&()
const {
1636 return *(
const double*)m_p;
1640 _RetType get()
const {
1641 if (1 /
int(K < 3)) {
1643 return _RetType(&this->x);
1645 return _RetType(&this->y);
1647 return _RetType(&this->z);
1649 return _RetType(NULL);
1656 void set(coordinate_type
const v) {
1657 if (1 /
int(K < 2)) {
1665 void set(
double const v) {
1666 if (1 /
int(K == 2))
1689 point_type
const& corner()
const noexcept {
1690 if (!(1 /
int(C < 2)))
1700 point_type& corner() noexcept {
1701 if (!(1 /
int(C < 2)))
1710 point_type
const& min_corner()
const noexcept {
1713 point_type& min_corner() noexcept {
1716 point_type
const& max_corner()
const noexcept {
1719 point_type& max_corner() noexcept {
1738 typedef double coordinate_type;
1739 enum DimensionCount_ { dimension_count = 2 };
1741 static coordinate_type bad_coordinate() {
1742 return IEEE754_2008::dbl_NaN();
1749 coordinate_type get()
const {
1750 if (1 /
int(K < dimension_count)) {
1763 void set(coordinate_type
const v) {
1764 if (1 /
int(K < dimension_count)) {
1772 bool IsValid()
const {
1775 if (IEEE754_2008::is_NaN(x) || IEEE754_2008::is_NaN(y))
1783 bool IsEqual(
const SDKGeoPoint& pt)
const noexcept {
1784 if (IsValid() != pt.IsValid())
1789 if (fabs(x - pt.x) >= 90.0/0x40000000)
1791 if (fabs(y - pt.y) >= 90.0/0x40000000)
1816 point_type
const& corner()
const noexcept {
1817 if (!(1 /
int(C < 2)))
1826 point_type& corner() noexcept {
1827 if (!(1 /
int(C < 2)))
1835 point_type
const& min_corner()
const noexcept {
1838 point_type& min_corner() noexcept {
1841 point_type
const& max_corner()
const noexcept {
1844 point_type& max_corner() noexcept {
1864 typedef double coordinate_type;
1865 enum DimensionCount_ { dimension_count = 3 };
1867 static coordinate_type bad_coordinate() {
1868 return IEEE754_2008::dbl_NaN();
1875 coordinate_type get()
const {
1876 if (1 /
int(K < dimension_count)) {
1891 void set(coordinate_type
const v) {
1892 if (1 /
int(K < dimension_count)) {
1908 return lhs.x == rhs.x && lhs.y == rhs.y;
1912 return !(lhs == rhs);
1917 fabsf(lhs.x - rhs.x) < FLT_EPSILON &&
1918 fabsf(lhs.y - rhs.y) < FLT_EPSILON;
1922 return !(lhs == rhs);
1927 fabsf(lhs.x - rhs.x) < FLT_EPSILON &&
1928 fabsf(lhs.y - rhs.y) < FLT_EPSILON &&
1929 fabsf(lhs.z - rhs.z) < FLT_EPSILON;
1936 return lhs.x == rhs.x && lhs.y == rhs.y;
1940 return !(lhs == rhs);
1948 return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z;
1952 return !(lhs == rhs);
1956 return lhs.x == rhs.x && lhs.y == rhs.y;
1960 return !(lhs == rhs);
1964 return lhs.IsEqual(rhs);
1968 return !(lhs == rhs);
1973 fabs(lhs.x - rhs.x) < 90.0/0x40000000 &&
1974 fabs(lhs.y - rhs.y) < 90.0/0x40000000 &&
1975 fabs(lhs.z - rhs.z) < FLT_EPSILON;
1979 return !(lhs == rhs);
1984 return lhs.x == rhs.x && lhs.y == rhs.y && fabs(lhs.z - rhs.z) < FLT_EPSILON;
1989 return !(lhs == rhs);
1993 return (lhs.min) == (rhs.min) && (lhs.max) == (rhs.max);
1997 return !(lhs == rhs);
2001 return (lhs.min) == (rhs.min) && (lhs.max) == (rhs.max);
2005 return !(lhs == rhs);
2009 return (lhs.min) == (rhs.min) && (lhs.max) == (rhs.max);
2013 return !(lhs == rhs);
2017 return (lhs.min) == (rhs.min) && (lhs.max) == (rhs.max);
2021 return !(lhs == rhs);
2025 return lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width &&
2026 lhs.height == rhs.height;
2030 return !(lhs == rhs);
2034 return lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width &&
2035 lhs.height == rhs.height;
2039 return !(lhs == rhs);
2043 return lhs.x == rhs.x && lhs.y == rhs.y &&
2044 lhs.width == rhs.width && lhs.height == rhs.height;
2048 return !(lhs == rhs);
2052 return lhs.IsEqual(rhs);
2056 return !(lhs == rhs);
2060 return lhs.IsEqual(rhs);
2064 return !(lhs == rhs);
2068 return lhs.IsEqual(rhs);
2072 return !(lhs == rhs);
2077 return ((p1.x == p2.x) && (p1.y == p2.y));
2080 inline bool IsValidGeoPoint(
const SDKGeoPoint& p) {
2085 inline bool IsValidLat(
double lat) {
2089 inline bool IsValidLon(
double lon) {
2093 inline void NormalizeLat(
double& lat) {
2102 namespace geometry {
2105 struct GenGeometryTag<
SDKPointI2D> {
typedef GenGeometryPointTag type; };
2107 struct GenGeometryTag<
SDKPointF2D> {
typedef GenGeometryPointTag type; };
2109 struct GenGeometryTag<
SDKPointF3D> {
typedef GenGeometryPointTag type; };
2111 struct GenGeometryTag<
SDKPointD2D> {
typedef GenGeometryPointTag type; };
2113 struct GenGeometryTag<
SDKPointD3D> {
typedef GenGeometryPointTag type; };
2115 struct GenGeometryTag<
SDKGeoIntPoint> {
typedef GenGeometryPointTag type; };
2117 struct GenGeometryTag<
SDKGeoPoint> {
typedef GenGeometryPointTag type; };
2119 struct GenGeometryTag<
SDKGeoPoint3D> {
typedef GenGeometryPointTag type; };
2121 struct GenGeometryTag<
SDKGeoIntPoint3D> {
typedef GenGeometryPointTag type; };
2123 struct GenGeometryTag<
SDKEnvelopeF2D> {
typedef GenGeometryBoxTag type; };
2125 struct GenGeometryTag<
SDKEnvelopeF3D> {
typedef GenGeometryBoxTag type; };
2127 struct GenGeometryTag<
SDKEnvelopeD2D> {
typedef GenGeometryBoxTag type; };
2129 struct GenGeometryTag<
SDKEnvelopeD3D> {
typedef GenGeometryBoxTag type; };
2131 struct GenGeometryTag<
SDKRectF2D> {
typedef GenGeometryXYWHRectTag type; };
2133 struct GenGeometryTag<
SDKRectD2D> {
typedef GenGeometryXYWHRectTag type; };
2140 typedef double coordinate_type;
2168 typename x1_type,
typename y1_type,
2169 typename x0_type,
typename y0_type>
2170 static inline int quadrantNum(
2171 const x1_type x1,
const y1_type y1,
2172 const x0_type x0=x0_type(),
const y0_type y0=y0_type())
2177 | (1 << 0) | (1 << 3) | (4 << 6)
2178 | (1 << 9) | (0 << 12) | (3 << 15)
2179 | (2 << 18) | (3 << 21) | (3 << 24)
2181 return ((codes >> 3 * (3 * ((y0 < y1) - (y1 < y0) + 1) + ((x0 < x1) - (x1 < x0) + 1))) & 7) - 1;
2215 typename wnd_x_type,
typename wnd_y_type,
2216 typename pnt_x_type,
typename pnt_y_type>
2217 static int getOctantCodeAndIndex(
2218 const wnd_x_type x1,
2219 const wnd_y_type y1,
2220 const wnd_x_type x2,
2221 const wnd_y_type y2,
2234 c |= (0 << kOC_Ishf);
2240 c |= (2 << kOC_Ishf);
2244 c |= (1 << kOC_Ishf);
2255 c |= (6 << kOC_Ishf);
2261 c |= (4 << kOC_Ishf);
2265 c |= (5 << kOC_Ishf);
2274 c |= (7 << kOC_Ishf);
2280 c |= (3 << kOC_Ishf);
2284 c = (-1 << kOC_Ishf);
2295 #endif // __cplusplus
2297 #pragma pop_macro("min")
2298 #pragma pop_macro("max")
2299 #endif // SDK_GEOMETRY_BASE_TYPES_H_