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