mikemalinowski / spatial Goto Github PK
View Code? Open in Web Editor NEWSmall library for utility functions/classes related to spatial manipulation and queries
License: MIT License
Small library for utility functions/classes related to spatial manipulation and queries
License: MIT License
When checking intersection of bounds, the method intersect
returns a false positive if the bounds intersect in one dimension but lay completely outside of each other considering all dimensions (red region). It works correctly if all they lay outside in all dimensions (green):
Example:
Bounds([(0,0), (1,1)]).intersects(Bounds([(-2,0), (-1,1)]))
def intersects(self, bounds):
"""
Tests whether this bounding box and the given bounding box
intersect one-another.
:param bounds: spatial.Bounds
:return: bool
"""
if bounds.num_dimensions() > self.num_dimensions():
return False
intersects_in_dimension = [False] * self.num_dimensions()
# Check whether at least one corner of bounds is within self.
for dimension in range(bounds.num_dimensions()):
if bounds.min(dimension) >= self.min(dimension) and bounds.min(
dimension) <= self.max(dimension):
intersects_in_dimension[dimension] = True
continue
if bounds.max(dimension) >= self.min(dimension) and bounds.max(
dimension) <= self.max(dimension):
intersects_in_dimension[dimension] = True
continue
if all(intersects_in_dimension):
return True
# Otherwise bounds could be fully containing self (all corners outside).
# Check whether any arbitrary corner of self is within bounds.
for dimension in range(bounds.num_dimensions()):
if self.min(dimension) >= bounds.min(dimension) and self.min(
dimension) <= bounds.max(dimension):
intersects_in_dimension[dimension] = True
return all(intersects_in_dimension)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.