Coder Social home page Coder Social logo

pymbr's Introduction

minimum bounding box - python

Minimum bounding box operations in python

example

from mbr import MBR

box1 = MBR(0, 0, 0, 0)
box1.expand_include_xy(2, 2)
print(box1)  # POLYGON ((0 0, 0 2, 2 2, 2 0, 0 0))

box2 = MBR(0, 0, 2, 2)
print(box2.equals(box1))  # True
print(box1.height)  # 2
print(box1.width)  # 2
print(box1.area)  # 4
print(box1.center)  # (1.0, 1.0)

# let p = point(1.7, 1.5)
p = 1.7, 1.5
print(box2.intersects_point(p))  # True

box3 = MBR(1.7, 1.5, 3.0, 1.9)
box4 = MBR(2.5, 3, 4.0, 5.0)

# intersects & intersection 
print(box2.intersects(box3))  # True
iters, bln = box2.intersection(box3)
# mbr, intersects
# MBR (1.7, 1.5, 2.0, 1.9), True

print(box2.intersects(box4))  # False
inter, _ = box2.intersection(box4)
# MBR(nan, nan, nan, nan), False

print(box1.distance(box4))  # 1.118

methods

    as_poly_array(self)      # ((x, y),..., (x, y)) 
    is_point(self)           # bool  -> (height,width) == (0,0)
    clone(self)              # MBR(minx, miny, maxx, maxy)
    as_tuple(self)           # (minx, miny, maxx, maxy)
    equals(self, other)      # bool
    translate(self, dx, dy)  # bool
    intersection(self, other)# MBR, bool
    intersects_bounds(self, q1, q2)           # bool, q1 and q2 -> (x, y)
    contains(self, other)                     # bool
    contains_xy(self, x, y)                   # bool
    completely_contains_xy(self, x, y)        # bool
    completely_contains_mbr(self, other)      # bool
    disjoint(self, other)                     # bool
    intersects(self, other)                   # bool
    intersects_point(self, pt)                # bool, pt -> (x, y)
    expand_include_mbr(self, other)           # bool
    expand_by_delta(self, dx, dy)             # self
    expand_include_xy(self, x_coord, y_coord) # self 
    distance(self, other)                     # float 
    distance_square(self, other)              # float 

properties

    llur    # float
    width   # float
    height  # float
    area    # float
    center  # (float, float)

lic

MIT

pymbr's People

Contributors

intdxdt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.