mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
from __future__ import annotations (#2464)
* from __future__ import annotations * fixup! from __future__ import annotations * fixup! from __future__ import annotations * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
# https://en.wikipedia.org/wiki/B%C3%A9zier_curve
|
||||
# https://www.tutorialspoint.com/computer_graphics/computer_graphics_curves.htm
|
||||
from typing import List, Tuple
|
||||
from __future__ import annotations
|
||||
|
||||
from scipy.special import comb
|
||||
|
||||
@ -12,7 +12,7 @@ class BezierCurve:
|
||||
This implementation works only for 2d coordinates in the xy plane.
|
||||
"""
|
||||
|
||||
def __init__(self, list_of_points: List[Tuple[float, float]]):
|
||||
def __init__(self, list_of_points: list[tuple[float, float]]):
|
||||
"""
|
||||
list_of_points: Control points in the xy plane on which to interpolate. These
|
||||
points control the behavior (shape) of the Bezier curve.
|
||||
@ -22,7 +22,7 @@ class BezierCurve:
|
||||
# Degree = 1 will produce a straight line.
|
||||
self.degree = len(list_of_points) - 1
|
||||
|
||||
def basis_function(self, t: float) -> List[float]:
|
||||
def basis_function(self, t: float) -> list[float]:
|
||||
"""
|
||||
The basis function determines the weight of each control point at time t.
|
||||
t: time value between 0 and 1 inclusive at which to evaluate the basis of
|
||||
@ -36,7 +36,7 @@ class BezierCurve:
|
||||
[0.0, 1.0]
|
||||
"""
|
||||
assert 0 <= t <= 1, "Time t must be between 0 and 1."
|
||||
output_values: List[float] = []
|
||||
output_values: list[float] = []
|
||||
for i in range(len(self.list_of_points)):
|
||||
# basis function for each i
|
||||
output_values.append(
|
||||
@ -46,7 +46,7 @@ class BezierCurve:
|
||||
assert round(sum(output_values), 5) == 1
|
||||
return output_values
|
||||
|
||||
def bezier_curve_function(self, t: float) -> Tuple[float, float]:
|
||||
def bezier_curve_function(self, t: float) -> tuple[float, float]:
|
||||
"""
|
||||
The function to produce the values of the Bezier curve at time t.
|
||||
t: the value of time t at which to evaluate the Bezier function
|
||||
@ -80,8 +80,8 @@ class BezierCurve:
|
||||
"""
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
to_plot_x: List[float] = [] # x coordinates of points to plot
|
||||
to_plot_y: List[float] = [] # y coordinates of points to plot
|
||||
to_plot_x: list[float] = [] # x coordinates of points to plot
|
||||
to_plot_y: list[float] = [] # y coordinates of points to plot
|
||||
|
||||
t = 0.0
|
||||
while t <= 1:
|
||||
|
Reference in New Issue
Block a user