/**
 * Check if two line segments intersect each other.
 *
 * @param x1 The x-coordinate of the first point of the first line segment.
 * @param y1 The y-coordinate of the first point of the first line segment.
 * @param x2 The x-coordinate of the second point of the first line segment.
 * @param y2 The y-coordinate of the second point of the first line segment.
 * @param x3 The x-coordinate of the first point of the second line segment.
 * @param y3 The y-coordinate of the first point of the second line segment.
 * @param x4 The x-coordinate of the second point of the second line segment.
 * @param y4 The y-coordinate of the second point of the second line segment.
 *
 * @return True if the line segments intersect, False otherwise.
 */
fun intersectionCheck(x1: Double, y1: Double, x2: Double, y2: Double, x3: Double, y3: Double, x4: Double, y4: Double): Boolean {

    // Calculate the equation of the first line segment
    val slope1 = (y2 - y1) / (x2 - x1)
    val intercept1 = y1 - slope1 * x1

    // Calculate the equation of the second line segment
    val slope2 = (y4 - y3) / (x4 - x3)
    val intercept2 = y3 - slope2 * x3

    // Check if the lines are parallel
    if (Math.abs(slope1 - slope2) < 1e-10) {
        return false
    }

    // Calculate the intersection point
    val intersectionX = (intercept2 - intercept1) / (slope1 - slope2)
    return true
}
/**
 * Check if two line segments intersect each other.
 *
 * @param x1 The x-coordinate of the first point of the first line segment.
 * @param y1 The y-coordinate of the first point of the first line segment.
 * @param x2 The x-coordinate of the second point of the first line segment.
 * @param y2 The y-coordinate of the second point of the first line segment.
 * @param x3 The x-coordinate of the first point of the second line segment.
 * @param y3 The y-coordinate of the first point of the second line segment.
 * @param x4 The x-coordinate of the second point of the second line segment.
 * @param y4 The y-coordinate of the second point of the second line segment.
 *
 * @return True if the line segments intersect, False otherwise.
 */
fun intersectionCheck(x1: Double, y1: Double, x2: Double, y2: Double, x3: Double, y3: Double, x4: Double, y4: Double): Boolean {
/**
 * Check if two line segments intersect each other.
 *
 * @param x1 The x-coordinate of the first point of the first line segment.
 * @param y1 The y-coordinate of the first point of the first line segment.
 * @param x2 The x-coordinate of the second point of the first line segment.
 * @param y2 The y-coordinate of the second point of the first line segment.
 * @param x3 The x-coordinate of the first point of the second line segment.
 * @param y3 The y-coordinate of the first point of the second line segment.
 * @param x4 The x-coordinate of the second point of the second line segment.
 * @param y4 The y-coordinate of the second point of the second line segment.
 *
 * @return True if the line segments intersect, False otherwise.
 */
fun intersectionCheck(x1: Double, y1: Double, x2: Double, y2: Double, x3: Double, y3: Double, x4: Double, y4: Double): Boolean {

    // Calculate the equation of the first line segment
    val slope1 = (y2 - y1) / (x2 - x1)
    val intercept1 = y1 - slope1 * x1

    // Calculate the equation of the second line segment
    val slope2 = (y4 - y3) / (x4 - x3)
    val intercept2 = y3 - slope2 * x3

    // Check if the lines are parallel
    if (Math.abs(slope1 - slope2) < 1e-10) {
        return false
    }

    // Calculate the intersection point
    val intersectionX = (intercept2 - intercept1) / (slope1 - slope2)
    return true
}