/// <summary> /// Returns the y-coordinate of the center point for automatic routing. /// </summary> /// <returns>Returns the y-coordinate of the routing center point.</returns> public double GetRoutingCenterY(mxCellState state) { float f = (state.Style != null) ? mxUtils.GetFloat(state. Style, mxConstants.STYLE_ROUTING_CENTER_Y) : 0; return(state.GetCenterY() + f * state.Height); }
/// <summary> /// Returns the nearest point in the list of absolute points or the center /// of the opposite terminal. /// </summary> /// <param name="edge">State that represents the edge.</param> /// <param name="opposite">State that represents the opposite terminal.</param> /// <param name="source">Boolean indicating if the next point for the source or target /// should be returned.</param> public mxPoint GetNextPoint(mxCellState edge, mxCellState opposite, bool source) { List <mxPoint> pts = edge.AbsolutePoints; mxPoint point = null; if (pts != null && pts.Count >= 2) { int count = pts.Count; int index = (source) ? Math.Min(1, count - 1) : Math.Max(0, count - 2); point = pts[index]; } if (point == null && opposite != null) { point = new mxPoint(opposite.GetCenterX(), opposite.GetCenterY()); } return(point); }
/// <summary> /// Returns the absolute point on the edge for the given relative /// geometry as a point. The edge is represented by the given cell state. /// </summary> /// <param name="state">Represents the state of the parent edge.</param> /// <param name="geometry">Represents the relative location.</param> public mxPoint GetPoint(mxCellState state, mxGeometry geometry) { double x = state.GetCenterX(); double y = state.GetCenterY(); if (state.Segments != null && (geometry == null || geometry.Relative)) { double gx = (geometry != null) ? geometry.X / 2 : 0; int pointCount = state.AbsolutePoints.Count; double dist = (gx + 0.5) * state.Length; double[] segments = state.Segments; double segment = segments[0]; double length = 0; int index = 1; while (dist > length + segment && index < pointCount - 1) { length += segment; segment = segments[index++]; } double factor = (segment == 0) ? 0 : (dist - length) / segment; mxPoint p0 = state.AbsolutePoints[index - 1]; mxPoint pe = state.AbsolutePoints[index]; if (p0 != null && pe != null) { double gy = 0; double offsetX = 0; double offsetY = 0; if (geometry != null) { gy = geometry.Y; mxPoint offset = geometry.Offset; if (offset != null) { offsetX = offset.X; offsetY = offset.Y; } } double dx = pe.X - p0.X; double dy = pe.Y - p0.Y; double nx = (segment == 0) ? 0 : dy / segment; double ny = (segment == 0) ? 0 : dx / segment; x = p0.X + dx * factor + (nx * gy + offsetX) * scale; y = p0.Y + dy * factor - (ny * gy - offsetY) * scale; } } else if (geometry != null) { mxPoint offset = geometry.Offset; if (offset != null) { x += offset.X; y += offset.Y; } } return(new mxPoint(x, y)); }