Simpoly
A package for simple polygon operations.
Usage
Here's a quick guide on how to use the package
# +-------------------------------------------+
# | Import package and define example polygon |
# +-------------------------------------------+
import simpoly
import math
polygon = [[0, 0], [0, 1], [-1, 1]]
# +---------------------------+
# | Rotate polygon by radians |
# +---------------------------+
simpoly.rotate(polygon, math.pi/2)
# +----------------------------------------+
# | Translate (x, y) coordinates by (1, 2) |
# +----------------------------------------+
simpoly.translate(polygon, 1, 2)
# +---------------------------------------+
# | Scale (x, y) coordinates by (100, 10) |
# +---------------------------------------+
simpoly.scale(polygon, 100, 10)
# +-----------------------------------------------------------+
# | Get area (signed) and perimeter of polygon |
# | The area is positive if the polygon is counter clockwise |
# +-----------------------------------------------------------+
area = simpoly.get_area(polygon) # signed area
simpoly.get_perimeter(polygon)
# +------------------------------------------------------------------------------+
# | Offset polygon edges by some distance. |
# | Positive distance expands the polygon, negative distance shrinks it. |
# | The 3rd parameter specify if the polygon is counter clockwise (ccw), |
# | it is assumed that the polygon is ccw by default, if the polygon is not |
# | ccw, the distance's sign will be change so that the behaviour is consistent. |
# | One can use get_area to check if the polygon is counter clockwise. |
# +------------------------------------------------------------------------------+
simpoly.offset(polygon, 1, area >= 0)
# +----------------------------------------------------------------+
# | Apply affine transformation to polygon, the second argument |
# | [a, b, c, d, e, f] is equivalent to the transformation matrix: |
# | [ a b c ] |
# | [ d e f ] |
# +----------------------------------------------------------------+
simpoly.affine_transform(polygon, [1, 0, 1, 0, 1, -2]) # offset by [1, -2]
There are also some bounding box utilities in here:
import random
from pprint import pprint
from simpoly import bbox_utils
# +-------------------+
# | Generate examples |
# +-------------------+
def rand_boxes(n):
bounding_boxes = []
for _ in range(n):
x_min = random.randint(0, 100)
y_min = random.randint(0, 100)
x_max = random.randint(x_min + 1, 200)
y_max = random.randint(y_min + 1, 200)
bounding_boxes.append([x_min, y_min, x_max, y_max])
return bounding_boxes
boxes = rand_boxes(5)
# Compute IoU / Batch IoU
iou = bbox_utils.get_iou(boxes[0], boxes[1])
print("IoU(b[1], b[1])", iou)
# Compute IoU / Batch IoU
ious = bbox_utils.get_iou_matrix(boxes, boxes, symetric=True)
ious = [["%.4f" % x for x in row] for row in ious]
pprint(ious)
# Non max suppression
# Boxes must be list of list
keep = bbox_utils.nms(boxes, [1.0] * 5, iou_threshold=0.5)
print("Keep", keep)
Metadata
Release files for simpoly 0.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| simpoly-0.3.5.tar.gz | 271.3 kB | Details |
Built distributions (wheels)
Total release size: 6.0 MB
Release files / simpoly-0.3.5.tar.gz
| Download URL | simpoly-0.3.5.tar.gz |
|---|---|
| Size | 271.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc0055c74ff632f19e12bb9a11a8f85510f834ec4d7374e711da73b2c2015702
|
|
BLAKE2b-256 checksum How to use checksums |
0b223cc250c5780cb1ab946a56082f8bd7f8b3dfb535063e0d55ef6bd006823a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / simpoly-0.3.5-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
| Download URL | simpoly-0.3.5-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 173.2 kB |
| Tags | Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 PyPy 3.10 PyPy 3.10 7.3 |
|
SHA-256 checksum How to use checksums |
ab2f44fbafbb7517f7d185a9d0cf07c6c7084f460cb90bbdfb6d6f3e70d1deb6
|
|
BLAKE2b-256 checksum How to use checksums |
0db287de4127f6a58f894b630a3b550bbca4426dda873f97578a2967c7f48368
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / simpoly-0.3.5-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
| Download URL | simpoly-0.3.5-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 173.0 kB |
| Tags | Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 PyPy 3.9 PyPy 3.9 7.3 |
|
SHA-256 checksum How to use checksums |
529376ef2a1b927caf56c2c26537d79d4da86af4a7c97aa22ae3bfcb1a9bb805
|
|
BLAKE2b-256 checksum How to use checksums |
3b3e9cb440574d5cc1cf4bb36bd75d9c06b8e4cecccd05bef6ab21f6535a7cc5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / simpoly-0.3.5-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
| Download URL | simpoly-0.3.5-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 172.5 kB |
| Tags | Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 PyPy 3.8 PyPy 3.8 7.3 |
|
SHA-256 checksum How to use checksums |
058cc401105fd4a7b096f82d3a0bfca9413211208d5f790fb5c2f86729678444
|
|
BLAKE2b-256 checksum How to use checksums |
03ab6411d11afae0529063f875e3a6802a26f8084e3579ef20c2dcd04665eb62
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / simpoly-0.3.5-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
| Download URL | simpoly-0.3.5-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 172.4 kB |
| Tags | Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 PyPy 3.7 PyPy 3.7 7.3 |
|
SHA-256 checksum How to use checksums |
b7fb652be0f97d29f4da3846dc4ae7bf12644e8a1ad1e07dd0fbbaa16b7d2e73
|
|
BLAKE2b-256 checksum How to use checksums |
31b704a6cc216f86b3efd4ac5b441e3f0b388bf6183f25e4a6607027939e08f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / simpoly-0.3.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
| Download URL | simpoly-0.3.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
21ed8f8df6a0c28100a2aaa294c70a797832be75285d00d349fb266e18468d14
|
|
BLAKE2b-256 checksum How to use checksums |
dae525f87aa923f65255bc03f821af7d6cc746631f3807fd35207685f6e280a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / simpoly-0.3.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
| Download URL | simpoly-0.3.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
fa7535bd01561d8fc7fbb315969ee7d25fef36e25d1f605f134fc8958a5d0fa5
|
|
BLAKE2b-256 checksum How to use checksums |
3e7068584bd456a40535422875c89f4f927f30a298d89fd929f80d66f5cec57b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / simpoly-0.3.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
| Download URL | simpoly-0.3.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 965.4 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
293feaf7cf97174a0f77efa13d5af8b4a03fcc39882eaf79aeb7f0360ab7a838
|
|
BLAKE2b-256 checksum How to use checksums |
e1456b1854e9b183b965e3887be4168d1bb0935129d251713c0987e1c073cdb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / simpoly-0.3.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
| Download URL | simpoly-0.3.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 967.1 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
64ddb9c8f9927788459b40cf14626f7facaa9ab158fda203378e958769f66a2a
|
|
BLAKE2b-256 checksum How to use checksums |
fd0500560fae9ad6824e5db4d46f01f2511d4fc3d8ba7f28d0635db4635a9c89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / simpoly-0.3.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
| Download URL | simpoly-0.3.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
640fd112071a32115fcec0a0461781dbca48df6818c0839a13772d13ddc37676
|
|
BLAKE2b-256 checksum How to use checksums |
4d9f48a73cca09e22674d6f2e9d27eec66aaf9aeb76bbb1e1932b0c6a17985d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|