コード例 #1
0
ファイル: test_utilities.py プロジェクト: dkkline/bravo
 def test_taxicab2(self):
     cases = {
         (1, 2, 3, 4): 4,
         (1, 2, 1, 2): 0,
         (2, 1, 4, 3): 4,
     }
     for case in cases:
         self.assertEqual(taxicab2(*case), cases[case])
コード例 #2
0
ファイル: spatial.py プロジェクト: EntityReborn/bravo
    def iteritemsnear(self, key, radius):
        """
        A version of ``iteritems()`` that filters based on the distance from a
        given key.

        The key does not need to actually be in the dictionary.
        """

        for coords in self.keys_near(key, radius):
            for target, value in self.buckets[coords].iteritems():
                if taxicab2(target[0], target[1], key[0], key[1]) <= radius:
                    yield target, value
コード例 #3
0
ファイル: spatial.py プロジェクト: tazjel/bravo
    def iteritemsnear(self, key, radius):
        """
        A version of ``iteritems()`` that filters based on the distance from a
        given key.

        The key does not need to actually be in the dictionary.
        """

        for coords in self.keys_near(key, radius):
            for target, value in self.buckets[coords].iteritems():
                if taxicab2(target[0], target[1], key[0], key[1]) <= radius:
                    yield target, value