+// Assuming the attachment lies along a vertical or horizontal line,
+// calculate the position on that point.
+wxRealPoint wxShape::CalcSimpleAttachment(const wxRealPoint& pt1, const wxRealPoint& pt2,
+ int nth, int noArcs, wxLineShape* line)
+{
+ bool isEnd = (line && line->IsEnd(this));
+
+ // Are we horizontal or vertical?
+ bool isHorizontal = (oglRoughlyEqual(pt1.y, pt2.y) == TRUE);
+
+ double x, y;
+
+ if (isHorizontal)
+ {
+ wxRealPoint firstPoint, secondPoint;
+ if (pt1.x > pt2.x)
+ {
+ firstPoint = pt2;
+ secondPoint = pt1;
+ }
+ else
+ {
+ firstPoint = pt1;
+ secondPoint = pt2;
+ }
+
+ if (m_spaceAttachments)
+ {
+ if (line && (line->GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE))
+ {
+ // Align line according to the next handle along
+ wxRealPoint *point = line->GetNextControlPoint(this);
+ if (point->x < firstPoint.x)
+ x = firstPoint.x;
+ else if (point->x > secondPoint.x)
+ x = secondPoint.x;
+ else
+ x = point->x;
+ }
+ else
+ x = firstPoint.x + (nth + 1)*(secondPoint.x - firstPoint.x)/(noArcs + 1);
+ }
+ else x = (secondPoint.x - firstPoint.x)/2.0; // Midpoint
+
+ y = pt1.y;
+ }
+ else
+ {
+ wxASSERT( oglRoughlyEqual(pt1.x, pt2.x) == TRUE );
+
+ wxRealPoint firstPoint, secondPoint;
+ if (pt1.y > pt2.y)
+ {
+ firstPoint = pt2;
+ secondPoint = pt1;
+ }
+ else
+ {
+ firstPoint = pt1;
+ secondPoint = pt2;
+ }
+
+ if (m_spaceAttachments)
+ {
+ if (line && (line->GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE))
+ {
+ // Align line according to the next handle along
+ wxRealPoint *point = line->GetNextControlPoint(this);
+ if (point->y < firstPoint.y)
+ y = firstPoint.y;
+ else if (point->y > secondPoint.y)
+ y = secondPoint.y;
+ else
+ y = point->y;
+ }
+ else
+ y = firstPoint.y + (nth + 1)*(secondPoint.y - firstPoint.y)/(noArcs + 1);
+ }
+ else y = (secondPoint.y - firstPoint.y)/2.0; // Midpoint
+
+ x = pt1.x;
+ }
+
+ return wxRealPoint(x, y);
+}
+
+// Return the zero-based position in m_lines of line.
+int wxShape::GetLinePosition(wxLineShape* line)
+{
+ int i = 0;
+ for (i = 0; i < m_lines.Number(); i++)
+ if ((wxLineShape*) (m_lines.Nth(i)->Data()) == line)
+ return i;
+
+ return 0;
+}
+