fun calculatePath()

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


        fun calculatePath(newTarget: Point): FBConnectionPath {
            val s = myOriginalPath.sourcePosition
            val t = myOriginalPath.targetPosition
            val ntx = newTarget.x
            val nty = newTarget.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 (ntx >= s.x + 2 * scale(
                        ENDPOINTS_PADDING
                    )
                ) {
                    kind = ConnectionPath.Kind.TwoAngles
                    if (t.x != s.x) {
                        x1 = s.x + (ntx - s.x) * (x1 - s.x) / (t.x - s.x)
                    } else {
                        x2 = (s.x + ntx) / 2
                    }
                } else {
                    kind = ConnectionPath.Kind.FourAngles
                    x1 = s.x + scale(ENDPOINTS_PADDING)
                    x2 = ntx - scale(ENDPOINTS_PADDING)
                    y = (s.y + nty) / 2
                    if (y >= s.y && y - scale(ENDPOINTS_PADDING) < s.y) {
                        y = s.y + scale(ENDPOINTS_PADDING)
                    } else if (y < s.y && y + scale(ENDPOINTS_PADDING) > s.y) {
                        y = s.y - scale(ENDPOINTS_PADDING)
                    }
                }

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