Skip to main content

Simple polygon operations

Project description

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simpoly-0.3.5.tar.gz (271.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

simpoly-0.3.5-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (173.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

simpoly-0.3.5-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (173.0 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

simpoly-0.3.5-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (172.5 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

simpoly-0.3.5-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (172.4 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

simpoly-0.3.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

simpoly-0.3.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

simpoly-0.3.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (965.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

simpoly-0.3.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (967.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

simpoly-0.3.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file simpoly-0.3.5.tar.gz.

File metadata

  • Download URL: simpoly-0.3.5.tar.gz
  • Upload date:
  • Size: 271.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for simpoly-0.3.5.tar.gz
Algorithm Hash digest
SHA256 dc0055c74ff632f19e12bb9a11a8f85510f834ec4d7374e711da73b2c2015702
MD5 5ae21b4c09492e1f3d9e62ae0fce24b5
BLAKE2b-256 0b223cc250c5780cb1ab946a56082f8bd7f8b3dfb535063e0d55ef6bd006823a

See more details on using hashes here.

File details

Details for the file simpoly-0.3.5-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for simpoly-0.3.5-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ab2f44fbafbb7517f7d185a9d0cf07c6c7084f460cb90bbdfb6d6f3e70d1deb6
MD5 58ff82452070a19bf26cfaae622acf28
BLAKE2b-256 0db287de4127f6a58f894b630a3b550bbca4426dda873f97578a2967c7f48368

See more details on using hashes here.

File details

Details for the file simpoly-0.3.5-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for simpoly-0.3.5-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 529376ef2a1b927caf56c2c26537d79d4da86af4a7c97aa22ae3bfcb1a9bb805
MD5 293d46273e8c7e807e5cbb0dc622bfbc
BLAKE2b-256 3b3e9cb440574d5cc1cf4bb36bd75d9c06b8e4cecccd05bef6ab21f6535a7cc5

See more details on using hashes here.

File details

Details for the file simpoly-0.3.5-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for simpoly-0.3.5-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 058cc401105fd4a7b096f82d3a0bfca9413211208d5f790fb5c2f86729678444
MD5 ae848f101b7e9dc9b72379b6bd02658f
BLAKE2b-256 03ab6411d11afae0529063f875e3a6802a26f8084e3579ef20c2dcd04665eb62

See more details on using hashes here.

File details

Details for the file simpoly-0.3.5-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for simpoly-0.3.5-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b7fb652be0f97d29f4da3846dc4ae7bf12644e8a1ad1e07dd0fbbaa16b7d2e73
MD5 ea48fae9e724690137b7f70e607514da
BLAKE2b-256 31b704a6cc216f86b3efd4ac5b441e3f0b388bf6183f25e4a6607027939e08f0

See more details on using hashes here.

File details

Details for the file simpoly-0.3.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for simpoly-0.3.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 21ed8f8df6a0c28100a2aaa294c70a797832be75285d00d349fb266e18468d14
MD5 a2634428d497e6e4e306d64f3edd77c0
BLAKE2b-256 dae525f87aa923f65255bc03f821af7d6cc746631f3807fd35207685f6e280a9

See more details on using hashes here.

File details

Details for the file simpoly-0.3.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for simpoly-0.3.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fa7535bd01561d8fc7fbb315969ee7d25fef36e25d1f605f134fc8958a5d0fa5
MD5 c9295b383226eab1222482d768f53372
BLAKE2b-256 3e7068584bd456a40535422875c89f4f927f30a298d89fd929f80d66f5cec57b

See more details on using hashes here.

File details

Details for the file simpoly-0.3.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for simpoly-0.3.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 293feaf7cf97174a0f77efa13d5af8b4a03fcc39882eaf79aeb7f0360ab7a838
MD5 88d30a2c2fd0c14f66c90b492e0dfd9c
BLAKE2b-256 e1456b1854e9b183b965e3887be4168d1bb0935129d251713c0987e1c073cdb9

See more details on using hashes here.

File details

Details for the file simpoly-0.3.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for simpoly-0.3.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 64ddb9c8f9927788459b40cf14626f7facaa9ab158fda203378e958769f66a2a
MD5 fd2cc9b1e19e377a08f155bacd4e487d
BLAKE2b-256 fd0500560fae9ad6824e5db4d46f01f2511d4fc3d8ba7f28d0635db4635a9c89

See more details on using hashes here.

File details

Details for the file simpoly-0.3.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for simpoly-0.3.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 640fd112071a32115fcec0a0461781dbca48df6818c0839a13772d13ddc37676
MD5 32d72a15812d5235b9b6b18b666374f9
BLAKE2b-256 4d9f48a73cca09e22674d6f2e9d27eec66aaf9aeb76bbb1e1932b0c6a17985d9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page