void-packages/srcpkgs/starplot/patches/05-startup-crash.diff
2020-03-20 15:16:09 +01:00

84 lines
2.7 KiB
Diff

From f603ddfa6a0eb6fc90bc8f14d0bb010efef975fa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bernhard=20=C3=9Cbelacker?= <bernhardu@mailbox.org>
Date: Mon, 8 May 2017 23:05:28 +0200
Subject: Replace c-like qsort with c++-like std::sort.
https://bugs.debian.org/862065
---
src/classes/stararray.cc | 49 +++++++++++++++++-------------------------------
1 file changed, 17 insertions(+), 32 deletions(-)
diff --git a/src/classes/stararray.cc b/src/classes/stararray.cc
index 26cc6a0..72cc856 100644
--- src/classes/stararray.cc
+++ src/classes/stararray.cc
@@ -26,6 +26,7 @@
#define NEED_FULL_NAMES
#include "constellations.h"
+#include <algorithm>
using std::string;
using std::vector;
@@ -167,42 +168,26 @@ typedef struct {
// Next, the function to compare for qsort().
-int compare_function(const void *p, const void *q)
-{
- double x1 = ((const sortable *)p)->xposition;
- double x2 = ((const sortable *)q)->xposition;
- return (x1 - x2 >= 0.0) ? 1 : -1;
-}
+struct sort_class {
+ Rules &rules;
+ sort_class(Rules &r) : rules(r) {};
+ bool operator() (const Star &p, const Star &q)
+ {
+ SolidAngle orientation = rules.ChartOrientation;
+ Vector3 relativeLocation;
+ relativeLocation = p.GetStarXYZ() - rules.ChartLocation;
+ double x1 = relativeLocation.getX() * cos(orientation.getPhi()) + relativeLocation.getY() * sin(orientation.getPhi());
+ relativeLocation = q.GetStarXYZ() - rules.ChartLocation;
+ double x2 = relativeLocation.getX() * cos(orientation.getPhi()) + relativeLocation.getY() * sin(orientation.getPhi());
+ return (x1 - x2 >= 0.0) ? 1 : -1;
+ }
+};
-// Finally, the main function which calls qsort()
+// Finally, the main function which calls std::sort()
void StarArray::Sort()
{
- size_t size = Array.size();
- Vector3 relativeLocation;
- SolidAngle orientation = ArrayRules.ChartOrientation;
- sortable *temparray = new sortable[size];
-
- // Make a temporary array for qsort(), consisting of "sortable" structs
- // which each contain a Star and a position in local coordinates.
- for (size_t i = 0; i < size; i++) {
- relativeLocation = Array[i].GetStarXYZ() - ArrayRules.ChartLocation;
- temparray[i].xposition =
- relativeLocation.getX() * cos(orientation.getPhi())
- + relativeLocation.getY() * sin(orientation.getPhi());
- temparray[i].star = Array[i];
- }
-
- qsort(temparray, size, sizeof(sortable), compare_function);
-
- // Put the sorted temporary array back into the vector
- Array.clear();
- for (size_t i = 0; i < size; i++) {
- temparray[i].star.SetPlace(i+1); // label stars starting at 1
- Array.push_back(temparray[i].star);
- }
-
- delete [] temparray;
+ std::sort(Array.begin(), Array.end(), sort_class(ArrayRules));
return;
}
--
2.11.0