48 m_points.push_back(QPointF(top_left_point.x(), std::numeric_limits<double>::max()));
51 m_points.push_back(QPointF(top_right_point.x(), std::numeric_limits<double>::max()));
54 m_points.push_back(QPointF(top_right_point.x(), std::numeric_limits<double>::min()));
57 m_points.push_back(QPointF(top_left_point.x(), std::numeric_limits<double>::min()));
66 QPointF top_right_point,
67 QPointF bottom_right_point,
68 QPointF bottom_left_point)
77 m_points.push_back(bottom_right_point);
78 m_points.push_back(bottom_left_point);
89 qFatal(
"The template selection polygon must have four points, no less, no more");
115 m_points[
static_cast<int>(point_spec)].setX(
x);
116 m_points[
static_cast<int>(point_spec)].setY(
y);
125 setPoint(point_spec, point.x(), point.y());
134 QPointF src_point =
getPoint(point_spec_src);
135 setPoint(point_spec_dest, src_point);
165 QPointF(x_range_start, std::numeric_limits<double>::min()));
176 QPointF bottom_right,
224 QPointF temp_point(std::numeric_limits<double>::max(), 0);
244 QPointF temp_point(std::numeric_limits<double>::min(), 0);
264 QPointF temp_point(0, std::numeric_limits<double>::min());
284 QPointF temp_point(0, std::numeric_limits<double>::max());
298const std::vector<QPointF> &
308 return m_points[
static_cast<int>(point_spec)];
318 m_minX = std::numeric_limits<double>::max();
319 m_minY = std::numeric_limits<double>::max();
320 m_maxX = std::numeric_limits<double>::min();
321 m_maxY = std::numeric_limits<double>::min();
345 min_x = std::numeric_limits<double>::max();
346 min_y = std::numeric_limits<double>::max();
347 max_x = std::numeric_limits<double>::min();
348 max_y = std::numeric_limits<double>::min();
352 min_x = std::min(
m_points.at(iter).x(), min_x);
353 max_x = std::max(
m_points.at(iter).x(), max_x);
355 min_y = std::min(
m_points.at(iter).y(), min_y);
356 max_y = std::max(
m_points.at(iter).y(), max_y);
377 return max_x - min_x;
392 return max_y - min_y;
399 double min_y = std::numeric_limits<double>::max();
400 double max_y = std::numeric_limits<double>::min();
409 double min_x = std::numeric_limits<double>::max();
410 double max_x = std::numeric_limits<double>::min();
420 return rangeX(range_start, range_end);
422 return rangeY(range_start, range_end);
449 qFatal(
"The polygon must have four points, no less, no more");
471 return selection_polygon;
481 if(tested_point.x() <
m_minX || tested_point.x() >
m_maxX || tested_point.y() <
m_minY ||
482 tested_point.y() >
m_maxY)
502 double x = tested_point.x();
503 double y = tested_point.y();
534 bool is_inside =
false;
538 for(i = 0, j = vertex_count - 1; i < vertex_count; j = i++)
540 if(((
m_points.at(i).y() > tested_point.y()) != (
m_points.at(j).y() > tested_point.y())) &&
542 (tested_point.y() -
m_points.at(i).y()) /
545 is_inside = !is_inside;
565 bool is_inside =
true;
584 qFatal(
"Programming error.");
587 qFatal(
"Programming error.");
608 m_points[0] = QPointF(std::numeric_limits<double>::min(), std::numeric_limits<double>::max());
609 m_points[0] = QPointF(std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
610 m_points[0] = QPointF(std::numeric_limits<double>::max(), std::numeric_limits<double>::min());
611 m_points[0] = QPointF(std::numeric_limits<double>::min(), std::numeric_limits<double>::max());
622 double width_value =
width(ok);
626 double height_value =
height(ok);
635 return ((width_value > 0 &&
636 width_value < std::numeric_limits<double>::max() - std::numeric_limits<double>::min()) &&
637 (height_value == 0 || height_value == std::numeric_limits<double>::max() -
638 std::numeric_limits<double>::min()));
650 double width_value =
width(ok);
654 double height_value =
height(ok);
660 return ((width_value > 0 &&
661 width_value < std::numeric_limits<double>::max() - std::numeric_limits<double>::min()) &&
663 height_value < std::numeric_limits<double>::max() - std::numeric_limits<double>::min()));
712 qFatal(
"Programming error.");
716 QString text =
"Selection polygon points, from top left, clockwise\n";
720 QPointF iter_point =
m_points[iter];
722 QString x_string =
"NOT_SET";
724 if(iter_point.x() != std::numeric_limits<double>::min() &&
725 iter_point.x() != std::numeric_limits<double>::max())
726 x_string = QString(
"%1").arg(iter_point.x(), 0,
'f', 10);
728 QString y_string =
"NOT_SET";
730 if(iter_point.y() != std::numeric_limits<double>::min() &&
731 iter_point.y() != std::numeric_limits<double>::max())
732 y_string = QString(
"%1").arg(iter_point.y(), 0,
'f', 10);
734 text += QString(
"(%1,%2)\n").arg(x_string).arg(y_string);
737 if(
m_minX != std::numeric_limits<double>::min() &&
m_minX != std::numeric_limits<double>::max())
738 text += QString(
"minX: %1 - ").arg(
m_minX, 0,
'f', 10);
740 text += QString(
"minX: NOT_SET - ");
742 if(
m_maxX != std::numeric_limits<double>::min() &&
m_maxX != std::numeric_limits<double>::max())
743 text += QString(
"maxX: %1 - ").arg(
m_maxX, 0,
'f', 10);
745 text += QString(
"maxX: NOT_SET - ");
747 if(
m_minY != std::numeric_limits<double>::min() &&
m_minY != std::numeric_limits<double>::max())
748 text += QString(
"minY: %1 - ").arg(
m_minY, 0,
'f', 10);
750 text += QString(
"minY: NOT_SET - ");
752 if(
m_maxY != std::numeric_limits<double>::min() &&
m_maxY != std::numeric_limits<double>::max())
753 text += QString(
"maxY: %1 - ").arg(
m_maxY, 0,
'f', 10);
755 text += QString(
"maxY: NOT_SET - ");
767 qFatal(
"Programming error.");
773 QString x_string =
"NOT_SET";
774 QString y_string =
"NOT_SET";
791 QPointF iter_point =
m_points[iter];
794 if(iter_point.x() != std::numeric_limits<double>::min() &&
795 iter_point.x() != std::numeric_limits<double>::max())
796 x_string = QString(
"%1").arg(iter_point.x(), 0,
'f', 3);
798 if(iter_point.y() != std::numeric_limits<double>::min() &&
799 iter_point.y() != std::numeric_limits<double>::max())
800 y_string = QString(
"%1").arg(iter_point.y(), 0,
'f', 3);
802 text += QString(
"(%1,%2)").arg(x_string).arg(y_string);
814 const QPointF &tested_point)
816 bool is_point_inside =
false;
818 QString debug_string;
820 is_point_inside = selection_polygon.
contains(tested_point);
821 debug_string = QString(
"(%1,%2) is inside: %3")
822 .arg(tested_point.x(), 0,
'f', 10)
823 .arg(tested_point.y(), 0,
'f', 10)
824 .arg(is_point_inside ?
"true" :
"false");
825 qDebug().noquote() << debug_string;
845 qDebug() <<
"The test selection polygon:" << selection_polygon.toString();
847 std::vector<QPointF> test_points;
849 test_points.push_back(QPointF(25, 250));
850 test_points.push_back(QPointF(22.3, 362));
851 test_points.push_back(QPointF(22.4, 473));
852 test_points.push_back(QPointF(22.4, 473.5));
853 test_points.push_back(QPointF(25, 250));
854 test_points.push_back(QPointF(25, 250.5));
855 test_points.push_back(QPointF(25, 360));
856 test_points.push_back(QPointF(28.9, 250));
857 test_points.push_back(QPointF(29, 250));
858 test_points.push_back(QPointF(29, 360));
859 test_points.push_back(QPointF(28.9, 473));
860 test_points.push_back(QPointF(28.9, 473.5));
861 test_points.push_back(QPointF(20, 200));
862 test_points.push_back(QPointF(20, 600));
863 test_points.push_back(QPointF(35, 200));
864 test_points.push_back(QPointF(35, 600));
873 for(
auto &&data_point : test_points)
879 selection_polygon.getPoint(pappso::PointSpecs::BOTTOM_LEFT_POINT).x();
881 selection_polygon.getPoint(pappso::PointSpecs::BOTTOM_LEFT_POINT).y();
885 selection_polygon.getPoint(pappso::PointSpecs::TOP_LEFT_POINT).x();
887 selection_polygon.getPoint(pappso::PointSpecs::TOP_LEFT_POINT).y();
889 if((xB_left - xA_left) * (data_point.y() - yA_left) -
890 (yB_left - yA_left) * (data_point.x() - xA_left) >
896 qDebug() << qSetRealNumberPrecision(10)
897 <<
"Filtered out point (left of left line):"
898 << data_point.x() <<
"-" << data_point.y();
903 qDebug() << qSetRealNumberPrecision(10)
904 <<
"Kept point (right of left line):" << data_point.x()
905 <<
"-" << data_point.y();
912 selection_polygon.getPoint(pappso::PointSpecs::BOTTOM_RIGHT_POINT).x();
914 selection_polygon.getPoint(pappso::PointSpecs::BOTTOM_RIGHT_POINT).y();
918 selection_polygon.getPoint(pappso::PointSpecs::TOP_RIGHT_POINT).x();
920 selection_polygon.getPoint(pappso::PointSpecs::TOP_RIGHT_POINT).y();
922 if((xB_right - xA_right) * (data_point.y() - yA_right) -
923 (yB_right - yA_right) * (data_point.x() - xA_right) <
926 qDebug() << qSetRealNumberPrecision(10)
927 <<
"Filtered out point (right of right line):"
928 << data_point.x() <<
"-" << data_point.y();
932 qDebug() << qSetRealNumberPrecision(10)
933 <<
"Definitively kept point (left of right line):"
934 << data_point.x() <<
"-" << data_point.y();
945 SelectionPolygon first_polygon(
946 QPointF(3, 8), QPointF(12, 8), QPointF(12, 3), QPointF(3, 3));
948 qDebug() <<
"square rectangle polygon: " << first_polygon.toString();
950 qDebug() <<
"outside";
952 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2,1));
953 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2.999999,5));
954 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2.999999,8.000001));
955 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2,5));
956 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2,9));
957 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,1));
958 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,8.0000001));
959 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,1));
960 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12.0000001,3));
961 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,3));
962 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,5));
963 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,8));
964 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,9));
965 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,9));
966 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,2.9999999));
968 qDebug() <<
"on the lines";
970 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(3,4));
971 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,3));
972 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,3));
973 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,7));
974 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,8));
975 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,8));
977 qDebug() <<
"inside";
979 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(4,4));
980 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(3.00001, 3.00001));
981 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,4));
982 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,3.1));
983 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(11,5));
984 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(11.99999,5));
985 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,7.9));
986 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
988 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
989 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
990 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
991 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
993 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
994 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
995 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
996 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
998 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
999 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1000 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1001 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1003 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1004 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1005 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1006 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1010 SelectionPolygon second_polygon(
1011 QPointF(9, 8), QPointF(12, 8), QPointF(6, 2), QPointF(3, 2));
1013 qDebug() <<
"skewed rectangle polygon: " << second_polygon.toString();
1015 qDebug() <<
"outside";
1017 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2,1));
1018 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2.999999,1.999999));
1019 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2.999999,3));
1020 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2.999999,8.000001));
1021 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2,5));
1022 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2,9));
1023 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(6,5.0000001));
1024 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,1));
1025 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,2.999999));
1026 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,4.999999));
1027 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,8.0000001));
1028 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(12.00000001,8));
1029 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(12,7.999999));
1030 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(14,3));
1031 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(14,5));
1033 qDebug() <<
"on the lines";
1035 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(3,2));
1036 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(6,5));
1037 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(12,8));
1038 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,8));
1039 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,5));
1040 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(11,7));
1041 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,6));
1042 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(4,3));
1044 qDebug() <<
"inside";
1046 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(3.00001,2.000001));
1047 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(4,2.000001));
1048 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(6.000001,2.00003));
1049 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,4));
1050 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(8.99999,5));
1051 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(10,7.99999));
1052 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(5,3));
1053 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(5,3.99999));
1060SelectionPolygon::reorderPoints()
1065 computeMinMaxCoordinates();
1072 double PI = 3.14159265358979323846;
1073 QPointF center_point(0, 0);
1075 for(
auto &point : m_points)
1077 center_point.setX(center_point.x() + point.x());
1078 center_point.setY(center_point.y() + point.y());
1081 center_point.setX(center_point.x() / m_points.size());
1082 center_point.setY(center_point.y() / m_points.size());
1088 double distance_x = center_point.x() - m_minX;
1089 double distance_y = center_point.y() - m_minY;
1091 center_point.setX(center_point.x() - (distance_x / 20));
1092 center_point.setY(center_point.y() - (distance_y / 20));
1094 std::sort(m_points.begin(),
1096 [center_point, PI](
const QPointF &a,
const QPointF &b) ->
bool {
1097 double a1 = std::fmod(
1098 std::atan2(a.x() - center_point.x(), a.y() - center_point.y()) *
1103 double a2 = std::fmod(
1104 std::atan2(b.x() - center_point.x(), b.y() - center_point.y()) *
1114 return (int)(a1 - a2);
bool range(Enums::Axis axis, double &range_start, double &range_end) const
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
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...