I'm doing MFC project now to study and given concept of this is "to reinvent the wheel". So, I should not use CRect or ArcTo and etcs. Make every basic functions by my own.
I made a getDIstance function, and I got an error that detected the shape on all the straight lines extended from each side of the shape. Considering that the error detected in Arc does not occur in Circles (and some other hints), it seems to be a matter of variables related to angles, but further estimation is difficult.
The basic form of my getDistance is like this
c++
double Line::getDistance(MyPoint point) {
double a = m_p2.y - m_p1.y;
double b = m_p1.x - m_p2.x;
double c = (m_p2.x * m_p1.y) - (m_p1.x * m_p2.y);
double dist = std:: abs((a * point.x) + (b * point.y) + c) / std::sqrt((a * a + b * b));
return dist;
}
and it used like this
SHAPE* CMFCPresentingView::SelectOperation(MyPoint point) {
CMFCPresentingDoc* pDoc = GetDocument();
const int range = 5;
SHAPE* shape = nullptr;
if (pDoc->m_ShapeListCount == 0) return nullptr;
for (int i = 0; i < pDoc->m_ShapeListCount; i++) {
double dist = pDoc->m_ShapeList[i]->getDistance(point);
if (dist < range) {
m_Found = true;
m_EditShapeNo = i;
m_MoveBase = point;
pDoc->m_ShapeList[i]->m_isSelected = true;
shape = pDoc->m_ShapeList[i];
return shape;
}
}
return nullptr;
}
what point I've mistaken? I don't really get it.
click nearby the line and 'select' to change values on mouse move. simply, pick and move the shapes.