Skip to main content

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) 

Metadata

Release files for intersectioncalc 0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for intersectioncalc 0.10
File Size Uploaded Provenance
intersectioncalc-0.10.tar.gz 22.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for intersectioncalc 0.10
File Interpreter ABI Platform
intersectioncalc-0.10-py3-none-any.whl Python 3 none any Details

Total release size: 45.2 kB

Release files / intersectioncalc-0.10.tar.gz

Download URL intersectioncalc-0.10.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
67b13a4bf78bf9500bd10e0793daa96c970b396bd3e5fa53e4cd5b76af7ad723
BLAKE2b-256 checksum
How to use checksums
61d4e1f866109e81da8dd1ccbbece90c69d5ede2000eece1e2aefc722441d8ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / intersectioncalc-0.10-py3-none-any.whl

Download URL intersectioncalc-0.10-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
102ac5213a1a3a99647f4fd9209375ef47cfa02fe21909988e65eddf09ad9696
BLAKE2b-256 checksum
How to use checksums
04d7f3229f1b9f7e1780dda2990478b65bf812a9a2105e43ab467fcaf4ce812a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Security for intersectioncalc 0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.10 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page