[python/turtle] The turtle heading is in [0;360[

This commit is contained in:
Léa Saviot
2019-02-05 17:32:55 +01:00
committed by EmilieNumworks
parent a25b2a8ce5
commit 287dedabc0
2 changed files with 8 additions and 1 deletions

View File

@@ -175,6 +175,13 @@ void Turtle::viewDidDisappear() {
// Private functions
void Turtle::setHeadingPrivate(mp_float_t angle) {
// Put the angle in [0; 360[
mp_float_t angleLimit = 360;
m_heading = angle - ((angle >= 0 && angle < angleLimit) ? 0 : std::floor(angle/angleLimit) * angleLimit);
assert(m_heading >= 0 && m_heading < angleLimit);
}
KDPoint Turtle::position(mp_float_t x, mp_float_t y) const {
return KDPoint(floor(x + k_xOffset), floor(k_invertedYAxisCoefficient * y + k_yOffset));
}

View File

@@ -115,7 +115,7 @@ private:
KDColor m_color;
};
void setHeadingPrivate(mp_float_t angle) { m_heading = angle; }
void setHeadingPrivate(mp_float_t angle);
KDPoint position(mp_float_t x, mp_float_t y) const;
KDPoint position() const { return position(m_x, m_y); }