intersectioncalc


Nameintersectioncalc JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/intersectioncalc
SummaryFinds rectangle intersections
upload_time2023-08-29 23:19:48
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords rectangle intersections
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Finds rectangle intersections

## pip install intersectioncalc

### Tested against Windows 10 / Python 3.10 / Anaconda - should work on MacOS / Linux


```python
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) 
```
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/intersectioncalc",
    "name": "intersectioncalc",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "rectangle,intersections",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/61/d4/e1f866109e81da8dd1ccbbece90c69d5ede2000eece1e2aefc722441d8ce/intersectioncalc-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# Finds rectangle intersections\r\n\r\n## pip install intersectioncalc\r\n\r\n### Tested against Windows 10 / Python 3.10 / Anaconda - should work on MacOS / Linux\r\n\r\n\r\n```python\r\nFinds rectangle intersections in a DataFrame and populates a new column with results.\r\nThe function utilizes NumExpr for calculations, which can significantly improve\r\nperformance when dealing with large datasets of rectangles\r\n\r\nArgs:\r\n    df (pd.DataFrame): Input DataFrame containing rectangle coordinates.\r\n    columns (tuple or list, optional): Names of columns containing rectangle coordinates\r\n        (start_x, start_y, end_x, end_y). Defaults to (\"start_x\", \"start_y\", \"end_x\", \"end_y\").\r\n    new_column (str, int, float, optional): Name of the new column to store intersection results.\r\n        Defaults to \"aa_intersecting\".\r\n    dtype (np.float32 | np.float64 | np.int32 | np.int64, optional): Data type for calculations. Defaults to np.int32.\r\n    convert_to_tuples (bool, optional): If True, converts intersection results to tuples.\r\n        Defaults to False.\r\n\r\nReturns:\r\n    pd.DataFrame: Input DataFrame with the new_column populated with intersection results.\r\n\r\nfrom intersectioncalc import find_rectangle_intersections\r\nimport time\r\nimport pandas as pd\r\nimport numpy as np\r\nmin_x = 1\r\nmax_x = 100\r\nmin_y = 1\r\nmax_y = 100\r\nsize = 50000\r\nmin_width = 1\r\nmax_width = 1000\r\nmin_height = 1\r\nmax_height = 1000\r\ndf = pd.DataFrame(\r\n    [\r\n        (startx := np.random.randint(min_x, max_x, size=size)),\r\n        (starty := np.random.randint(min_y, max_y, size=size)),\r\n        startx + np.random.randint(min_width, max_width, size=size),\r\n        starty + np.random.randint(min_height, max_height, size=size),\r\n    ]\r\n).T.rename(columns={0: \"start_x\", 1: \"start_y\", 2: \"end_x\", 3: \"end_y\"})\r\nstart = time.perf_counter()\r\ndf = find_rectangle_intersections(\r\n    df,\r\n    columns=(\"start_x\", \"start_y\", \"end_x\", \"end_y\"),\r\n    new_column=\"aa_intersecting\",\r\n    dtype=np.int32,\r\n    convert_to_tuples=False,\r\n)\r\nprint(time.perf_counter() - start) \r\n```\r\n                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                \r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Finds rectangle intersections",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/intersectioncalc"
    },
    "split_keywords": [
        "rectangle",
        "intersections"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "04d7f3229f1b9f7e1780dda2990478b65bf812a9a2105e43ab467fcaf4ce812a",
                "md5": "f31f4791a6459d323cce9acddb40cec6",
                "sha256": "102ac5213a1a3a99647f4fd9209375ef47cfa02fe21909988e65eddf09ad9696"
            },
            "downloads": -1,
            "filename": "intersectioncalc-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f31f4791a6459d323cce9acddb40cec6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 22855,
            "upload_time": "2023-08-29T23:19:47",
            "upload_time_iso_8601": "2023-08-29T23:19:47.131368Z",
            "url": "https://files.pythonhosted.org/packages/04/d7/f3229f1b9f7e1780dda2990478b65bf812a9a2105e43ab467fcaf4ce812a/intersectioncalc-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "61d4e1f866109e81da8dd1ccbbece90c69d5ede2000eece1e2aefc722441d8ce",
                "md5": "8b8ded8c14d5dc6fb0f1cdf3d10f532d",
                "sha256": "67b13a4bf78bf9500bd10e0793daa96c970b396bd3e5fa53e4cd5b76af7ad723"
            },
            "downloads": -1,
            "filename": "intersectioncalc-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "8b8ded8c14d5dc6fb0f1cdf3d10f532d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 22342,
            "upload_time": "2023-08-29T23:19:48",
            "upload_time_iso_8601": "2023-08-29T23:19:48.588163Z",
            "url": "https://files.pythonhosted.org/packages/61/d4/e1f866109e81da8dd1ccbbece90c69d5ede2000eece1e2aefc722441d8ce/intersectioncalc-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-29 23:19:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "intersectioncalc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "intersectioncalc"
}
        
Elapsed time: 0.15519s