libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
integrationscoperhomb.cpp
Go to the documentation of this file.
1// Copyright 2021 Filippo Rusconi
2// GPLv3+
3
4
5/////////////////////// StdLib includes
6#include <limits>
7#include <cmath>
8
9
10/////////////////////// Qt includes
11#include <QDebug>
12
13
14/////////////////////// Local includes
16
17
18namespace pappso
19{
20
22{
23 // qDebug() << "Constructing" << this;
24}
25
26IntegrationScopeRhomb::IntegrationScopeRhomb(const std::vector<QPointF> &points) : m_points(points)
27{
28 // qDebug() << "Constructing" << this << "with" << m_points.size() << "points.";
29}
30
31IntegrationScopeRhomb::IntegrationScopeRhomb(const std::vector<QPointF> &points,
32 Enums::DataKind data_kind_x,
33 Enums::DataKind data_kind_y)
34 : IntegrationScopeBase(), m_points(points), m_dataKindX(data_kind_x), m_dataKindY(data_kind_y)
35{
36 // qDebug() << "Constructing" << this << "with" << m_points.size() << "points."
37 // << "data_kind_x:" << static_cast<int>(data_kind_x)
38 // << "data_kind_y:" << static_cast<int>(data_kind_y);
39}
47
49{
50 // qDebug() << "Destructing" << this;
51}
52
55{
56 if(this == &other)
57 return *this;
58
59 m_points.assign(other.m_points.begin(), other.m_points.end());
60
63
64 return *this;
65}
66
67std::size_t
69{
70 m_points.push_back(point);
71 return m_points.size();
72}
73
74bool
75IntegrationScopeRhomb::getPoint([[maybe_unused]] QPointF &point) const
76{
77 return false;
78}
79
80bool
81IntegrationScopeRhomb::getPoints(std::vector<QPointF> &points) const
82{
83 points.clear();
84 points.assign(m_points.begin(), m_points.end());
85 return true;
86}
87
90{
91 if(m_points.size() < 4)
92 qFatal("The rhomboid has not four points.");
93
94 double top_most_y_value = std::numeric_limits<double>::min();
95
96 for(auto &the_point : m_points)
97 {
98 if(the_point.y() > top_most_y_value)
99 {
100 top_most_y_value = the_point.y();
101 point = the_point;
102 }
103 }
104
105 // Necessarily, whe have a top most point (greatest y of all).
107}
108
110IntegrationScopeRhomb::getTopMostPoints(std::vector<QPointF> &points) const
111{
112 if(m_points.size() < 4)
113 qFatal("The rhomboid has not four points.");
114
115 // Depending on the horiz or vert quality of the scope we are going to return
116 // 2 or 1 point, respectively.
117
118 points.clear();
119
120 QPointF point;
121
123 qFatal("Failed to get the top most point.");
124
125 // Store that point immediately.
126 points.push_back(point);
127
128 // Now that we know at least one of the top most points, check if there are
129 // other points having same y and different x. Note that one specific case
130 // is when the rhomboid is flat on the x axis, in which case all the points
131 // have the same y value. We will thus return 4 points. In all the other
132 // cases, we return 2 points if the rhomboid is horizontal and 1 point if the
133 // rhomboid is vertical.
134
135 for(auto &the_point : m_points)
136 {
137 if(the_point == point)
138 continue;
139
140 if(the_point.y() == point.y())
141 {
142 // We are handling a horizontal rhomboid.
143 points.push_back(the_point);
144 }
145 }
146
147 uint temp = 0;
148
149 if(points.size() == 1)
151 else if(points.size() == 2)
153 else if(points.size() > 2)
155
157
158 return static_cast<IntegrationScopeFeatures>(temp);
159}
160
163{
164 if(m_points.size() < 4)
165 qFatal("The rhomboid has not four points.");
166
167 double bottom_most_y_value = std::numeric_limits<double>::max();
168
169 for(auto &the_point : m_points)
170 {
171 if(the_point.y() < bottom_most_y_value)
172 {
173 bottom_most_y_value = the_point.y();
174 point = the_point;
175 }
176 }
177
179}
180
182IntegrationScopeRhomb::getBottomMostPoints(std::vector<QPointF> &points) const
183{
184 if(m_points.size() < 4)
185 qFatal("The rhomboid has not four points.");
186
187 // Depending of the horiz or vert quality of the scope we are going to return
188 // 1 or 2 points, respectively.
189
190 points.clear();
191
192 QPointF point;
193
195 qFatal("Failed to get the bottom most point.");
196
197 // Store that point immediately.
198 points.push_back(point);
199
200 // Now that we know at least one of the bottom most points, check if there are
201 // other points having same y and different x. Note that one specific case
202 // is when the rhomboid is flat on the x axis, in which case all the points
203 // have the same y value. We will thus return 4 points. In all the other
204 // cases, we return 2 points if the rhomboid is horizontal and 1 point if the
205 // rhomboid is vertical.
206
207 for(auto &the_point : m_points)
208 {
209 if(the_point == point)
210 continue;
211
212 if(the_point.y() == point.y())
213 {
214 // We are handling a vertical rhomboid.
215 points.push_back(the_point);
216 }
217 }
218
219 uint temp = 0;
220
221 if(points.size() == 1)
222 temp |= static_cast<int>(IntegrationScopeFeatures::RHOMBOID_VERTICAL);
223 else if(points.size() == 2)
224 temp |= static_cast<int>(IntegrationScopeFeatures::RHOMBOID_HORIZONTAL);
225 else if(points.size() > 2)
226 temp |= static_cast<int>(IntegrationScopeFeatures::FLAT_ON_X_AXIS);
227
228 temp |= static_cast<int>(IntegrationScopeFeatures::SUCCESS);
229
230 return static_cast<IntegrationScopeFeatures>(temp);
231}
232
235{
236 if(m_points.size() < 4)
237 qFatal("The rhomboid has not four points.");
238
239 double left_most_x = std::numeric_limits<double>::max();
240
241 for(auto &the_point : m_points)
242 {
243 if(the_point.x() < left_most_x)
244 {
245 left_most_x = the_point.x();
246 point = the_point;
247 }
248 }
249
251}
252
254IntegrationScopeRhomb::getLeftMostPoints(std::vector<QPointF> &points) const
255{
256 if(m_points.size() < 4)
257 qFatal("The rhomboid has not four points.");
258
259 // Depending of the horiz or vert quality of the scope we are going to return
260 // 1 or 2 points, respectively.
261
262 points.clear();
263
264 QPointF point;
265
267 qFatal("Failed to get at least one left most point.");
268
269 // Store that point immediately.
270 points.push_back(point);
271
272 // Now that we know at least one of the left most points, check if there are
273 // other points having same x and different y. Note that one specific case
274 // is when the rhomboid is flat on the y axis, in which case all the points
275 // have the same x value. We will thus return 4 points. In all the other
276 // cases, we return 1 point if the rhomboid is horizontal and 2 points if the
277 // rhomboid is vertical.
278
279 for(auto &the_point : m_points)
280 {
281 if(the_point == point)
282 continue;
283
284 if(the_point.x() == point.x())
285 {
286 // We are handling a vertical rhomboid.
287 points.push_back(the_point);
288 }
289 }
290
291 uint temp = 0;
292
293 if(points.size() == 1)
294 temp |= static_cast<int>(IntegrationScopeFeatures::RHOMBOID_HORIZONTAL);
295 else if(points.size() == 2)
296 temp |= static_cast<int>(IntegrationScopeFeatures::RHOMBOID_VERTICAL);
297 else if(points.size() > 2)
298 temp |= static_cast<int>(IntegrationScopeFeatures::FLAT_ON_Y_AXIS);
299
300 temp |= static_cast<int>(IntegrationScopeFeatures::SUCCESS);
301
302 return static_cast<IntegrationScopeFeatures>(temp);
303}
304
307{
308 if(m_points.size() < 4)
309 qFatal("The rhomboid has not four points.");
310
311 double greatest_x = std::numeric_limits<double>::min();
312
313 for(auto &the_point : m_points)
314 {
315 if(the_point.x() > greatest_x)
316 {
317 greatest_x = the_point.x();
318 point = the_point;
319 }
320 }
321
323}
324
326IntegrationScopeRhomb::getRightMostPoints(std::vector<QPointF> &points) const
327{
328 if(m_points.size() < 4)
329 qFatal("The rhomboid has not four points.");
330
331 // Depending of the horiz or vert quality of the scope we are going to return
332 // 1 or 2 points, respectively.
333
334 points.clear();
335
336 QPointF point;
337
339 qFatal("Failed to get at least one left most point.");
340
341 // Store that point immediately.
342 points.push_back(point);
343
344 // Now that we know at least one of the right most points, check if there are
345 // other points having same x and different y. Note that one specific case
346 // is when the rhomboid is flat on the y axis, in which case all the points
347 // have the same x value. We will thus return 4 points. In all the other
348 // cases, we return 1 point if the rhomboid is horizontal and 2 points if the
349 // rhomboid is vertical.
350
351 for(auto &the_point : m_points)
352 {
353 if(the_point == point)
354 continue;
355
356 if(the_point.x() == point.x())
357 {
358 // We are handling a vertical rhomboid.
359 points.push_back(the_point);
360 }
361 }
362
363 uint temp = 0;
364
365 if(points.size() == 1)
366 temp |= static_cast<int>(IntegrationScopeFeatures::RHOMBOID_HORIZONTAL);
367 else if(points.size() == 2)
368 temp |= static_cast<int>(IntegrationScopeFeatures::RHOMBOID_VERTICAL);
369 else if(points.size() > 2)
370 temp |= static_cast<int>(IntegrationScopeFeatures::FLAT_ON_Y_AXIS);
371
372 temp |= static_cast<int>(IntegrationScopeFeatures::SUCCESS);
373
374 return static_cast<IntegrationScopeFeatures>(temp);
375}
376
379{
380 if(m_points.size() < 4)
381 qFatal("The rhomboid has not four points.");
382
383 std::vector<QPointF> points;
384
385 // Try the top most points, which will tell us if the rhomboid is horizontal
386 // or not.
387
388 IntegrationScopeFeatures scope_features = getTopMostPoints(points);
389
390 if(scope_features == IntegrationScopeFeatures::FAILURE)
391 qFatal("Failed to get the top most points.");
392
394 {
395 // We should have gotten 2 points.
396
397 if(points.size() != 2)
398 qFatal("We should have gotten two points.");
399
400 if(points.at(0).x() < points.at(1).x())
401 point = points.at(0);
402 else
403 point = points.at(1);
404 }
405 else if(scope_features & IntegrationScopeFeatures::RHOMBOID_VERTICAL)
406 {
407 // In this case, we need to ask for the left most points. We'll have to
408 // check the
409 // results again!
410
411 scope_features = getLeftMostPoints(points);
412
413 if(scope_features == IntegrationScopeFeatures::FAILURE)
414 qFatal("Failed to get the left most points.");
415
417 {
418 // We should have gotten 2 points.
419
420 if(points.size() != 2)
421 qFatal("We should have gotten two points.");
422
423 if(points.at(0).y() > points.at(1).y())
424 point = points.at(0);
425 else
426 point = points.at(1);
427 }
428 else if(scope_features & IntegrationScopeFeatures::FLAT_ON_Y_AXIS)
429 {
430 // It is possible that the user has rotated the vertical rhomboid
431 // such that all the points are aligned on the y axis (all have the
432 // same x axis value). This is not an error condition. All we do is
433 // return scope_features so the caller understands the situations.
434 }
435 else
436 qFatal("This point should never be reached.");
437 }
438 else if(scope_features & IntegrationScopeFeatures::FLAT_ON_X_AXIS)
439 {
440 // This is not an error condition. All we do is return scope_features
441 // so the caller understands the situations.
442 }
443 else
444 qFatal("This point should never be reached.");
445
446 return scope_features;
447}
448
451{
452 if(m_points.size() < 4)
453 qFatal("The rhomboid has not four points.");
454
455 std::vector<QPointF> points;
456
457 // Try the bottom most points, which will tell us if the rhomboid is
458 // horizontal or not.
459
460 IntegrationScopeFeatures scope_features = getBottomMostPoints(points);
461
462 if(scope_features == IntegrationScopeFeatures::FAILURE)
463 qFatal("Failed to get the bottom most points.");
464
466 {
467 // We should have gotten 2 points.
468
469 if(points.size() != 2)
470 qFatal("We should have gotten two points.");
471
472 if(points.at(0).x() < points.at(1).x())
473 point = points.at(0);
474 else
475 point = points.at(1);
476 }
477 else if(scope_features & IntegrationScopeFeatures::RHOMBOID_VERTICAL)
478 {
479 // In this case, we need to ask for the left most points. We'll have to
480 // check the results again!
481
482 scope_features = getLeftMostPoints(points);
483
484 if(!(scope_features & IntegrationScopeFeatures::SUCCESS))
485 qFatal("Failed to get the left most points.");
486
488 {
489 // We should have gotten 2 points.
490
491 if(points.size() != 2)
492 qFatal("We should have gotten two points.");
493
494 if(points.at(0).y() < points.at(1).y())
495 point = points.at(0);
496 else
497 point = points.at(1);
498 }
499 else if(scope_features & IntegrationScopeFeatures::FLAT_ON_Y_AXIS)
500 {
501 // It is possible that the user has rotated the vertical rhomboid
502 // such that all the points are aligned on the y axis (all have the
503 // same x axis value). This is not an error condition. All we do is
504 // return scope_features so the caller understands the situations.
505 }
506 else
507 qFatal("This point should never be reached.");
508 }
509 else if(scope_features & IntegrationScopeFeatures::FLAT_ON_X_AXIS)
510 {
511 // This is not an error condition. All we do is return scope_features
512 // so the caller understands the situations.
513 }
514 else
515 qFatal("This point should never be reached.");
516
517 return scope_features;
518}
519
522{
523 if(m_points.size() < 4)
524 qFatal("The rhomboid has not four points.");
525
526 std::vector<QPointF> points;
527
528 // Try the top most points, which will tell us if the rhomboid is horizontal
529 // or not.
530
531 IntegrationScopeFeatures scope_features = getTopMostPoints(points);
532
533 if(scope_features == IntegrationScopeFeatures::FAILURE)
534 qFatal("Failed to get the top most points.");
535
537 {
538 // We should have gotten 2 points.
539
540 if(points.size() != 2)
541 qFatal("We should have gotten two points.");
542
543 if(points.at(0).x() > points.at(1).x())
544 point = points.at(0);
545 else
546 point = points.at(1);
547 }
548 else if(scope_features & IntegrationScopeFeatures::RHOMBOID_VERTICAL)
549 {
550 // In this case, we need to ask for the left most points. We'll have to
551 // check the results again!
552
553 scope_features = getRightMostPoints(points);
554
555 if(scope_features == IntegrationScopeFeatures::FAILURE)
556 qFatal("Failed to get the right most points.");
557
559 {
560 // We should have gotten 2 points.
561
562 if(points.size() != 2)
563 qFatal("We should have gotten two points.");
564
565 if(points.at(0).y() > points.at(1).y())
566 point = points.at(0);
567 else
568 point = points.at(1);
569 }
570 else if(scope_features & IntegrationScopeFeatures::FLAT_ON_Y_AXIS)
571 {
572 // It is possible that the user has rotated the vertical rhomboid
573 // such that all the points are aligned on the y axis (all have the
574 // same x axis value). This is not an error condition. All we do is
575 // return scope_features so the caller understands the situations.
576 }
577 else
578 qFatal("This point should never be reached.");
579 }
580 else if(scope_features & IntegrationScopeFeatures::FLAT_ON_X_AXIS)
581 {
582 // This is not an error condition. All we do is return scope_features
583 // so the caller understands the situations.
584 }
585 else
586 qFatal("This point should never be reached.");
587
588 return scope_features;
589}
590
593{
594 if(m_points.size() < 4)
595 qFatal("The rhomboid has not four points.");
596
597 std::vector<QPointF> points;
598
599 // Try the bottom most points, which will tell us if the rhomboid is
600 // horizontal or not.
601
602 IntegrationScopeFeatures scope_features = getBottomMostPoints(points);
603
604 if(scope_features == IntegrationScopeFeatures::FAILURE)
605 qFatal("Failed to get the bottom most points.");
606
608 {
609 // We should have gotten 2 points.
610
611 if(points.size() != 2)
612 qFatal("We should have gotten two points.");
613
614 if(points.at(0).x() > points.at(1).x())
615 point = points.at(0);
616 else
617 point = points.at(1);
618 }
619 else if(scope_features & IntegrationScopeFeatures::RHOMBOID_VERTICAL)
620 {
621 // In this case, we need to ask for the left most points. We'll have to
622 // check the results again!
623
624 scope_features = getRightMostPoints(points);
625
626 if(!(scope_features & IntegrationScopeFeatures::SUCCESS))
627 qFatal("Failed to get the right most points.");
628
630 {
631 // We should have gotten 2 points.
632
633 if(points.size() != 2)
634 qFatal("We should have gotten two points.");
635
636 if(points.at(0).y() < points.at(1).y())
637 point = points.at(0);
638 else
639 point = points.at(1);
640 }
641 else if(scope_features & IntegrationScopeFeatures::FLAT_ON_Y_AXIS)
642 {
643 // It is possible that the user has rotated the vertical rhomboid
644 // such that all the points are aligned on the y axis (all have the
645 // same x axis value). This is not an error condition. All we do is
646 // return scope_features so the caller understands the situations.
647 }
648 else
649 qFatal("This point should never be reached.");
650 }
651 else if(scope_features & IntegrationScopeFeatures::FLAT_ON_ANY_AXIS)
652 {
653 // This is not an error condition. All we do is return scope_features
654 // so the caller understands the situations.
655 }
656 else
657 qFatal("This point should never be reached.");
658
659 return scope_features;
660}
661
664{
665 if(m_points.size() < 4)
666 qFatal("The IntegrationScopeRhomb has less than four points.");
667
668 // There are two kinds of rhomboid integration scopes:
669
670 /*
671 4 +-----------+3
672 | |
673 | |
674 | |
675 | |
676 | |
677 | |
678 | |
679 1+----------+2
680 ----width---
681 */
682
683 // As visible here, the fixed size of the rhomboid (using the S key in the
684 // plot widget) is the *horizontal* side (this is the plot context's
685 // m_integrationScopeRhombWidth). In this case the height of the scope is 0.
686
687 // and
688
689
690 /*
691 * +3
692 * . |
693 * . |
694 * . |
695 * . +2
696 * . .
697 * . .
698 * . .
699 * 4+ .
700 * | | .
701 * height | | .
702 * | | .
703 * 1+
704 *
705 */
706
707 // As visible here, the fixed size of the rhomboid (using the S key in the
708 // plot widget) is the *vertical* side (this is the plot context's
709 // m_integrationScopeRhombHeight). In this case the width of the scope is 0.
710
711 // The width of the rhomboid is the entire span that it has on the x axis.
712
713 QPointF left_most_point;
714 QPointF right_most_point;
715
716 if(!getLeftMostPoint(left_most_point))
717 qFatal("Failed to get the left most point.");
718
719 if(!getRightMostPoint(right_most_point))
720 qFatal("Failed to get the right most point.");
721
722 width = fabs(right_most_point.x() - left_most_point.x());
723
725}
726
729{
730 // See getWidth() for explanations.
731
732 if(m_points.size() < 4)
733 qFatal("The IntegrationScopeRhomb has less than four points.");
734
735 // The height of the rhomboid is the entire span that it has on the y axis.
736
737 QPointF top_most_point;
738 QPointF bottom_most_point;
739
740 if(!getTopMostPoint(top_most_point))
741 qFatal("Failed to get the top most point.");
742
743 if(!getBottomMostPoint(bottom_most_point))
744 qFatal("Failed to get the bottom most point.");
745
746 height = fabs(top_most_point.y() - bottom_most_point.y());
747
749}
750
753{
754 if(m_points.size() < 4)
755 qFatal("The IntegrationScopeRhomb has less than four points.");
756
757 // There are two kinds of rhomboid integration scopes:
758
759 /*
760 * 4 +-----------+3
761 * | |
762 * | |
763 * | |
764 * | |
765 * | |
766 * | |
767 * | |
768 * 1+----------+2
769 * ----width---
770 */
771
772 // As visible here, the fixed size of the rhomboid (using the S key in the
773 // plot widget) is the *horizontal* side (this is the plot context's
774 // m_integrationScopeRhombWidth). In this case the height of the scope is 0.
775
776 // and
777
778
779 /*
780 * +3
781 * . |
782 * . |
783 * . |
784 * . +2
785 * . .
786 * . .
787 * . .
788 * 4+ .
789 * | | .
790 * height | | .
791 * | | .
792 * 1+
793 *
794 */
795
796 // As visible here, the fixed size of the rhomboid (using the S key in the
797 // plot widget) is the *vertical* side (this is the plot context's
798 // m_integrationScopeRhombHeight). In this case the width of the scope is 0.
799
800 // In this function we need to establish what kind of rhomboid (horizontal or
801 // vertical) we are dealing with.
802
803 // If the scope is horizontal, then two points of same y value (either top or
804 // bottom) have different x values. That is, leftmost top point has the same y
805 // value as the rightmost top point. Similarly, the leftmost bottom point has
806 // the same y value as the rightmost bottom point.
807
808 // If the scope is vertical, then there is only one single point that has the
809 // greatest y value. Likewise, there is only one single point having the
810 // smallest y value. Conversely, there are going to be two points of differing
811 // y values having the same x value (2 leftmost points and two rightmost
812 // points).
813
814 std::vector<QPointF> points;
815
816 // First get the top most point, we'll use the y value to check if there is
817 // only one point sharing that value or not.
818
819 // qDebug() << "The rhomboid integration scope:" << toString();
820
821 IntegrationScopeFeatures scope_features = getTopMostPoints(points);
822
823 if(scope_features == IntegrationScopeFeatures::FAILURE)
824 qFatal("Failed to get top most points.");
825
826 // qDebug() << "getTopMostPoints() got" << points.size() << "points.";
827
829 {
830 // Do not change anything to the width passed as parameter.
831 }
832 else if(scope_features & IntegrationScopeFeatures::RHOMBOID_HORIZONTAL)
833 {
834 // We are dealing with a horizontal rhomboid. Thus we *must* have
835 // gotten 2 points.
836 size = fabs(points.at(0).x() - points.at(1).x());
837 }
838 else if(scope_features & IntegrationScopeFeatures::RHOMBOID_VERTICAL)
839 {
840 // We are dealing with a vertical rhomboid.
841 size = 0;
842 }
843
844 return scope_features;
845}
846
849{
850 // See getRhombHorizontalSize() for explanations.
851
852 // If the scope is horizontal, then two points of same y value (either top or
853 // bottom) have different x values. That is, leftmost top point has the same y
854 // value as the rightmost top point. Similarly, the leftmost bottom point has
855 // the same y value as the rightmost bottom point.
856
857 // If the scope is vertical, then there is only one single point that has the
858 // greatest y value. Likewise, there is only one single point having the
859 // smallest y value. Conversely, there are going to be two points of differing
860 // y values having the same x value (2 leftmost points and two rightmost
861 // points).
862
863 std::vector<QPointF> points;
864
865 // Get the leftmost points (there are going to be 1 or 2 points in the
866 // vector depending on the kind of rhomboid.
867
868 // qDebug() << "The rhomboid integration scope:" << toString();
869
870 IntegrationScopeFeatures scope_features = getLeftMostPoints(points);
871
872 if(scope_features == IntegrationScopeFeatures::FAILURE)
873 qFatal("Failed to get left most points.");
874
875 // qDebug() << "getLeftMostPoints() got" << points.size() << "points.";
876
878 {
879 // Do not change anything to the width passed as parameter.
880 }
881 else if(scope_features & IntegrationScopeFeatures::RHOMBOID_HORIZONTAL)
882 {
883 // We are dealing with a horizontal rhomboid.
884 size = 0;
885 }
886 else if(scope_features & IntegrationScopeFeatures::RHOMBOID_VERTICAL)
887 {
888 // We are dealing with a vertical rhomboid. Thus we *must* have
889 // gotten 2 points.
890 size = fabs(points.at(0).y() - points.at(1).y());
891 }
892
893 return scope_features;
894}
895
896bool
897IntegrationScopeRhomb::range(Enums::Axis axis, double &start, double &end) const
898{
899 if(axis == Enums::Axis::x)
900 {
901 QPointF left_most_point;
903 qFatal("Failed to get left-most point.");
904
905 QPointF right_most_point;
907 qFatal("Failed to get right-most point.");
908
909 start = left_most_point.x();
910 end = right_most_point.x();
911
912 return true;
913 }
914 else if(axis == Enums::Axis::y)
915 {
916 QPointF bottom_most_point;
918 qFatal("Failed to get bottom-most point.");
919
920 QPointF top_most_point;
922 qFatal("Failed to get top-most point.");
923
924 start = bottom_most_point.y();
925 end = top_most_point.y();
926
927 return true;
928 }
929
930 return false;
931}
932
933void
935{
936 m_dataKindX = data_kind;
937}
938
939void
941{
942 m_dataKindY = data_kind;
943}
944
945bool
947{
948 data_kind = m_dataKindX;
949 return true;
950}
951
952bool
954{
955 data_kind = m_dataKindY;
956 return true;
957}
958
959bool
961{
962 return false;
963}
964
965bool
967{
968 return !is1D();
969}
970
971bool
973{
974 return false;
975}
976
977bool
979{
980 return true;
981}
982
983bool
985{
986 Enums::DataKind was_data_kind_y = m_dataKindY;
988 m_dataKindX = was_data_kind_y;
989
990 // Transpose each point in a new vector.
991 std::vector<QPointF> transposed_points;
992
993 for(QPointF &point : m_points)
994 transposed_points.push_back(QPointF(point.y(), point.x()));
995
996 // And now set them back to the member datum.
997 m_points.assign(transposed_points.begin(), transposed_points.end());
998
999 return true;
1000}
1001
1002bool
1003IntegrationScopeRhomb::contains(const QPointF &point) const
1004{
1005 // We have to make the real check using the point-in-polygon algorithm.
1006
1007 // This code is inspired by the work described here:
1008 // https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html
1009
1010 // int pnpoly(int vertex_count, float *vertx, float *verty, float testx,
1011 // float testy)
1012
1013 int i = 0;
1014 int j = 0;
1015 bool is_inside = false;
1016
1017 int vertex_count = m_points.size();
1018
1019 for(i = 0, j = vertex_count - 1; i < vertex_count; j = i++)
1020 {
1021 if(((m_points.at(i).y() > point.y()) != (m_points.at(j).y() > point.y())) &&
1022 (point.x() < (m_points.at(j).x() - m_points.at(i).x()) * (point.y() - m_points.at(i).y()) /
1023 (m_points.at(j).y() - m_points.at(i).y()) +
1024 m_points.at(i).x()))
1025 is_inside = !is_inside;
1026 }
1027
1028 // if(is_inside)
1029 // qDebug() << "Testing point:" << point
1030 // << "against rhomboid polygon - turns out be in.";
1031 // else
1032 // qDebug() << "Testing point:" << point
1033 // << "against rhomboid polygon - turns out be out.";
1034
1035 return is_inside;
1036}
1037
1038QString
1040{
1041 QString text = "[";
1042
1043#if 0
1044
1045 // This version is bad because it has reentrancy problems: it might be
1046 // called by functions that are actually called in turn here.
1047
1048 // First the bottom points pair
1050 text.append(QString("(%1, %2)").arg(point.x()).arg(point.y()));
1051
1053 text.append(QString("(%1, %2)").arg(point.x()).arg(point.y()));
1054
1055 // Second the top points pair
1056 getLeftMostTopPoint(point);
1057 text.append(QString("(%1, %2)").arg(point.x()).arg(point.y()));
1058
1059 getRightMostTopPoint(point);
1060 text.append(QString("(%1, %2)").arg(point.x()).arg(point.y()));
1061
1062#endif
1063
1064 for(auto &point : m_points)
1065 text.append(QString("(%1, %2)").arg(point.x()).arg(point.y()));
1066
1067 text.append("]");
1068
1069 // qDebug() << "Returning toString():" << text;
1070
1071 return text;
1072}
1073
1074void
1080
1081} // namespace pappso
IntegrationScopeBase(QObject *parent_p=nullptr)
virtual bool getPoints(std::vector< QPointF > &points) const override
virtual bool getDataKindX(Enums::DataKind &data_kind) override
virtual IntegrationScopeFeatures getWidth(double &width) const override
virtual IntegrationScopeFeatures getBottomMostPoints(std::vector< QPointF > &points) const override
virtual QString toString() const override
virtual IntegrationScopeFeatures getBottomMostPoint(QPointF &point) const override
virtual IntegrationScopeFeatures getRightMostPoints(std::vector< QPointF > &points) const override
virtual bool isRhomboid() const override
virtual IntegrationScopeFeatures getTopMostPoints(std::vector< QPointF > &points) const override
virtual IntegrationScopeFeatures getRightMostTopPoint(QPointF &point) const override
virtual void setDataKindX(Enums::DataKind data_kind) override
virtual bool range(Enums::Axis axis, double &start, double &end) const override
virtual IntegrationScopeFeatures getTopMostPoint(QPointF &point) const override
virtual std::size_t addPoint(QPointF point)
virtual IntegrationScopeFeatures getRhombVerticalSize(double &size) const override
virtual bool getDataKindY(Enums::DataKind &data_kind) override
virtual void setDataKindY(Enums::DataKind data_kind) override
virtual IntegrationScopeFeatures getHeight(double &height) const override
virtual IntegrationScopeFeatures getLeftMostPoint(QPointF &point) const override
virtual IntegrationScopeFeatures getLeftMostPoints(std::vector< QPointF > &points) const override
virtual bool getPoint(QPointF &point) const override
virtual IntegrationScopeFeatures getLeftMostTopPoint(QPointF &point) const override
virtual IntegrationScopeRhomb & operator=(const IntegrationScopeRhomb &other)
virtual IntegrationScopeFeatures getLeftMostBottomPoint(QPointF &point) const override
virtual IntegrationScopeFeatures getRhombHorizontalSize(double &size) const override
virtual IntegrationScopeFeatures getRightMostPoint(QPointF &point) const override
virtual IntegrationScopeFeatures getRightMostBottomPoint(QPointF &point) const override
virtual bool contains(const QPointF &point) const override
virtual bool isRectangle() const override
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
unsigned int uint
Definition types.h:67