32 QPointF top_right_point)
50 QPointF(top_left_point.x(), std::numeric_limits<double>::max()));
54 QPointF(top_right_point.x(), std::numeric_limits<double>::max()));
58 QPointF(top_right_point.x(), std::numeric_limits<double>::min()));
62 QPointF(top_left_point.x(), std::numeric_limits<double>::min()));
71 QPointF top_right_point,
72 QPointF bottom_right_point,
73 QPointF bottom_left_point)
82 m_points.push_back(bottom_right_point);
83 m_points.push_back(bottom_left_point);
95 "The template selection polygon must have four points, no less, no more");
121 m_points[
static_cast<int>(point_spec)].setX(
x);
122 m_points[
static_cast<int>(point_spec)].setY(
y);
131 setPoint(point_spec, point.x(), point.y());
141 QPointF src_point =
getPoint(point_spec_src);
142 setPoint(point_spec_dest, src_point);
163 QPointF(x_range_start, std::numeric_limits<double>::max()));
167 QPointF(x_range_end, std::numeric_limits<double>::max()));
171 QPointF(x_range_end, std::numeric_limits<double>::min()));
175 QPointF(x_range_start, std::numeric_limits<double>::min()));
186 QPointF bottom_right,
234 QPointF temp_point(std::numeric_limits<double>::max(), 0);
254 QPointF temp_point(std::numeric_limits<double>::min(), 0);
274 QPointF temp_point(0, std::numeric_limits<double>::min());
294 QPointF temp_point(0, std::numeric_limits<double>::max());
308const std::vector<QPointF> &
318 return m_points[
static_cast<int>(point_spec)];
328 m_minX = std::numeric_limits<double>::max();
329 m_minY = std::numeric_limits<double>::max();
330 m_maxX = std::numeric_limits<double>::min();
331 m_maxY = std::numeric_limits<double>::min();
355 min_x = std::numeric_limits<double>::max();
356 min_y = std::numeric_limits<double>::max();
357 max_x = std::numeric_limits<double>::min();
358 max_y = std::numeric_limits<double>::min();
362 min_x = std::min(
m_points.at(iter).x(), min_x);
363 max_x = std::max(
m_points.at(iter).x(), max_x);
365 min_y = std::min(
m_points.at(iter).y(), min_y);
366 max_y = std::max(
m_points.at(iter).y(), max_y);
387 return max_x - min_x;
402 return max_y - min_y;
409 double min_y = std::numeric_limits<double>::max();
410 double max_y = std::numeric_limits<double>::min();
419 double min_x = std::numeric_limits<double>::max();
420 double max_x = std::numeric_limits<double>::min();
430 return rangeX(range_start, range_end);
432 return rangeY(range_start, range_end);
459 qFatal(
"The polygon must have four points, no less, no more");
484 return selection_polygon;
494 if(tested_point.x() <
m_minX || tested_point.x() >
m_maxX ||
515 double x = tested_point.x();
516 double y = tested_point.y();
547 bool is_inside =
false;
551 for(i = 0, j = vertex_count - 1; i < vertex_count; j = i++)
553 if(((
m_points.at(i).y() > tested_point.y()) !=
554 (
m_points.at(j).y() > tested_point.y())) &&
556 (tested_point.y() -
m_points.at(i).y()) /
559 is_inside = !is_inside;
579 bool is_inside =
true;
598 qFatal(
"Programming error.");
601 qFatal(
"Programming error.");
622 m_points[0] = QPointF(std::numeric_limits<double>::min(),
623 std::numeric_limits<double>::max());
624 m_points[0] = QPointF(std::numeric_limits<double>::max(),
625 std::numeric_limits<double>::max());
626 m_points[0] = QPointF(std::numeric_limits<double>::max(),
627 std::numeric_limits<double>::min());
628 m_points[0] = QPointF(std::numeric_limits<double>::min(),
629 std::numeric_limits<double>::max());
640 double width_value =
width(ok);
644 double height_value =
height(ok);
654 (width_value > 0 && width_value < std::numeric_limits<double>::max() -
655 std::numeric_limits<double>::min()) &&
656 (height_value == 0 ||
657 height_value == std::numeric_limits<double>::max() -
658 std::numeric_limits<double>::min()));
670 double width_value =
width(ok);
674 double height_value =
height(ok);
681 (width_value > 0 && width_value < std::numeric_limits<double>::max() -
682 std::numeric_limits<double>::min()) &&
683 (height_value > 0 && height_value < std::numeric_limits<double>::max() -
684 std::numeric_limits<double>::min()));
737 qFatal(
"Programming error.");
741 QString text =
"Selection polygon points, from top left, clockwise\n";
745 QPointF iter_point =
m_points[iter];
747 QString x_string =
"NOT_SET";
749 if(iter_point.x() != std::numeric_limits<double>::min() &&
750 iter_point.x() != std::numeric_limits<double>::max())
751 x_string = QString(
"%1").arg(iter_point.x(), 0,
'f', 10);
753 QString y_string =
"NOT_SET";
755 if(iter_point.y() != std::numeric_limits<double>::min() &&
756 iter_point.y() != std::numeric_limits<double>::max())
757 y_string = QString(
"%1").arg(iter_point.y(), 0,
'f', 10);
759 text += QString(
"(%1,%2)\n").arg(x_string).arg(y_string);
762 if(
m_minX != std::numeric_limits<double>::min() &&
763 m_minX != std::numeric_limits<double>::max())
764 text += QString(
"minX: %1 - ").arg(
m_minX, 0,
'f', 10);
766 text += QString(
"minX: NOT_SET - ");
768 if(
m_maxX != std::numeric_limits<double>::min() &&
769 m_maxX != std::numeric_limits<double>::max())
770 text += QString(
"maxX: %1 - ").arg(
m_maxX, 0,
'f', 10);
772 text += QString(
"maxX: NOT_SET - ");
774 if(
m_minY != std::numeric_limits<double>::min() &&
775 m_minY != std::numeric_limits<double>::max())
776 text += QString(
"minY: %1 - ").arg(
m_minY, 0,
'f', 10);
778 text += QString(
"minY: NOT_SET - ");
780 if(
m_maxY != std::numeric_limits<double>::min() &&
781 m_maxY != std::numeric_limits<double>::max())
782 text += QString(
"maxY: %1 - ").arg(
m_maxY, 0,
'f', 10);
784 text += QString(
"maxY: NOT_SET - ");
796 qFatal(
"Programming error.");
802 QString x_string =
"NOT_SET";
803 QString y_string =
"NOT_SET";
820 QPointF iter_point =
m_points[iter];
823 if(iter_point.x() != std::numeric_limits<double>::min() &&
824 iter_point.x() != std::numeric_limits<double>::max())
825 x_string = QString(
"%1").arg(iter_point.x(), 0,
'f', 3);
827 if(iter_point.y() != std::numeric_limits<double>::min() &&
828 iter_point.y() != std::numeric_limits<double>::max())
829 y_string = QString(
"%1").arg(iter_point.y(), 0,
'f', 3);
831 text += QString(
"(%1,%2)").arg(x_string).arg(y_string);
843 const QPointF &tested_point)
845 bool is_point_inside =
false;
847 QString debug_string;
849 is_point_inside = selection_polygon.
contains(tested_point);
850 debug_string = QString(
"(%1,%2) is inside: %3")
851 .arg(tested_point.x(), 0,
'f', 10)
852 .arg(tested_point.y(), 0,
'f', 10)
853 .arg(is_point_inside ?
"true" :
"false");
854 qDebug().noquote() << debug_string;
874 qDebug() <<
"The test selection polygon:" << selection_polygon.toString();
876 std::vector<QPointF> test_points;
878 test_points.push_back(QPointF(25, 250));
879 test_points.push_back(QPointF(22.3, 362));
880 test_points.push_back(QPointF(22.4, 473));
881 test_points.push_back(QPointF(22.4, 473.5));
882 test_points.push_back(QPointF(25, 250));
883 test_points.push_back(QPointF(25, 250.5));
884 test_points.push_back(QPointF(25, 360));
885 test_points.push_back(QPointF(28.9, 250));
886 test_points.push_back(QPointF(29, 250));
887 test_points.push_back(QPointF(29, 360));
888 test_points.push_back(QPointF(28.9, 473));
889 test_points.push_back(QPointF(28.9, 473.5));
890 test_points.push_back(QPointF(20, 200));
891 test_points.push_back(QPointF(20, 600));
892 test_points.push_back(QPointF(35, 200));
893 test_points.push_back(QPointF(35, 600));
902 for(
auto &&data_point : test_points)
908 selection_polygon.getPoint(pappso::PointSpecs::BOTTOM_LEFT_POINT).x();
910 selection_polygon.getPoint(pappso::PointSpecs::BOTTOM_LEFT_POINT).y();
914 selection_polygon.getPoint(pappso::PointSpecs::TOP_LEFT_POINT).x();
916 selection_polygon.getPoint(pappso::PointSpecs::TOP_LEFT_POINT).y();
918 if((xB_left - xA_left) * (data_point.y() - yA_left) -
919 (yB_left - yA_left) * (data_point.x() - xA_left) >
925 qDebug() << qSetRealNumberPrecision(10)
926 <<
"Filtered out point (left of left line):"
927 << data_point.x() <<
"-" << data_point.y();
932 qDebug() << qSetRealNumberPrecision(10)
933 <<
"Kept point (right of left line):" << data_point.x()
934 <<
"-" << data_point.y();
941 selection_polygon.getPoint(pappso::PointSpecs::BOTTOM_RIGHT_POINT).x();
943 selection_polygon.getPoint(pappso::PointSpecs::BOTTOM_RIGHT_POINT).y();
947 selection_polygon.getPoint(pappso::PointSpecs::TOP_RIGHT_POINT).x();
949 selection_polygon.getPoint(pappso::PointSpecs::TOP_RIGHT_POINT).y();
951 if((xB_right - xA_right) * (data_point.y() - yA_right) -
952 (yB_right - yA_right) * (data_point.x() - xA_right) <
955 qDebug() << qSetRealNumberPrecision(10)
956 <<
"Filtered out point (right of right line):"
957 << data_point.x() <<
"-" << data_point.y();
961 qDebug() << qSetRealNumberPrecision(10)
962 <<
"Definitively kept point (left of right line):"
963 << data_point.x() <<
"-" << data_point.y();
974 SelectionPolygon first_polygon(
975 QPointF(3, 8), QPointF(12, 8), QPointF(12, 3), QPointF(3, 3));
977 qDebug() <<
"square rectangle polygon: " << first_polygon.toString();
979 qDebug() <<
"outside";
981 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2,1));
982 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2.999999,5));
983 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2.999999,8.000001));
984 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2,5));
985 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2,9));
986 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,1));
987 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,8.0000001));
988 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,1));
989 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12.0000001,3));
990 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,3));
991 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,5));
992 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,8));
993 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,9));
994 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,9));
995 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,2.9999999));
997 qDebug() <<
"on the lines";
999 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(3,4));
1000 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,3));
1001 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,3));
1002 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,7));
1003 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,8));
1004 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,8));
1006 qDebug() <<
"inside";
1008 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(4,4));
1009 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(3.00001, 3.00001));
1010 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,4));
1011 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,3.1));
1012 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(11,5));
1013 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(11.99999,5));
1014 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,7.9));
1015 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1017 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1018 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1019 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1020 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1022 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1023 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1024 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1025 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1027 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1028 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1029 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1030 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1032 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1033 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1034 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1035 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1039 SelectionPolygon second_polygon(
1040 QPointF(9, 8), QPointF(12, 8), QPointF(6, 2), QPointF(3, 2));
1042 qDebug() <<
"skewed rectangle polygon: " << second_polygon.toString();
1044 qDebug() <<
"outside";
1046 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2,1));
1047 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2.999999,1.999999));
1048 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2.999999,3));
1049 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2.999999,8.000001));
1050 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2,5));
1051 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2,9));
1052 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(6,5.0000001));
1053 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,1));
1054 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,2.999999));
1055 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,4.999999));
1056 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,8.0000001));
1057 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(12.00000001,8));
1058 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(12,7.999999));
1059 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(14,3));
1060 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(14,5));
1062 qDebug() <<
"on the lines";
1064 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(3,2));
1065 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(6,5));
1066 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(12,8));
1067 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,8));
1068 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,5));
1069 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(11,7));
1070 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,6));
1071 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(4,3));
1073 qDebug() <<
"inside";
1075 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(3.00001,2.000001));
1076 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(4,2.000001));
1077 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(6.000001,2.00003));
1078 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,4));
1079 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(8.99999,5));
1080 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(10,7.99999));
1081 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(5,3));
1082 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(5,3.99999));
1089SelectionPolygon::reorderPoints()
1094 computeMinMaxCoordinates();
1101 double PI = 3.14159265358979323846;
1102 QPointF center_point(0, 0);
1104 for(
auto &point : m_points)
1106 center_point.setX(center_point.x() + point.x());
1107 center_point.setY(center_point.y() + point.y());
1110 center_point.setX(center_point.x() / m_points.size());
1111 center_point.setY(center_point.y() / m_points.size());
1117 double distance_x = center_point.x() - m_minX;
1118 double distance_y = center_point.y() - m_minY;
1120 center_point.setX(center_point.x() - (distance_x / 20));
1121 center_point.setY(center_point.y() - (distance_y / 20));
1123 std::sort(m_points.begin(),
1125 [center_point, PI](
const QPointF &a,
const QPointF &b) ->
bool {
1126 double a1 = std::fmod(
1127 std::atan2(a.x() - center_point.x(), a.y() - center_point.y()) *
1132 double a2 = std::fmod(
1133 std::atan2(b.x() - center_point.x(), b.y() - center_point.y()) *
1143 return (int)(a1 - a2);
bool rangeX(double &range_start, double &range_end) const
virtual ~SelectionPolygon()
bool rangeY(double &range_start, double &range_end) const
static void debugAlgorithm(const SelectionPolygon &selection_polygon, const QPointF &tested_point)
SelectionPolygon transpose() const
bool range(Axis axis, double &range_start, double &range_end) const
QString toShort4PointsString() const
void setPoint(PointSpec point_spec, double x, double y)
QPointF getTopMostPoint() const
QPointF getRightMostPoint() const
void set2D(QPointF top_left, QPointF top_right, QPointF bottom_right, QPointF bottom_left)
bool computeMinMaxCoordinates()
const std::vector< QPointF > & getPoints() const
void copyPoint(PointSpec point_spec_src, PointSpec point_spec_dest)
double width(bool &ok) const
QPointF getLeftMostPoint() const
SelectionPolygon & operator=(const SelectionPolygon &other)
QPointF getBottomMostPoint() const
void set1D(double x_range_start, double x_range_end)
QPointF getPoint(PointSpec point_spec) const
double height(bool &ok) const
bool contains(const QPointF &tested_point) const
std::vector< QPointF > m_points
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...