[Kstars-devel] KDE/kdeedu/kstars/kstars/skycomponents
Jason Harris
kstars at 30doradus.org
Sun Nov 13 07:16:03 CET 2005
SVN commit 480085 by harris:
Adding objectNearest( SkyPoint *p, double &maxrad ) to the Components
This function looks for SkyObjects in the Component that are closer to p
than maxrad. If such an object is found, a pointer to it is returned,
and its angular distance from p is returned-by-reference through maxrad.
If no object is found to be nearer to p than maxrad, then it returns 0.
SkyComposite::objectNearest() executes objectNearest() for each of its
child Components, and returns the overall nearest SkyObject.
The result is that calling skyComposite()->objectNearest( p, maxrad )
will return a pointer to the object that is closest to p.
CCMAIL: kstars-devel at kde.org
M +40 -0 deepskycomponent.cpp
M +4 -1 deepskycomponent.h
M +14 -0 listcomponent.cpp
M +3 -1 listcomponent.h
M +10 -0 singlecomponent.cpp
M +3 -1 singlecomponent.h
M +4 -0 skycomponent.cpp
M +20 -1 skycomponent.h
M +12 -0 skycomposite.cpp
M +10 -1 skycomposite.h
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/deepskycomponent.cpp #480084:480085
@@ -306,3 +306,43 @@
//No object found
return 0;
}
+
+SkyObject* DeepSkyComponent::objectNearest( SkyPoint *p, double &maxrad ) {
+ SkyObject *oBest = 0;
+ double r;
+
+ foreach ( SkyObject *o, m_MessierList ) {
+ r = o->angularDistanceTo( p ).Degrees();
+ if ( r < maxrad ) {
+ maxrad = r;
+ oBest = o;
+ }
+ }
+
+ foreach ( SkyObject *o, m_NGCList ) {
+ r = o->angularDistanceTo( p ).Degrees();
+ if ( r < maxrad ) {
+ maxrad = r;
+ oBest = o;
+ }
+ }
+
+ foreach ( SkyObject *o, m_ICList ) {
+ r = o->angularDistanceTo( p ).Degrees();
+ if ( r < maxrad ) {
+ maxrad = r;
+ oBest = o;
+ }
+ }
+
+ foreach ( SkyObject *o, m_OtherList ) {
+ r = o->angularDistanceTo( p ).Degrees();
+ if ( r < maxrad ) {
+ maxrad = r;
+ oBest = o;
+ }
+ }
+
+ return oBest;
+}
+
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/deepskycomponent.h #480084:480085
@@ -39,6 +39,7 @@
class SkyMap;
class KSNumbers;
class DeepSkyObject;
+class SkyPoint;
class DeepSkyComponent: public SkyComponent
{
@@ -67,8 +68,10 @@
*@return a pointer to the SkyObject whose name matches
*the argument, or a NULL pointer if no match was found.
*/
- SkyObject* findByName( const QString &name );
+ virtual SkyObject* findByName( const QString &name );
+ virtual SkyObject* objectNearest( SkyPoint *p, double &maxrad );
+
private:
/**
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/listcomponent.cpp #480084:480085
@@ -52,3 +52,17 @@
//No object found
return 0;
}
+
+SkyObject* ListComponent::objectNearest( SkyPoint *p, double &maxrad ) {
+ SkyObject *oBest = 0;
+
+ foreach ( SkyObject *o, objectList() ) {
+ double r = o->angularDistanceTo( p ).Degrees();
+ if ( r < maxrad ) {
+ oBest = o;
+ maxrad = r;
+ }
+ }
+
+ return oBest;
+}
\ No newline at end of file
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/listcomponent.h #480084:480085
@@ -69,8 +69,10 @@
*/
virtual void update( KStarsData *data, KSNumbers *num=0 );
- SkyObject* findByName( const QString &name );
+ virtual SkyObject* findByName( const QString &name );
+ virtual SkyObject* objectNearest( SkyPoint *p, double &maxrad );
+
QList<SkyObject*>& objectList() { return ObjectList; }
private:
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/singlecomponent.cpp #480084:480085
@@ -49,3 +49,13 @@
return 0;
}
+
+SkyObject* SingleComponent::objectNearest( SkyPoint *p, double &maxrad ) {
+ double r = skyObject()->angularDistanceTo( p ).Degrees();
+ if ( r < maxrad ) {
+ maxrad = r;
+ return skyObject();
+ }
+
+ return 0;
+}
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/singlecomponent.h #480084:480085
@@ -71,8 +71,10 @@
*/
virtual void update( KStarsData *data, KSNumbers *num=0 );
- SkyObject* findByName( const QString &name );
+ virtual SkyObject* findByName( const QString &name );
+ virtual SkyObject* objectNearest( SkyPoint *p, double &maxrad );
+
SkyObject* skyObject() { return m_StoredObject; }
void setStoredObject( SkyObject *o ) { m_StoredObject = o; }
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skycomponent.cpp #480084:480085
@@ -74,6 +74,10 @@
parent()->emitProgressText( message );
}
+SkyObject* SkyComponent::findByName( const QString & ) { return 0; }
+
+SkyObject* SkyComponent::objectNearest( SkyPoint *, double & ) { return 0; }
+
//Reimplemented in Solar system components
bool SkyComponent::addTrail( SkyObject * ) { return false; }
bool SkyComponent::hasTrail( SkyObject *, bool & ) { return false; }
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skycomponent.h #480084:480085
@@ -27,6 +27,7 @@
class KStars;
class KStarsData;
class SkyObject;
+class SkyPoint;
/**
*@short static placeholder function for SkyComponents that don't
@@ -154,12 +155,30 @@
*the argument, or a NULL pointer if no match was found.
*@note This function simply returns the NULL pointer; it
*is reimplemented in various sub-classes
+ *@sa SkyComposite::findByName()
*@sa SingleComponent::findByName()
*@sa ListComponent::findByName()
*@sa DeepSkyComponent::findByName()
*/
- SkyObject* findByName( const QString &name );
+ virtual SkyObject* findByName( const QString &name );
+ /**
+ *@short Find the SkyObject nearest the given SkyPoint
+ *
+ *Look for a SkyObject that is nearer to point p than maxrad.
+ *If one is found, then maxrad is reset to the separation of the new nearest object.
+ *@p p pointer to the SkyPoint to search around
+ *@p maxrad reference to current search radius
+ *@return a pointer to the nearest SkyObject
+ *@note This function simply returns a NULL pointer; it is
+ *reimplemented in various sub-classes.
+ *@sa SkyComposite::objectNearest()
+ *@sa SingleComponent::objectNearest()
+ *@sa ListComponent::objectNearest()
+ *@sa DeepSkyComponent::objectNearest()
+ */
+ virtual SkyObject* objectNearest( SkyPoint *p, double &maxrad );
+
void emitProgressText( const QString &message );
protected:
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skycomposite.cpp #480084:480085
@@ -80,3 +80,15 @@
}
return 0;
}
+
+SkyObject* SkyComposite::objectNearest( SkyPoint *p, double &maxrad ) {
+ SkyObject *oTry = 0;
+ SkyObject *oBest = 0;
+
+ foreach ( SkyComponent *comp, components() ) {
+ oTry = comp->objectNearest( p, maxrad );
+ if ( oTry ) oBest = oTry; //found a closer object
+ }
+
+ return oBest; //will be 0 if no object nearer than maxrad was found
+}
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skycomposite.h #480084:480085
@@ -164,8 +164,17 @@
*@return a pointer to the SkyObject whose name matches
*the argument, or a NULL pointer if no match was found.
*/
- SkyObject* findByName( const QString &name );
+ virtual SkyObject* findByName( const QString &name );
+ /**
+ *@short Identify the nearest SkyObject to the given SkyPoint,
+ *among the children of this SkyComposite
+ *@p p pointer to the SkyPoint around which to search.
+ *@p maxrad reference to current search radius
+ *@return a pointer to the nearest SkyObject
+ */
+ virtual SkyObject* objectNearest( SkyPoint *p, double &maxrad );
+
QList<SkyComponent*>& components() { return m_Components; }
private:
More information about the Kstars-devel
mailing list