Finds rectangle intersections
Project description
Finds rectangle intersections
pip install intersectioncalc
Tested against Windows 10 / Python 3.10 / Anaconda - should work on MacOS / Linux
Finds rectangle intersections in a DataFrame and populates a new column with results.
The function utilizes NumExpr for calculations, which can significantly improve
performance when dealing with large datasets of rectangles
Args:
df (pd.DataFrame): Input DataFrame containing rectangle coordinates.
columns (tuple or list, optional): Names of columns containing rectangle coordinates
(start_x, start_y, end_x, end_y). Defaults to ("start_x", "start_y", "end_x", "end_y").
new_column (str, int, float, optional): Name of the new column to store intersection results.
Defaults to "aa_intersecting".
dtype (np.float32 | np.float64 | np.int32 | np.int64, optional): Data type for calculations. Defaults to np.int32.
convert_to_tuples (bool, optional): If True, converts intersection results to tuples.
Defaults to False.
Returns:
pd.DataFrame: Input DataFrame with the new_column populated with intersection results.
from intersectioncalc import find_rectangle_intersections
import time
import pandas as pd
import numpy as np
min_x = 1
max_x = 100
min_y = 1
max_y = 100
size = 50000
min_width = 1
max_width = 1000
min_height = 1
max_height = 1000
df = pd.DataFrame(
[
(startx := np.random.randint(min_x, max_x, size=size)),
(starty := np.random.randint(min_y, max_y, size=size)),
startx + np.random.randint(min_width, max_width, size=size),
starty + np.random.randint(min_height, max_height, size=size),
]
).T.rename(columns={0: "start_x", 1: "start_y", 2: "end_x", 3: "end_y"})
start = time.perf_counter()
df = find_rectangle_intersections(
df,
columns=("start_x", "start_y", "end_x", "end_y"),
new_column="aa_intersecting",
dtype=np.int32,
convert_to_tuples=False,
)
print(time.perf_counter() - start)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
intersectioncalc-0.10.tar.gz
(22.3 kB
view details)
Built Distribution
File details
Details for the file intersectioncalc-0.10.tar.gz
.
File metadata
- Download URL: intersectioncalc-0.10.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67b13a4bf78bf9500bd10e0793daa96c970b396bd3e5fa53e4cd5b76af7ad723 |
|
MD5 | 8b8ded8c14d5dc6fb0f1cdf3d10f532d |
|
BLAKE2b-256 | 61d4e1f866109e81da8dd1ccbbece90c69d5ede2000eece1e2aefc722441d8ce |
File details
Details for the file intersectioncalc-0.10-py3-none-any.whl
.
File metadata
- Download URL: intersectioncalc-0.10-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 102ac5213a1a3a99647f4fd9209375ef47cfa02fe21909988e65eddf09ad9696 |
|
MD5 | f31f4791a6459d323cce9acddb40cec6 |
|
BLAKE2b-256 | 04d7f3229f1b9f7e1780dda2990478b65bf812a9a2105e43ab467fcaf4ce812a |