- x += (this->ps().x4() - this->ps().x1()) / 2;
- x += (this->gc().df() + 0.01) * cos(h + dts);
- y += (this->ps().y4() - this->ps().y1()) / 2;
- y += (this->gc().df() + 0.01) * sin(h + dts);
- if (this->ps().right())
- h += M_PI / 2;
- else
- h -= M_PI / 2;
+ dts = atan2(
+ this->ps().y2() - this->ps().y1(),
+ this->ps().x2() - this->ps().x1()
+ );
+ dts *= 1.01; // precision workaround
+ if (std::abs(dts - this->ps().heading()) < M_PI / 2) {
+ x = this->ps().x4();
+ y = this->ps().y4();
+ h = dts;
+ x += (this->gc().dr() + 0.01) * cos(h);
+ y += (this->gc().dr() + 0.01) * sin(h);
+ if (this->ps().right())
+ dts -= M_PI / 2;
+ else
+ dts += M_PI / 2;
+ x += (this->gc().w() / 2 + 0.01) * cos(dts);
+ y += (this->gc().w() / 2 + 0.01) * sin(dts);
+ } else {
+ h = dts + M_PI;
+ x += -(this->gc().df() + 0.01) * cos(h);
+ y += -(this->gc().df() + 0.01) * sin(h);
+ if (this->ps().right())
+ dts += M_PI / 2;
+ else
+ dts -= M_PI / 2;
+ x += (this->gc().w() / 2 + 0.01) * cos(dts);
+ y += (this->gc().w() / 2 + 0.01) * sin(dts);
+ }