bool FloatRect::intersects(const Line &line){ float scalar; glm::vec2 ray(line.x2 - line.x1, line.y2 - line.y1); float rayLength = length(ray.x, ray.y); scalar = skalar(this->x - line.x1, this->y - line.y1, ray.x, ray.y); float rayPoint1 = scalar /rayLength; scalar = skalar((this->x + this->w) - line.x1, this->y - line.y1, ray.x, ray.y); float rayPoint2 = scalar /rayLength; scalar = skalar(this->x - line.x1, (this->y + this->h) - line.y1, ray.x, ray.y); float rayPoint3 = scalar /rayLength; scalar = skalar((this->x + this->w) - line.x1, (this->y + this->h) - line.y1, ray.x, ray.y); float rayPoint4 = scalar /rayLength; float maxRay = std::fmax(std::fmax(rayPoint1, rayPoint2), std::fmax(rayPoint3, rayPoint4)); float minRay = std::fmin(std::fmin(rayPoint1, rayPoint2), std::fmin(rayPoint3, rayPoint4)); if(maxRay < 0.f || minRay > rayLength) return false; glm::vec2 ortho(ray.y, -ray.x); float orthoLength = length(ortho.x, ortho.y); scalar = skalar(this->x - line.x1, this->y - line.y1, ortho.x, ortho.y); float orthoPoint1 = scalar / orthoLength; scalar = skalar((this->x + this->w) - line.x1, this->y - line.y1, ortho.x, ortho.y); float orthoPoint2 = scalar / orthoLength; scalar = skalar(this->x - line.x1, (this->y + this->h) - line.y1, ortho.x, ortho.y); float orthoPoint3 = scalar / orthoLength; scalar = skalar((this->x + this->w) - line.x1, (this->y + this->h) - line.y1, ortho.x, ortho.y); float orthoPoint4 = scalar / orthoLength; float maxOrtho = std::fmax(std::fmax(orthoPoint1, orthoPoint2), std::fmax(orthoPoint3, orthoPoint4)); float minOrtho = std::fmin(std::fmin(orthoPoint1, orthoPoint2), std::fmin(orthoPoint3, orthoPoint4)); if(maxOrtho < 0.f || minOrtho > 0.f) return false; glm::vec2 rectX(this->w, 0); float rectXLength = rectX.x; scalar = skalar(line.x1 - this->x, line.y1 - this->y, rectX.x, rectX.y); float rectXPoint1 = scalar / rectXLength; scalar = skalar(line.x2 - this->x, line.y2 - this->y, rectX.x, rectX.y); float rectXPoint2 = scalar / rectXLength; float maxRectX = std::fmax(rectXPoint1, rectXPoint2); float minRectX = std::fmin(rectXPoint1, rectXPoint2); if(maxRectX < 0.f || minRectX > rectXLength) return false; glm::vec2 rectY(0, this->h); float rectYLength = rectY.y; scalar = skalar(line.x1 - this->x, line.y1 - this->y, rectY.x, rectY.y); float rectYPoint1 = scalar / rectYLength; scalar = skalar(line.x2 - this->x, line.y2 - this->y, rectY.x, rectY.y); float rectYPoint2 = scalar / rectYLength; float maxRectY = std::fmax(rectYPoint1, rectYPoint2); float minRectY = std::fmin(rectYPoint1, rectYPoint2); if(maxRectY < 0.f || minRectY > rectYLength) return false; return true; }
void CSignatureWnd::OnPaint() { CRect rect; GetClientRect(&rect); CPoint pt = rect.CenterPoint(); CPaintDC dc(this); // device context for painting CPen* p = dc.SelectObject(&m_Pen); int nMargin = rect.Width() / 20; int nWidth = 12; int nHeight = nWidth * 1.5; CRect rectX(0, 0, nWidth, nHeight); pt.x = nMargin; rectX.OffsetRect(pt.x, pt.y - (nHeight / 1)); pt = rectX.TopLeft(); dc.MoveTo(pt); pt = rectX.BottomRight(); dc.LineTo(pt); pt.x -= rectX.Width(); dc.MoveTo(pt); pt = rectX.TopLeft(); pt.x += rectX.Width(); dc.LineTo(pt); pt = rectX.BottomRight(); pt.Offset(3, 3); dc.MoveTo(pt); pt.x = rect.Width() - nMargin; dc.LineTo(pt); if (!m_nPoint) return; int i = 0; CPoint pZero(0,0); while (i < m_nPoint) { int k = 0, m = i; while (m_SaveLine[i] != pZero && i < m_nPoint) { i++; k++; } i++; dc.Polyline(&(m_SaveLine[m]), k); } dc.SelectObject(p); }