// Assume (x1, y1) is centre of box (most generally, line end at box) bool wxPolygonShape::GetPerimeterPoint(double x1, double y1, double x2, double y2, double *x3, double *y3) { int n = m_points->GetCount(); // First check for situation where the line is vertical, // and we would want to connect to a point on that vertical -- // oglFindEndForPolyline can't cope with this (the arrow // gets drawn to the wrong place). if ((m_attachmentMode == ATTACHMENT_MODE_NONE) && (x1 == x2)) { // Look for the point we'd be connecting to. This is // a heuristic... wxNode *node = m_points->GetFirst(); while (node) { wxRealPoint *point = (wxRealPoint *)node->GetData(); if (point->x == 0.0) { if ((y2 > y1) && (point->y > 0.0)) { *x3 = point->x + m_xpos; *y3 = point->y + m_ypos; return TRUE; } else if ((y2 < y1) && (point->y < 0.0)) { *x3 = point->x + m_xpos; *y3 = point->y + m_ypos; return TRUE; } } node = node->GetNext(); } } double *xpoints = new double[n]; double *ypoints = new double[n]; wxNode *node = m_points->GetFirst(); int i = 0; while (node) { wxRealPoint *point = (wxRealPoint *)node->GetData(); xpoints[i] = point->x + m_xpos; ypoints[i] = point->y + m_ypos; node = node->GetNext(); i ++; } oglFindEndForPolyline(n, xpoints, ypoints, x1, y1, x2, y2, x3, y3); delete[] xpoints; delete[] ypoints; return TRUE; }
void oglFindEndForBox(double width, double height, double x1, double y1, // Centre of box (possibly) double x2, double y2, // other end of line double *x3, double *y3) // End on box edge { double xvec[5]; double yvec[5]; xvec[0] = (double)(x1 - width/2.0); yvec[0] = (double)(y1 - height/2.0); xvec[1] = (double)(x1 - width/2.0); yvec[1] = (double)(y1 + height/2.0); xvec[2] = (double)(x1 + width/2.0); yvec[2] = (double)(y1 + height/2.0); xvec[3] = (double)(x1 + width/2.0); yvec[3] = (double)(y1 - height/2.0); xvec[4] = (double)(x1 - width/2.0); yvec[4] = (double)(y1 - height/2.0); oglFindEndForPolyline(5, xvec, yvec, x2, y2, x1, y1, x3, y3); }