31 QPointF top_right_point)
47 QPointF(top_left_point.x(), std::numeric_limits<double>::max()));
51 QPointF(top_right_point.x(), std::numeric_limits<double>::max()));
55 QPointF(top_right_point.x(), std::numeric_limits<double>::min()));
59 QPointF(top_left_point.x(), std::numeric_limits<double>::min()));
68 QPointF top_right_point,
69 QPointF bottom_right_point,
70 QPointF bottom_left_point)
79 m_points.push_back(bottom_right_point);
80 m_points.push_back(bottom_left_point);
92 "The template selection polygon must have four points, no less, no more");
118 m_points[
static_cast<int>(point_spec)].setX(
x);
119 m_points[
static_cast<int>(point_spec)].setY(
y);
128 setPoint(point_spec, point.x(), point.y());
138 QPointF src_point =
getPoint(point_spec_src);
139 setPoint(point_spec_dest, src_point);
160 QPointF(x_range_start, std::numeric_limits<double>::max()));
164 QPointF(x_range_end, std::numeric_limits<double>::max()));
168 QPointF(x_range_end, std::numeric_limits<double>::min()));
172 QPointF(x_range_start, std::numeric_limits<double>::min()));
183 QPointF bottom_right,
231 QPointF temp_point(std::numeric_limits<double>::max(), 0);
251 QPointF temp_point(std::numeric_limits<double>::min(), 0);
271 QPointF temp_point(0, std::numeric_limits<double>::min());
291 QPointF temp_point(0, std::numeric_limits<double>::max());
305 const std::vector<QPointF> &
315 return m_points[
static_cast<int>(point_spec)];
325 m_minX = std::numeric_limits<double>::max();
326 m_minY = std::numeric_limits<double>::max();
327 m_maxX = std::numeric_limits<double>::min();
328 m_maxY = std::numeric_limits<double>::min();
352 min_x = std::numeric_limits<double>::max();
353 min_y = std::numeric_limits<double>::max();
354 max_x = std::numeric_limits<double>::min();
355 max_y = std::numeric_limits<double>::min();
359 min_x = std::min(
m_points.at(iter).x(), min_x);
360 max_x = std::max(
m_points.at(iter).x(), max_x);
362 min_y = std::min(
m_points.at(iter).y(), min_y);
363 max_y = std::max(
m_points.at(iter).y(), max_y);
384 return max_x - min_x;
399 return max_y - min_y;
406 double min_y = std::numeric_limits<double>::max();
407 double max_y = std::numeric_limits<double>::min();
416 double min_x = std::numeric_limits<double>::max();
417 double max_x = std::numeric_limits<double>::min();
427 return rangeX(range_start, range_end);
429 return rangeY(range_start, range_end);
456 qFatal(
"The polygon must have four points, no less, no more");
481 return selection_polygon;
491 if(tested_point.x() <
m_minX || tested_point.x() >
m_maxX ||
512 double x = tested_point.x();
513 double y = tested_point.y();
544 bool is_inside =
false;
548 for(i = 0, j = vertex_count - 1; i < vertex_count; j = i++)
550 if(((
m_points.at(i).y() > tested_point.y()) !=
551 (
m_points.at(j).y() > tested_point.y())) &&
553 (tested_point.y() -
m_points.at(i).y()) /
556 is_inside = !is_inside;
576 bool is_inside =
true;
595 qFatal(
"Programming error.");
598 qFatal(
"Programming error.");
619 m_points[0] = QPointF(std::numeric_limits<double>::min(),
620 std::numeric_limits<double>::max());
621 m_points[0] = QPointF(std::numeric_limits<double>::max(),
622 std::numeric_limits<double>::max());
623 m_points[0] = QPointF(std::numeric_limits<double>::max(),
624 std::numeric_limits<double>::min());
625 m_points[0] = QPointF(std::numeric_limits<double>::min(),
626 std::numeric_limits<double>::max());
637 double width_value =
width(ok);
641 double height_value =
height(ok);
651 (width_value > 0 && width_value < std::numeric_limits<double>::max() -
652 std::numeric_limits<double>::min()) &&
653 (height_value == 0 ||
654 height_value == std::numeric_limits<double>::max() -
655 std::numeric_limits<double>::min()));
667 double width_value =
width(ok);
671 double height_value =
height(ok);
678 (width_value > 0 && width_value < std::numeric_limits<double>::max() -
679 std::numeric_limits<double>::min()) &&
680 (height_value > 0 && height_value < std::numeric_limits<double>::max() -
681 std::numeric_limits<double>::min()));
734 qFatal(
"Programming error.");
738 QString text =
"Selection polygon points, from top left, clockwise\n";
742 QPointF iter_point =
m_points[iter];
744 QString x_string =
"NOT_SET";
746 if(iter_point.x() != std::numeric_limits<double>::min() &&
747 iter_point.x() != std::numeric_limits<double>::max())
748 x_string = QString(
"%1").arg(iter_point.x(), 0,
'f', 10);
750 QString y_string =
"NOT_SET";
752 if(iter_point.y() != std::numeric_limits<double>::min() &&
753 iter_point.y() != std::numeric_limits<double>::max())
754 y_string = QString(
"%1").arg(iter_point.y(), 0,
'f', 10);
756 text += QString(
"(%1,%2)\n").arg(x_string).arg(y_string);
759 if(
m_minX != std::numeric_limits<double>::min() &&
m_minX != std::numeric_limits<double>::max())
760 text += QString(
"minX: %1 - ").arg(
m_minX, 0,
'f', 10);
762 text += QString(
"minX: NOT_SET - ");
764 if(
m_maxX != std::numeric_limits<double>::min() &&
m_maxX != std::numeric_limits<double>::max())
765 text += QString(
"maxX: %1 - ").arg(
m_maxX, 0,
'f', 10);
767 text += QString(
"maxX: NOT_SET - ");
769 if(
m_minY != std::numeric_limits<double>::min() &&
m_minY != std::numeric_limits<double>::max())
770 text += QString(
"minY: %1 - ").arg(
m_minY, 0,
'f', 10);
772 text += QString(
"minY: NOT_SET - ");
774 if(
m_maxY != std::numeric_limits<double>::min() &&
m_maxY != std::numeric_limits<double>::max())
775 text += QString(
"maxY: %1 - ").arg(
m_maxY, 0,
'f', 10);
777 text += QString(
"maxY: NOT_SET - ");
789 qFatal(
"Programming error.");
795 QString x_string =
"NOT_SET";
796 QString y_string =
"NOT_SET";
813 QPointF iter_point =
m_points[iter];
816 if(iter_point.x() != std::numeric_limits<double>::min() &&
817 iter_point.x() != std::numeric_limits<double>::max())
818 x_string = QString(
"%1").arg(iter_point.x(), 0,
'f', 3);
820 if(iter_point.y() != std::numeric_limits<double>::min() &&
821 iter_point.y() != std::numeric_limits<double>::max())
822 y_string = QString(
"%1").arg(iter_point.y(), 0,
'f', 3);
824 text += QString(
"(%1,%2)").arg(x_string).arg(y_string);
836 const QPointF &tested_point)
838 bool is_point_inside =
false;
840 QString debug_string;
842 is_point_inside = selection_polygon.
contains(tested_point);
843 debug_string = QString(
"(%1,%2) is inside: %3")
844 .arg(tested_point.x(), 0,
'f', 10)
845 .arg(tested_point.y(), 0,
'f', 10)
846 .arg(is_point_inside ?
"true" :
"false");
847 qDebug().noquote() << debug_string;
867 qDebug() <<
"The test selection polygon:" << selection_polygon.toString();
869 std::vector<QPointF> test_points;
871 test_points.push_back(QPointF(25, 250));
872 test_points.push_back(QPointF(22.3, 362));
873 test_points.push_back(QPointF(22.4, 473));
874 test_points.push_back(QPointF(22.4, 473.5));
875 test_points.push_back(QPointF(25, 250));
876 test_points.push_back(QPointF(25, 250.5));
877 test_points.push_back(QPointF(25, 360));
878 test_points.push_back(QPointF(28.9, 250));
879 test_points.push_back(QPointF(29, 250));
880 test_points.push_back(QPointF(29, 360));
881 test_points.push_back(QPointF(28.9, 473));
882 test_points.push_back(QPointF(28.9, 473.5));
883 test_points.push_back(QPointF(20, 200));
884 test_points.push_back(QPointF(20, 600));
885 test_points.push_back(QPointF(35, 200));
886 test_points.push_back(QPointF(35, 600));
895 for(
auto &&data_point : test_points)
911 if((xB_left - xA_left) * (data_point.y() - yA_left) -
912 (yB_left - yA_left) * (data_point.x() - xA_left) >
918 qDebug() << qSetRealNumberPrecision(10)
919 <<
"Filtered out point (left of left line):"
920 << data_point.x() <<
"-" << data_point.y();
925 qDebug() << qSetRealNumberPrecision(10)
926 <<
"Kept point (right of left line):" << data_point.x()
927 <<
"-" << data_point.y();
944 if((xB_right - xA_right) * (data_point.y() - yA_right) -
945 (yB_right - yA_right) * (data_point.x() - xA_right) <
948 qDebug() << qSetRealNumberPrecision(10)
949 <<
"Filtered out point (right of right line):"
950 << data_point.x() <<
"-" << data_point.y();
954 qDebug() << qSetRealNumberPrecision(10)
955 <<
"Definitively kept point (left of right line):"
956 << data_point.x() <<
"-" << data_point.y();
967 SelectionPolygon first_polygon(
968 QPointF(3, 8), QPointF(12, 8), QPointF(12, 3), QPointF(3, 3));
970 qDebug() <<
"square rectangle polygon: " << first_polygon.toString();
972 qDebug() <<
"outside";
974 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2,1));
975 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2.999999,5));
976 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2.999999,8.000001));
977 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2,5));
978 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2,9));
979 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,1));
980 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,8.0000001));
981 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,1));
982 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12.0000001,3));
983 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,3));
984 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,5));
985 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,8));
986 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,9));
987 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,9));
988 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,2.9999999));
990 qDebug() <<
"on the lines";
992 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(3,4));
993 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,3));
994 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,3));
995 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,7));
996 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,8));
997 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,8));
999 qDebug() <<
"inside";
1001 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(4,4));
1002 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(3.00001, 3.00001));
1003 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,4));
1004 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,3.1));
1005 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(11,5));
1006 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(11.99999,5));
1007 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,7.9));
1008 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1010 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1011 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1012 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1013 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1015 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1016 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1017 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1018 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1020 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1021 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1022 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1023 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1025 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1026 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1027 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1028 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1032 SelectionPolygon second_polygon(
1033 QPointF(9, 8), QPointF(12, 8), QPointF(6, 2), QPointF(3, 2));
1035 qDebug() <<
"skewed rectangle polygon: " << second_polygon.toString();
1037 qDebug() <<
"outside";
1039 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2,1));
1040 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2.999999,1.999999));
1041 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2.999999,3));
1042 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2.999999,8.000001));
1043 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2,5));
1044 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2,9));
1045 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(6,5.0000001));
1046 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,1));
1047 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,2.999999));
1048 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,4.999999));
1049 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,8.0000001));
1050 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(12.00000001,8));
1051 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(12,7.999999));
1052 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(14,3));
1053 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(14,5));
1055 qDebug() <<
"on the lines";
1057 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(3,2));
1058 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(6,5));
1059 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(12,8));
1060 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,8));
1061 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,5));
1062 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(11,7));
1063 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,6));
1064 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(4,3));
1066 qDebug() <<
"inside";
1068 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(3.00001,2.000001));
1069 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(4,2.000001));
1070 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(6.000001,2.00003));
1071 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,4));
1072 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(8.99999,5));
1073 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(10,7.99999));
1074 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(5,3));
1075 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(5,3.99999));
1082 SelectionPolygon::reorderPoints()
1087 computeMinMaxCoordinates();
1094 double PI = 3.14159265358979323846;
1095 QPointF center_point(0, 0);
1097 for(
auto &point : m_points)
1099 center_point.setX(center_point.x() + point.x());
1100 center_point.setY(center_point.y() + point.y());
1103 center_point.setX(center_point.x() / m_points.size());
1104 center_point.setY(center_point.y() / m_points.size());
1110 double distance_x = center_point.x() - m_minX;
1111 double distance_y = center_point.y() - m_minY;
1113 center_point.setX(center_point.x() - (distance_x / 20));
1114 center_point.setY(center_point.y() - (distance_y / 20));
1116 std::sort(m_points.begin(),
1118 [center_point, PI](
const QPointF &a,
const QPointF &b) ->
bool {
1119 double a1 = std::fmod(
1120 std::atan2(a.x() - center_point.x(), a.y() - center_point.y()) *
1125 double a2 = std::fmod(
1126 std::atan2(b.x() - center_point.x(), b.y() - center_point.y()) *
1136 return (int)(a1 - a2);
void copyPoint(PointSpecs point_spec_src, PointSpecs point_spec_dest)
bool rangeX(double &range_start, double &range_end) const
virtual ~SelectionPolygon()
bool rangeY(double &range_start, double &range_end) const
void setPoint(PointSpecs point_spec, double x, double y)
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
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
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)
double height(bool &ok) const
bool contains(const QPointF &tested_point) const
QPointF getPoint(PointSpecs point_spec) const
std::vector< QPointF > m_points
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...