File indexing completed on 2024-03-24 15:18:13

0001 /*
0002     SPDX-FileCopyrightText: 2010 Akarsh Simha <akarshsimha@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QHash>
0010 #include <QList>
0011 
0012 class QStringList;
0013 
0014 class SkyPoint;
0015 class StarObject;
0016 
0017 /**
0018  * @class StarHopper
0019  * @short Helps planning star hopping
0020  *
0021  * @version 1.0
0022  * @author Akarsh Simha
0023  */
0024 class StarHopper
0025 {
0026   public:
0027     /**
0028      * @short Computes path for Star Hop
0029      * @param src SkyPoint to source of the Star Hop
0030      * @param dest SkyPoint to destination of the Star Hop
0031      * @param fov__ Field of view within which stars are considered
0032      * @param maglim__ Magnitude limit of stars to consider
0033      * @param metadata_ Directions for starhopping
0034      * @return QList of StarObject pointers which are the resultant path to Star Hop
0035      * @note The StarObjects in the list returned are mutable and not constant
0036      */
0037     QList<StarObject *> *computePath(const SkyPoint &src, const SkyPoint &dest, float fov__, float maglim__,
0038                                      QStringList *metadata_ = nullptr);
0039 
0040   protected:
0041     // Returns a list of constant StarObject pointers which form the resultant path of Star Hop
0042     QList<const StarObject *> computePath_const(const SkyPoint &src, const SkyPoint &dest, float fov_, float maglim_,
0043                                                 QStringList *metadata = nullptr);
0044 
0045   private:
0046     /**
0047      * @short The cost function for hopping from current position to the a given star, in view of the final destination
0048      * @param curr Source SkyPoint
0049      * @param next Next point in the hop.
0050      * @note If 'next' is neither the starting point of the hop, nor
0051      * the ending point, it _has_ to be a StarObject. A dynamic cast
0052      * followed by a Q_ASSERT will ensure this.
0053      */
0054     float cost(const SkyPoint *curr, const SkyPoint *next);
0055 
0056     /**
0057      * @short For internal use by the A* Search Algorithm. Completes
0058      * the star-hop path. See https://en.wikipedia.org/wiki/A*_search_algorithm for details
0059      */
0060     void reconstructPath(SkyPoint const *curr_node);
0061 
0062     float fov { 0 };
0063     float maglim { 0 };
0064     QString starHopDirections;
0065     // Useful for internal computations
0066     SkyPoint const *start { nullptr };
0067     SkyPoint const *end { nullptr };
0068     QHash<const SkyPoint *, const SkyPoint *> came_from; // Used by the A* search algorithm
0069     QList<StarObject const *> result_path;
0070     QHash<SkyPoint const *, QString> patternNames; // if patterns were identified, they are added to this hash.
0071 };