Remember how we talked about actually writing code to do intersection between
two rectangles? We've actually abstracted that away and actually turned it into
a function inside of gMaps. You can call gMap.intersectRect. The isVisible
function is actually a nice little helper that will pass in the viewRect and the
rectangle for this tile Into the intersectRect function to determine whether or
not this tile is visible to the current view rectangle. This is a helpful little
function that we'll utilize in a couple different places moving forward. Now,
before moving forward let's go ahead and write this intersectRect function so
that it takes two rectangles with top, bottom, left, and right values and
returns whether or not they intersect.
¿Recuerdan cuando hablamos acerca de escribir
códigos para hacer una intersección entre
dos rectángulos? De hecho, hemos
extraído eso y lo hemos convertido en
una función dentro de gMaps, llamada
gMap.intersectRect. La función isVisible
es en realidad una buena ayuda
que pasará el viewRect y
el rectángulo de este tile hacia la función
intersectRect para determinar si
este tile es visible en la vista
rectángulo actual. Esta es una
función bastante útil que utilizaremos en un par
de lugares diferentes a medida que avanzamos.
Ahora bien, antes de seguir avanzando, vayamos y escribamos esta función intersectRect para
que tome dos rectángulos con los valores
de arriba, abajo, izquierda y derecha,
y regrese en caso de que se hayan intersectado o no.
Lembra que falamos sobre escrever
um código para interseccionar
dois retângulos? Fizemos um resumo deste
procedimento e o transformamos em
uma função dentro do gMaps, chamada
gMap.intersectRect. Esta função
visível nos ajuda bastante, pois passará
o viewRect e o
retângulo deste bloco, à função intersectRect
para determinar se este bloco
é ou não perceptível na vista atual
do retângulo. Esta é uma função muito
útil que vamos utilizar em diferentes
situações, mais adiante.
Mas, antes de continuar, vamos escrever
esta função intersectRect para
que ela pegue os valores superior, inferior,
esquerdo e direito de dois retângulos,
e nos mostre se eles interseccionam ou não.