Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何找到矩形的最小值和最大值?_Javascript_Python_Hash_2d_Rect - Fatal编程技术网

Javascript 如何找到矩形的最小值和最大值?

Javascript 如何找到矩形的最小值和最大值?,javascript,python,hash,2d,rect,Javascript,Python,Hash,2d,Rect,我在这里关注这篇文章: 创建我的空间散列函数来解决碰撞检测2D游戏中的缓慢问题。但我不理解插入对象的部分: 如何找到下面对象的最小值和最大值 myObject = { x: 704, y: 448, width: 32, height: 32 } 几年前我放弃了python,忘记了它的语法,这意味着下面的代码: def insert_object_for_box(self, box, object): # hash the minimum and maxim

我在这里关注这篇文章:

创建我的空间散列函数来解决碰撞检测2D游戏中的缓慢问题。但我不理解插入对象的部分:

如何找到下面对象的最小值和最大值

myObject = {
    x: 704,
    y: 448,
    width: 32,
    height: 32
}
几年前我放弃了python,忘记了它的语法,这意味着下面的代码:

def insert_object_for_box(self, box, object):

# hash the minimum and maximum points

min, max = self._hash(box.min), self._hash(box.max)

# iterate over the rectangular region

for i in range(min[0], max[0]+1):

for j in range(min[1], max[1]+1):

# append to each intersecting cell

self.contents.setdefault( (i, j), [] ).append( object )
这是否是javascript格式:

function insert_object_for_box(box, object) {

    box.min.x = here?;
    box.min.y = here?;
    box.max.x = here?;
    box.max.y = here?;

    var minX = this.hash(box.min.x);
    var minY = this.hash(box.min.y);

    var maxX = this.hash(box.max.x);
    var maxY = this.hash(box.max.y);

    for(var x = minX; x < maxX+1, x++) {
        for(var y = minY; y < maxY+1, y++) {
             here?
        }
    }

}
函数为\u框(框,对象)插入\u对象{
box.min.x=此处?;
box.min.y=此处?;
box.max.x=此处?;
box.max.y=此处?;
var minX=this.hash(box.min.x);
var minY=this.hash(box.min.y);
var maxX=this.hash(box.max.x);
var maxY=this.hash(box.max.y);
对于(var x=minX;x
宽度大于高度的矩形不是正方形吗
Math.min
Math.max
函数将帮助您获得最小值和最大值though@Zyigh但我不明白最大值和最小值在哪里?你喜欢x还是y?我不明白他在文章中所说的最小值和最大值是什么意思。@Zyigh我编辑了这个问题