[Kstars-devel] KDE/kdeedu/kstars/kstars/skycomponents

Jason Harris kstars at 30doradus.org
Tue Mar 21 07:35:35 CET 2006


SVN commit 520886 by harris:

Horizon fixes:
+ Fix crash when horizon moves off the top of the screen (caused pAnchor 
to be accessed as a null pointer)

+ Draw compass labels and "Horizon" label with correct color when in 
Equatorial coords.

+ Correct positioning of "Horizon" label in Equatorial coords mode.

CCMAIL: kstars-devel at kde.org



 M  +84 -78    horizoncomponent.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/horizoncomponent.cpp #520885:520886
@@ -83,9 +83,12 @@
 		psky.setBrush( QColor ( ks->data()->colorScheme()->colorNamed( "HorzColor" ) ) );
 	else
 		psky.setBrush( Qt::NoBrush );
-	
-	double daz = 0.5*Width*57.3/Options::zoomFactor(); //center to edge, in degrees
+
+	double daz = 90.;
+	if ( Options::useAltAz() )
+		daz = 0.5*Width*57.3/Options::zoomFactor(); //center to edge, in degrees
 	if ( daz > 90.0 ) daz = 90.0;
+
 	double az1 = map->focus()->az()->Degrees() - daz;
 	double az2 = map->focus()->az()->Degrees() + daz;
 
@@ -221,85 +224,93 @@
 		psky.drawPolygon( groundPoly );
 	}
 
+	//Set color for compass labels and "Horizon" label.
+	if ( Options::showGround() && Options::useAltAz() )
+		psky.setPen( QColor ( ks->data()->colorScheme()->colorNamed( "CompassColor" ) ) );
+	else
+		psky.setPen( QColor ( ks->data()->colorScheme()->colorNamed( "HorzColor" ) ) );
+
 	drawCompassLabels( ks, psky, scale );
 
 	//Draw Horizon name label
 	//pAnchor contains the last point of the Horizon before it went offcreen 
 	//on the right/top/bottom edge.  oAnchor2 is the next point after oAnchor.
-	int iAnchor = pointList().indexOf( pAnchor );
-	if ( iAnchor == pointList().size()-1 ) iAnchor = 0;
-	else iAnchor++;
-	pAnchor2 = pointList().at( iAnchor );
-
-	QPointF o1 = map->getXY( pAnchor, Options::useAltAz(), false, scale );
-	QPointF o2 = map->getXY( pAnchor2, Options::useAltAz(), false, scale );
-
-	float x1, x2;
-	//there are 3 possibilities:  (o2.x() > width()); (o2.y() < 0); (o2.y() > height())
-	if ( o2.x() > Width ) {
-		x1 = (Width - o1.x())/(o2.x() - o1.x());
-		x2 = (o2.x() - Width)/(o2.x() - o1.x());
-	} else if ( o2.y() < 0 ) {
-		x1 = o1.y()/(o1.y() - o2.y());
-		x2 = -1.0*o2.y()/(o1.y() - o2.y());
-	} else if ( o2.y() > Height ) {
-		x1 = (Height - o1.y())/(o2.y() - o1.y());
-		x2 = (o2.y() - Height)/(o2.y() - o1.y());
-	} else {  //should never get here
-		x1 = 0.0;
-		x2 = 1.0;
-	}
-
-	//ra0 is the exact RA at which the Horizon intersects a screen edge
-	double ra0 = x1*pAnchor2->ra()->Hours() + x2*pAnchor->ra()->Hours();
-	//dec0 is the exact Dec at which the Horizon intersects a screen edge
-	double dec0 = x1*pAnchor2->dec()->Degrees() + x2*pAnchor->dec()->Degrees();
-
-	//LabelPoint is offset from the anchor point by -2.0 degrees in azimuth
-	//and -0.4 degree altitude, scaled by 2000./zoomFactor so that they are
-	//independent of zoom.
-	SkyPoint LabelPoint(ra0, dec0);
-	LabelPoint.EquatorialToHorizontal( ks->data()->lst(), ks->data()->geo()->lat() );
-	LabelPoint.setAlt( LabelPoint.alt()->Degrees() - 800./Options::zoomFactor() );
-	LabelPoint.setAz( LabelPoint.az()->Degrees() - 4000./Options::zoomFactor() );
-	LabelPoint.HorizontalToEquatorial( ks->data()->lst(), ks->data()->geo()->lat() );
-
-	if ( o.x() > Width || o.x() < 0 ) {
-		//the LabelPoint is offscreen.  Either we are in the Southern hemisphere,
-		//or the sky is rotated upside-down.  Use an azimuth offset of +2.0 degrees
-	LabelPoint.setAlt( LabelPoint.alt()->Degrees() + 1600./Options::zoomFactor() );
-		LabelPoint.setAz( LabelPoint.az()->Degrees() + 8000./Options::zoomFactor() );
+	if ( pAnchor ) {
+		int iAnchor = pointList().indexOf( pAnchor );
+		if ( iAnchor == pointList().size()-1 ) iAnchor = 0;
+		else iAnchor++;
+		pAnchor2 = pointList().at( iAnchor );
+	
+		QPointF o1 = map->getXY( pAnchor, Options::useAltAz(), false, scale );
+		QPointF o2 = map->getXY( pAnchor2, Options::useAltAz(), false, scale );
+		
+		float x1, x2;
+		//there are 3 possibilities:  (o2.x() > width()); (o2.y() < 0); (o2.y() > height())
+		if ( o2.x() > Width ) {
+			x1 = (Width - o1.x())/(o2.x() - o1.x());
+			x2 = (o2.x() - Width)/(o2.x() - o1.x());
+		} else if ( o2.y() < 0 ) {
+			x1 = o1.y()/(o1.y() - o2.y());
+			x2 = -1.0*o2.y()/(o1.y() - o2.y());
+		} else if ( o2.y() > Height ) {
+			x1 = (Height - o1.y())/(o2.y() - o1.y());
+			x2 = (o2.y() - Height)/(o2.y() - o1.y());
+		} else {  //should never get here
+			x1 = 0.0;
+			x2 = 1.0;
+		}
+	
+		//ra0 is the exact RA at which the Horizon intersects a screen edge
+		double ra0 = x1*pAnchor2->ra()->Hours() + x2*pAnchor->ra()->Hours();
+		//dec0 is the exact Dec at which the Horizon intersects a screen edge
+		double dec0 = x1*pAnchor2->dec()->Degrees() + x2*pAnchor->dec()->Degrees();
+	
+		//LabelPoint is offset from the anchor point by -2.0 degrees in azimuth
+		//and -0.4 degree altitude, scaled by 2000./zoomFactor so that they are
+		//independent of zoom.
+		SkyPoint LabelPoint(ra0, dec0);
+		LabelPoint.EquatorialToHorizontal( ks->data()->lst(), ks->data()->geo()->lat() );
+		LabelPoint.setAlt( LabelPoint.alt()->Degrees() - 800./Options::zoomFactor() );
+		LabelPoint.setAz( LabelPoint.az()->Degrees() - 4000./Options::zoomFactor() );
 		LabelPoint.HorizontalToEquatorial( ks->data()->lst(), ks->data()->geo()->lat() );
-	}
+	
+		o = map->getXY( &LabelPoint, Options::useAltAz(), false, scale );
 
-	//p2 is a skypoint offset from LabelPoint by +/-1 degree azimuth (scaled by
-	//2000./zoomFactor).  We use p2 to determine the rotation angle for the
-	//Horizon label, which we want to be parallel to the line between LabelPoint and p2.
-	SkyPoint p2( LabelPoint.ra(), LabelPoint.dec() );
-	p2.EquatorialToHorizontal( ks->data()->lst(), ks->data()->geo()->lat() );
-	p2.setAz( p2.az()->Degrees() + 2000./Options::zoomFactor() );
-	p2.HorizontalToEquatorial( ks->data()->lst(), ks->data()->geo()->lat() );
-
-	//o and o2 are the screen positions of LabelPoint and p2
-	o = map->getXY( &LabelPoint, Options::useAltAz(), false, scale );
-	o2 = map->getXY( &p2, Options::useAltAz(), false, scale );
-
-	float sx = o.x() - o2.x();
-	float sy = o.y() - o2.y();
-	float angle;
-	if ( sx ) {
-		angle = atan( sy/sx )*180.0/dms::PI;
-	} else {
-		angle = 90.0;
-		if ( sy < 0 ) angle = -90.0;
+		if ( o.x() > Width || o.x() < 0 ) {
+			//the LabelPoint is offscreen.  Either we are in the Southern hemisphere,
+			//or the sky is rotated upside-down.  Use an azimuth offset of +2.0 degrees
+		LabelPoint.setAlt( LabelPoint.alt()->Degrees() + 1600./Options::zoomFactor() );
+			LabelPoint.setAz( LabelPoint.az()->Degrees() + 8000./Options::zoomFactor() );
+			LabelPoint.HorizontalToEquatorial( ks->data()->lst(), ks->data()->geo()->lat() );
+		}
+	
+		//p2 is a skypoint offset from LabelPoint by +/-1 degree azimuth (scaled by
+		//2000./zoomFactor).  We use p2 to determine the rotation angle for the
+		//Horizon label, which we want to be parallel to the line between LabelPoint and p2.
+		SkyPoint p2( LabelPoint.ra(), LabelPoint.dec() );
+		p2.EquatorialToHorizontal( ks->data()->lst(), ks->data()->geo()->lat() );
+		p2.setAz( p2.az()->Degrees() + 2000./Options::zoomFactor() );
+		p2.HorizontalToEquatorial( ks->data()->lst(), ks->data()->geo()->lat() );
+	
+		o2 = map->getXY( &p2, Options::useAltAz(), false, scale );
+	
+		float sx = o.x() - o2.x();
+		float sy = o.y() - o2.y();
+		float angle;
+		if ( sx ) {
+			angle = atan( sy/sx )*180.0/dms::PI;
+		} else {
+			angle = 90.0;
+			if ( sy < 0 ) angle = -90.0;
+		}
+	
+		//Finally, draw the "Horizon" label at the determined location and angle
+		psky.save();
+		psky.translate( o.x(), o.y() );
+		psky.rotate( double( angle ) );  //rotate the coordinate system
+		psky.drawText( 0, 0, i18n( "Horizon" ) );
+		psky.restore(); //reset coordinate system
 	}
-
-	//Finally, draw the "Horizon" label at the determined location and angle
-	psky.save();
-	psky.translate( o.x(), o.y() );
-	psky.rotate( double( angle ) );  //rotate the coordinate system
-	psky.drawText( 0, 0, i18n( "Horizon" ) );
-	psky.restore(); //reset coordinate system
 }
 
 
@@ -310,11 +321,6 @@
 	float Width = scale * map->width();
 	float Height = scale * map->height();
 
-	if ( Options::showGround() )
-		psky.setPen( QColor ( ks->data()->colorScheme()->colorNamed( "CompassColor" ) ) );
-	else
-		psky.setPen( QColor ( ks->data()->colorScheme()->colorNamed( "HorzColor" ) ) );
-
 	//North
 	c.setAz( 359.99 );
 	c.setAlt( 0.0 );


More information about the Kstars-devel mailing list