Похожие чаты

Any way to make it more performant? def get_points_between_2_points(

point_1: tuple[int, int], point_2: tuple[int, int]
) -> np.ndarray:
"""Return an array of coordinates of points that lie on the line between
two given points.
"""

x1, y1 = np.array(point_1).astype(int)
x2, y2 = np.array(point_2).astype(int)

# Calculate the slope of the line
if x1 == x2:
# Handle the special case where the line is vertical
x_coords: np.ndarray = np.full(abs(y2 - y1) + 1, x1)
y_coords: np.ndarray = np.arange(min(y1, y2), max(y1, y2) + 1)
else:
slope: float = (y2 - y1) / (x2 - x1)
intercept: float = y1 - slope * x1

# Calculate the coordinates of the points on the line
x_coords: np.ndarray = np.arange(min(x1, x2), max(x1, x2) + 1)
y_coords: np.ndarray = np.around(slope * x_coords + intercept).astype(
int
)

# Combine the x and y coordinates into a single array
points: np.ndarray = np.column_stack((x_coords, y_coords))

# Remove duplicate points
points: np.ndarray = np.unique(points, axis=0)

# Sort the points by distance from the first input point
distances: np.ndarray = np.linalg.norm(points - point_1, axis=1)
sorted_indices: np.ndarray = np.argsort(distances)
points: np.ndarray = points[sorted_indices]

return points.astype(int)

2 ответов

21 просмотр

To post more than a few lines of code, use a pastebin like: * dpaste.org * linkode.org * bin.kv2.dev * hastebin.com If you are stuck in a terminal, you can use ix.io or paste.rs to paste from the CLI: <command to print output> |& curl -F 'f:1=<-' ix.io <command to print output> |& curl --data-binary @- https://paste.rs

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта