fun calculatePath()

in code/richediting/src/main/kotlin/org/fbme/ide/richediting/adapters/fbnetwork/FBConnectionController.kt [358:407]


        fun calculatePath(newSource: Point): FBConnectionPath {
            val s = myOriginalPath.sourcePosition
            val t = myOriginalPath.targetPosition
            val nsx = newSource.x
            val nsy = newSource.y
            var x1 = myOriginalPath.x1
            var y = myOriginalPath.y
            var x2 = myOriginalPath.x2
            var kind = myOriginalPath.pathKind
            if (kind == ConnectionPath.Kind.Straight) {
                x1 = (t.x + s.x) / 2
            }
            when (kind) {
                ConnectionPath.Kind.Straight, ConnectionPath.Kind.TwoAngles -> if (nsx <= t.x - 2 * scale(
                        ENDPOINTS_PADDING
                    )
                ) {
                    kind = ConnectionPath.Kind.TwoAngles
                    x1 = if (t.x != s.x) {
                        t.x - (t.x - nsx) * (t.x - x1) / (t.x - s.x)
                    } else {
                        (t.x + nsx) / 2
                    }
                } else {
                    kind = ConnectionPath.Kind.FourAngles
                    x1 = nsx + scale(ENDPOINTS_PADDING)
                    x2 = t.x - scale(ENDPOINTS_PADDING)
                    y = (t.y + nsy) / 2
                    if (y >= t.y && y - scale(ENDPOINTS_PADDING) < t.y) {
                        y = t.y + scale(ENDPOINTS_PADDING)
                    } else if (y < t.y && y + scale(ENDPOINTS_PADDING) > t.y) {
                        y = t.y - scale(ENDPOINTS_PADDING)
                    }
                }

                ConnectionPath.Kind.FourAngles, ConnectionPath.Kind.MoreThanFour -> if (nsx <= x2 + s.x - x1) {
                    kind = ConnectionPath.Kind.TwoAngles
                    x1 = if (t.x - s.x != x2 - x1) {
                        nsx + (t.x - nsx) * (x1 - s.x) / (t.x - x2 + x1 - s.x)
                    } else {
                        nsx
                    }
                } else {
                    kind = ConnectionPath.Kind.FourAngles
                    x1 = nsx + x1 - s.x
                }
            }
            val newConnectionPath = FBConnectionPath(newSource, t, kind, x1, y, x2)
            return magnetized(newConnectionPath)
        }