Giter Club home page Giter Club logo

spatial's People

Contributors

mikemalinowski avatar

spatial's Issues

Non-intersecting bounds intersect

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):

non-intersecting-rectangles

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)

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.