/**--------------------------------------------------------------------------<BR> C2DLine::Distance \brief Returns the distance from this to the point. <P>---------------------------------------------------------------------------*/ double C2DLine::Distance(const C2DPoint& TestPoint, C2DPoint* ptOnThis) const { C2DVector vP1ToPoint(point, TestPoint); double dLength = GetLength(); double dProjLength = vP1ToPoint.Dot(vector); if (dProjLength < 0) { if (ptOnThis != 0) *ptOnThis = point; return TestPoint.Distance(point); } else { dProjLength = dProjLength / dLength; if (dProjLength < dLength) { // The projection is on the line double dFactorOnLine = dProjLength / dLength; C2DPoint PtOnLine(point.x + vector.i * dFactorOnLine, point.y + vector.j * dFactorOnLine); if (ptOnThis != 0) *ptOnThis = PtOnLine; return TestPoint.Distance(PtOnLine); } else { if (ptOnThis != 0) *ptOnThis = GetPointTo(); return TestPoint.Distance( GetPointTo() ); } } }
/**--------------------------------------------------------------------------<BR> C2DLine::DistanceAsRay \brief Returns the distance from this to the point with this as a ray. <P>---------------------------------------------------------------------------*/ double C2DLine::DistanceAsRay(const C2DPoint& TestPoint, C2DPoint* ptOnThis) const { C2DVector vP1ToPoint(point, TestPoint); // The projection is on the line double dFactorOnLine = vP1ToPoint.Dot(vector) / (vector.i * vector.i + vector.j * vector.j); C2DPoint PtOnLine(point.x + vector.i * dFactorOnLine, point.y + vector.j * dFactorOnLine); if (ptOnThis != 0) *ptOnThis = PtOnLine; return TestPoint.Distance(PtOnLine); }
//new //需要增加一个标志参数,判断是在comview中,还是modelview中 STDMETHODIMP CMyCom1::PtInRgn(unsigned long point, unsigned long return_flag) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here BOOL flag = FALSE; if ( m_scale_flag ) { flag = upRgn.PtInRegion(*(CPoint*)point); if ( flag ) { *(BOOL *)return_flag = TRUE; return S_OK; } flag = PtOnLine(*(CPoint*)point, topPoint, bottomPoint); if ( flag ) { *(BOOL *)return_flag = TRUE; return S_OK; } flag = PtOnLine(*(CPoint*)point, leftPoint, rightPoint); if ( flag ) { *(BOOL *)return_flag = TRUE; return S_OK; } } flag = downRgn.PtInRegion(*(CPoint*)point); if ( flag ) *(BOOL *)return_flag = TRUE; else *(BOOL *)return_flag = FALSE; return S_OK; }