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());
305const 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() &&
760 m_minX != std::numeric_limits<double>::max())
761 text += QString(
"minX: %1 - ").arg(
m_minX, 0,
'f', 10);
763 text += QString(
"minX: NOT_SET - ");
765 if(
m_maxX != std::numeric_limits<double>::min() &&
766 m_maxX != std::numeric_limits<double>::max())
767 text += QString(
"maxX: %1 - ").arg(
m_maxX, 0,
'f', 10);
769 text += QString(
"maxX: NOT_SET - ");
771 if(
m_minY != std::numeric_limits<double>::min() &&
772 m_minY != std::numeric_limits<double>::max())
773 text += QString(
"minY: %1 - ").arg(
m_minY, 0,
'f', 10);
775 text += QString(
"minY: NOT_SET - ");
777 if(
m_maxY != std::numeric_limits<double>::min() &&
778 m_maxY != std::numeric_limits<double>::max())
779 text += QString(
"maxY: %1 - ").arg(
m_maxY, 0,
'f', 10);
781 text += QString(
"maxY: NOT_SET - ");
793 qFatal(
"Programming error.");
799 QString x_string =
"NOT_SET";
800 QString y_string =
"NOT_SET";
817 QPointF iter_point =
m_points[iter];
820 if(iter_point.x() != std::numeric_limits<double>::min() &&
821 iter_point.x() != std::numeric_limits<double>::max())
822 x_string = QString(
"%1").arg(iter_point.x(), 0,
'f', 3);
824 if(iter_point.y() != std::numeric_limits<double>::min() &&
825 iter_point.y() != std::numeric_limits<double>::max())
826 y_string = QString(
"%1").arg(iter_point.y(), 0,
'f', 3);
828 text += QString(
"(%1,%2)").arg(x_string).arg(y_string);
840 const QPointF &tested_point)
842 bool is_point_inside =
false;
844 QString debug_string;
846 is_point_inside = selection_polygon.
contains(tested_point);
847 debug_string = QString(
"(%1,%2) is inside: %3")
848 .arg(tested_point.x(), 0,
'f', 10)
849 .arg(tested_point.y(), 0,
'f', 10)
850 .arg(is_point_inside ?
"true" :
"false");
851 qDebug().noquote() << debug_string;
871 qDebug() <<
"The test selection polygon:" << selection_polygon.toString();
873 std::vector<QPointF> test_points;
875 test_points.push_back(QPointF(25, 250));
876 test_points.push_back(QPointF(22.3, 362));
877 test_points.push_back(QPointF(22.4, 473));
878 test_points.push_back(QPointF(22.4, 473.5));
879 test_points.push_back(QPointF(25, 250));
880 test_points.push_back(QPointF(25, 250.5));
881 test_points.push_back(QPointF(25, 360));
882 test_points.push_back(QPointF(28.9, 250));
883 test_points.push_back(QPointF(29, 250));
884 test_points.push_back(QPointF(29, 360));
885 test_points.push_back(QPointF(28.9, 473));
886 test_points.push_back(QPointF(28.9, 473.5));
887 test_points.push_back(QPointF(20, 200));
888 test_points.push_back(QPointF(20, 600));
889 test_points.push_back(QPointF(35, 200));
890 test_points.push_back(QPointF(35, 600));
899 for(
auto &&data_point : test_points)
915 if((xB_left - xA_left) * (data_point.y() - yA_left) -
916 (yB_left - yA_left) * (data_point.x() - xA_left) >
922 qDebug() << qSetRealNumberPrecision(10)
923 <<
"Filtered out point (left of left line):"
924 << data_point.x() <<
"-" << data_point.y();
929 qDebug() << qSetRealNumberPrecision(10)
930 <<
"Kept point (right of left line):" << data_point.x()
931 <<
"-" << data_point.y();
948 if((xB_right - xA_right) * (data_point.y() - yA_right) -
949 (yB_right - yA_right) * (data_point.x() - xA_right) <
952 qDebug() << qSetRealNumberPrecision(10)
953 <<
"Filtered out point (right of right line):"
954 << data_point.x() <<
"-" << data_point.y();
958 qDebug() << qSetRealNumberPrecision(10)
959 <<
"Definitively kept point (left of right line):"
960 << data_point.x() <<
"-" << data_point.y();
971 SelectionPolygon first_polygon(
972 QPointF(3, 8), QPointF(12, 8), QPointF(12, 3), QPointF(3, 3));
974 qDebug() <<
"square rectangle polygon: " << first_polygon.toString();
976 qDebug() <<
"outside";
978 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2,1));
979 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2.999999,5));
980 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2.999999,8.000001));
981 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2,5));
982 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(2,9));
983 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,1));
984 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,8.0000001));
985 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,1));
986 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12.0000001,3));
987 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,3));
988 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,5));
989 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,8));
990 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(14,9));
991 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,9));
992 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,2.9999999));
994 qDebug() <<
"on the lines";
996 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(3,4));
997 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,3));
998 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,3));
999 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,7));
1000 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(12,8));
1001 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,8));
1003 qDebug() <<
"inside";
1005 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(4,4));
1006 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(3.00001, 3.00001));
1007 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,4));
1008 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,3.1));
1009 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(11,5));
1010 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(11.99999,5));
1011 SelectionPolygon::debugAlgorithm(first_polygon, QPointF(7,7.9));
1012 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1014 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1015 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1016 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1017 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1019 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1020 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1021 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1022 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1024 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1025 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1026 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1027 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1029 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1030 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1031 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1032 SelectionPolygon::debugAlgorithm(first_polygon, QPointF());
1036 SelectionPolygon second_polygon(
1037 QPointF(9, 8), QPointF(12, 8), QPointF(6, 2), QPointF(3, 2));
1039 qDebug() <<
"skewed rectangle polygon: " << second_polygon.toString();
1041 qDebug() <<
"outside";
1043 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2,1));
1044 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2.999999,1.999999));
1045 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2.999999,3));
1046 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2.999999,8.000001));
1047 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2,5));
1048 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(2,9));
1049 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(6,5.0000001));
1050 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,1));
1051 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,2.999999));
1052 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,4.999999));
1053 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,8.0000001));
1054 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(12.00000001,8));
1055 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(12,7.999999));
1056 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(14,3));
1057 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(14,5));
1059 qDebug() <<
"on the lines";
1061 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(3,2));
1062 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(6,5));
1063 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(12,8));
1064 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,8));
1065 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(9,5));
1066 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(11,7));
1067 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,6));
1068 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(4,3));
1070 qDebug() <<
"inside";
1072 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(3.00001,2.000001));
1073 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(4,2.000001));
1074 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(6.000001,2.00003));
1075 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(7,4));
1076 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(8.99999,5));
1077 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(10,7.99999));
1078 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(5,3));
1079 SelectionPolygon::debugAlgorithm(second_polygon, QPointF(5,3.99999));
1086SelectionPolygon::reorderPoints()
1091 computeMinMaxCoordinates();
1098 double PI = 3.14159265358979323846;
1099 QPointF center_point(0, 0);
1101 for(
auto &point : m_points)
1103 center_point.setX(center_point.x() + point.x());
1104 center_point.setY(center_point.y() + point.y());
1107 center_point.setX(center_point.x() / m_points.size());
1108 center_point.setY(center_point.y() / m_points.size());
1114 double distance_x = center_point.x() - m_minX;
1115 double distance_y = center_point.y() - m_minY;
1117 center_point.setX(center_point.x() - (distance_x / 20));
1118 center_point.setY(center_point.y() - (distance_y / 20));
1120 std::sort(m_points.begin(),
1122 [center_point, PI](
const QPointF &a,
const QPointF &b) ->
bool {
1123 double a1 = std::fmod(
1124 std::atan2(a.x() - center_point.x(), a.y() - center_point.y()) *
1129 double a2 = std::fmod(
1130 std::atan2(b.x() - center_point.x(), b.y() - center_point.y()) *
1140 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...