How to use the slider.position.Position function in slider

To help you get started, we’ve selected a few slider examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github llllllllll / slider / tests / test_beatmap.py View on Github external
102, 106, 111, 114, 116, 122, 124, 125, 126, 128, 129,
                            134, 135, 137, 138, 140, 141, 142, 144, 145, 147, 150,
                            156, 162, 177, 180, 183, 191, 193, 194, 195, 196, 197,
                            198, 199, 201, 203, 207, 208, 209, 210, 211, 213, 214,
                            228, 240, 241, 242, 245, 246, 249, 251, 252, 253, 256,
                            257, 258, 260, 261, 262, 263, 266, 283, 284, 288, 289,
                            290, 291, 294, 295, 297, 301, 302, 303, 304, 305, 307,
                            308, 309, 310, 313, 316, 320, 321, 322, 324, 325, 329]])
    assert hit_objects_stacked[7].stack_height == 1
    assert hit_objects_stacked[7].position == Position(x=281.352, y=223.352)
    assert hit_objects_stacked[31].stack_height == -1
    assert hit_objects_stacked[31].position == Position(x=286.648, y=230.648)
    # test hard_rock hit_objects
    hit_objects_hard_rock_0 = beatmap.hit_objects(hard_rock=True, stacking=False)[0]
    assert hit_objects_hard_rock_0.position == Position(x=243, y=220)
    assert hit_objects_0.curve.points == [Position(x=243, y=220),
                                          Position(x=301, y=209)]
github llllllllll / slider / slider / replay.py View on Github external
compressed_byte_count = consume_int(buffer)
    compressed_data = buffer[:compressed_byte_count]
    del buffer[:compressed_byte_count]
    decompressed_data = lzma.decompress(compressed_data)

    out = []
    offset = 0
    for raw_action in decompressed_data.split(b','):
        if not raw_action:
            continue
        raw_offset, x, y, raw_action_mask = raw_action.split(b'|')
        action_mask = ActionBitMask.unpack(int(raw_action_mask))
        offset += int(raw_offset)
        out.append(Action(
            datetime.timedelta(milliseconds=offset),
            Position(float(x), float(y)),
            action_mask['m1'],
            action_mask['m2'],
            action_mask['k1'],
            action_mask['k2'],
        ))
    return out
github llllllllll / slider / slider / curve.py View on Github external
Parameters
    ----------
    position : Position
        The position to rotate.
    center : Position
        The point to rotate about.
    radians : float
        The number of radians to rotate ``position`` by.
    """
    p_x, p_y = position
    c_x, c_y = center

    x_dist = p_x - c_x
    y_dist = p_y - c_y

    return Position(
        (x_dist * math.cos(radians) - y_dist * math.sin(radians)) + c_x,
        (x_dist * math.sin(radians) + y_dist * math.cos(radians)) + c_y,
    )
github llllllllll / slider / slider / beatmap.py View on Github external
parse = Circle._parse
        elif type_ & Slider.type_code:
            parse = partial(
                Slider._parse,
                timing_points=timing_points,
                slider_multiplier=slider_multiplier,
                slider_tick_rate=slider_tick_rate,
            )
        elif type_ & Spinner.type_code:
            parse = Spinner._parse
        elif type_ & HoldNote.type_code:
            parse = HoldNote._parse
        else:
            raise ValueError(f'unknown type code {type_!r}')

        return parse(Position(x, y), time, hitsound, rest)
github llllllllll / slider / slider / beatmap.py View on Github external
def __init__(self, hit_object, radius, previous=None):
        self.hit_object = hit_object

        scaling_factor = 52 / radius
        if radius < self.circle_size_buffer_threshold:
            scaling_factor *= 1 + min(
                self.circle_size_buffer_threshold - radius,
                5,
            ) / 50

        # this currently ignores slider length
        self.normalized_start = self.normalized_end = Position(
            hit_object.position.x * scaling_factor,
            hit_object.position.y * scaling_factor,
        )

        if previous is None:
            self.strains = 0, 0
        else:
            self.strains = (
                self._calculate_strain(previous, self.Strain.speed),
                self._calculate_strain(previous, self.Strain.aim),
            )
github llllllllll / slider / slider / curve.py View on Github external
def hard_rock(self):
        """This curve when played with hard rock.
        """
        return type(self)(
            [Position(p.x, 384 - p.y) for p in self.points],
            self.req_length,
        )
github llllllllll / slider / slider / curve.py View on Github external
b_squared = np.sum(np.square(a - c))
    c_squared = np.sum(np.square(a - b))

    if np.isclose([a_squared, b_squared, c_squared], 0).any():
        raise ValueError(f'given points are collinear: {a}, {b}, {c}')

    s = a_squared * (b_squared + c_squared - a_squared)
    t = b_squared * (a_squared + c_squared - b_squared)
    u = c_squared * (a_squared + b_squared - c_squared)

    sum_ = s + t + u

    if np.isclose(sum_, 0):
        raise ValueError(f'given points are collinear: {a}, {b}, {c}')

    return Position(*(s * a + t * b + u * c) / sum_)