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