49 if ( mRatio.width() > 0 && mRatio.height() > 0 )
51 double width = std::fabs( p.
x() - mStartPoint.
x() );
52 double height = width * ( mRatio.width() / mRatio.height() );
53 if ( p.
y() - mStartPoint.
y() < 0 )
55 p.
setY( mStartPoint.
y() + height );
59 calculateEndPoint( mEndPoint );
66 mEndPoint = mStartPoint;
78 calculateEndPoint( mEndPoint );
88 if ( mStartPoint.
x() != mEndPoint.
x() && mStartPoint.
y() != mEndPoint.
y() )
98 void QgsMapToolExtent::calculateEndPoint(
QgsPointXY &point )
100 if ( mRatio.width() > 0 && mRatio.height() > 0 )
102 double width = std::fabs( point.
x() - mStartPoint.
x() );
103 double height = width * mRatio.height() / mRatio.width();
104 if ( point.
y() - mStartPoint.
y() < 0 )
106 point.
setY( mStartPoint.
y() + height );
110 void QgsMapToolExtent::drawExtent()
A rectangle specified with double values.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
A class to represent a 2D point.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
Map canvas is a class for displaying all GIS data types on a canvas.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
A class for drawing transient features (e.g.
void setY(double y)
Sets the y value of the point.
double xMinimum() const
Returns the x minimum value (left side of rectangle).