|
|
4df9cd |
|
|
|
4df9cd |
|
|
|
4df9cd |
#include "guidelineline.h"
|
|
|
4df9cd |
|
|
|
4df9cd |
// TnzCore includes
|
|
|
4df9cd |
#include "tgl.h"
|
|
|
4df9cd |
|
|
|
4df9cd |
|
|
|
4df9cd |
//*****************************************************************************************
|
|
|
4df9cd |
// TGuidelineLineBase implementation
|
|
|
4df9cd |
//*****************************************************************************************
|
|
|
4df9cd |
|
|
|
8074a5 |
TGuidelineLineBase::TGuidelineLineBase(bool enabled, double magnetism, const TPointD &p0, const TPointD &p1):
|
|
|
8074a5 |
TGuideline(enabled, magnetism), p0(p0), p1(p1) { }
|
|
|
4df9cd |
|
|
|
4df9cd |
TPointD
|
|
|
4df9cd |
TGuidelineLineBase::calcDirection(const TPointD &p0, const TPointD &p1) {
|
|
|
4df9cd |
TPointD d = p1 - p0;
|
|
|
4df9cd |
double k = norm2(d);
|
|
|
362052 |
return k > TConsts::epsilon*TConsts::epsilon ? d*(1.0/sqrt(k)) : TPointD();
|
|
|
4df9cd |
}
|
|
|
4df9cd |
|
|
|
4df9cd |
void
|
|
|
4df9cd |
TGuidelineLineBase::truncateInfiniteLine(const TRectD &bounds, TPointD &p0, TPointD &p1) {
|
|
|
4df9cd |
TPointD d = p0 - p1;
|
|
|
4df9cd |
TDimensionD size = bounds.getSize();
|
|
|
4df9cd |
if (fabs(d.x)*bounds.y0 > bounds.x0*fabs(d.y)) {
|
|
|
4df9cd |
// horizontal
|
|
|
4df9cd |
if (fabs(d.x) < TConsts::epsilon) return;
|
|
|
4df9cd |
double k = d.y/d.x;
|
|
|
4df9cd |
p1 = TPointD(bounds.x1, p0.y + k*(bounds.x1 - p0.x));
|
|
|
4df9cd |
p0 = TPointD(bounds.x0, p0.y + k*(bounds.x0 - p0.x));
|
|
|
4df9cd |
} else {
|
|
|
4df9cd |
// vertical
|
|
|
4df9cd |
if (fabs(d.y) < TConsts::epsilon) return;
|
|
|
4df9cd |
double k = d.x/d.y;
|
|
|
4df9cd |
p1 = TPointD(p0.x + k*(bounds.y1 - p0.y), bounds.y1);
|
|
|
4df9cd |
p0 = TPointD(p0.x + k*(bounds.y0 - p0.y), bounds.y0);
|
|
|
4df9cd |
}
|
|
|
4df9cd |
}
|
|
|
4df9cd |
|
|
|
4df9cd |
void
|
|
|
8074a5 |
TGuidelineLineBase::drawInliniteLine(const TPointD &p0, const TPointD &p1, bool ray, bool active, bool enabled) const {
|
|
|
249386 |
TAffine4 modelview, projection;
|
|
|
4df9cd |
glGetDoublev(GL_MODELVIEW_MATRIX, modelview.a);
|
|
|
249386 |
glGetDoublev(GL_PROJECTION_MATRIX, projection.a);
|
|
|
4df9cd |
|
|
|
249386 |
TAffine matrix = (projection*modelview).get2d();
|
|
|
4df9cd |
TPointD pp0 = matrix*p0;
|
|
|
4df9cd |
TPointD pp1 = matrix*p1;
|
|
|
4df9cd |
truncateInfiniteLine(TRectD(-1.0, -1.0, 1.0, 1.0), pp0, pp1);
|
|
|
4df9cd |
|
|
|
249386 |
double pixelSize = sqrt(tglGetPixelSize2());
|
|
|
4df9cd |
TAffine matrixInv = matrix.inv();
|
|
|
8074a5 |
drawSegment((ray ? p0 : matrixInv*pp0), matrixInv*pp1, pixelSize, active, enabled);
|
|
|
4df9cd |
}
|
|
|
4df9cd |
|
|
|
4df9cd |
|
|
|
4df9cd |
//*****************************************************************************************
|
|
|
4df9cd |
// TGuidelineLine implementation
|
|
|
4df9cd |
//*****************************************************************************************
|
|
|
4df9cd |
|
|
|
8074a5 |
TGuidelineLine::TGuidelineLine(bool enabled, double magnetism, const TPointD &p0, const TPointD &p1):
|
|
|
8074a5 |
TGuidelineLineBase(enabled, magnetism, p0, p1),
|
|
|
4df9cd |
dir(calcDirection(p0, p1)),
|
|
|
4df9cd |
dist(norm(p1 - p0)) { }
|
|
|
4df9cd |
|
|
|
4df9cd |
TTrackPoint
|
|
|
4df9cd |
TGuidelineLine::transformPoint(const TTrackPoint &point) const {
|
|
|
4df9cd |
TTrackPoint p(point);
|
|
|
4df9cd |
p.position = p0 + dir * std::max(0.0, std::min(dist, ((p.position - p0)*dir)));
|
|
|
4df9cd |
return p;
|
|
|
4df9cd |
}
|
|
|
4df9cd |
|
|
|
4df9cd |
void
|
|
|
8074a5 |
TGuidelineLine::draw(bool active, bool enabled) const
|
|
|
8074a5 |
{ drawSegment(p0, p1, sqrt(tglGetPixelSize2()), active, enabled); }
|
|
|
4df9cd |
|
|
|
4df9cd |
|
|
|
4df9cd |
//*****************************************************************************************
|
|
|
4df9cd |
// TGuidelineInfiniteLine implementation
|
|
|
4df9cd |
//*****************************************************************************************
|
|
|
4df9cd |
|
|
|
8074a5 |
TGuidelineInfiniteLine::TGuidelineInfiniteLine(bool enabled, double magnetism, const TPointD &p0, const TPointD &p1):
|
|
|
8074a5 |
TGuidelineLineBase(enabled, magnetism, p0, p1),
|
|
|
4df9cd |
dir(calcDirection(p0, p1)) { }
|
|
|
4df9cd |
|
|
|
4df9cd |
TTrackPoint
|
|
|
4df9cd |
TGuidelineInfiniteLine::transformPoint(const TTrackPoint &point) const {
|
|
|
4df9cd |
TTrackPoint p(point);
|
|
|
4df9cd |
p.position = p0 + dir * ((p.position - p0)*dir);
|
|
|
4df9cd |
return p;
|
|
|
4df9cd |
}
|
|
|
4df9cd |
|
|
|
4df9cd |
void
|
|
|
8074a5 |
TGuidelineInfiniteLine::draw(bool active, bool enabled) const
|
|
|
8074a5 |
{ drawInliniteLine(p0, p1, false, active, enabled); }
|
|
|
4df9cd |
|
|
|
4df9cd |
|
|
|
4df9cd |
//*****************************************************************************************
|
|
|
4df9cd |
// TGuidelineRay implementation
|
|
|
4df9cd |
//*****************************************************************************************
|
|
|
4df9cd |
|
|
|
8074a5 |
TGuidelineRay::TGuidelineRay(bool enabled, double magnetism, const TPointD &p0, const TPointD &p1):
|
|
|
8074a5 |
TGuidelineLineBase(enabled, magnetism, p0, p1),
|
|
|
4df9cd |
dir(calcDirection(p0, p1)) { }
|
|
|
4df9cd |
|
|
|
4df9cd |
TTrackPoint
|
|
|
4df9cd |
TGuidelineRay::transformPoint(const TTrackPoint &point) const {
|
|
|
4df9cd |
TTrackPoint p(point);
|
|
|
4df9cd |
p.position = p0 + dir * std::max(0.0, ((p.position - p0)*dir));
|
|
|
4df9cd |
return p;
|
|
|
4df9cd |
}
|
|
|
4df9cd |
|
|
|
4df9cd |
void
|
|
|
8074a5 |
TGuidelineRay::draw(bool active, bool enabled) const
|
|
|
8074a5 |
{ drawInliniteLine(p0, p1, true, active, enabled); }
|
|
|
4df9cd |
|