<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: hit code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 20:13:35 GMT</pubDate>
    <description>DZone Snippets: hit code</description>
    <item>
      <title>Point Inside a Polygon //JavaScript Function</title>
      <link>http://snippets.dzone.com/posts/show/5295</link>
      <description>&lt;a href="http://jsfromhell.com/math/is-point-in-poly"&gt;&lt;br /&gt;Checks whether a point is inside a polygon.&lt;br /&gt;Adapted from: [http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html]&lt;br /&gt;&lt;br /&gt;[UPDATED CODE AND HELP CAN BE FOUND HERE: Point Inside a Polygon]&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com/classes/is-point-in-poly [v1.0]&lt;br /&gt;&lt;br /&gt;function isPointInPoly(poly, pt){&lt;br /&gt;	for(var c = false, i = -1, l = poly.length, j = l - 1; ++i &lt; l; j = i)&lt;br /&gt;		((poly[i].y &lt;= pt.y &amp;&amp; pt.y &lt; poly[j].y) || (poly[j].y &lt;= pt.y &amp;&amp; pt.y &lt; poly[i].y))&lt;br /&gt;		&amp;&amp; (pt.x &lt; (poly[j].x - poly[i].x) * (pt.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x)&lt;br /&gt;		&amp;&amp; (c = !c);&lt;br /&gt;	return c;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Example&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;//&lt;![CDATA[&lt;br /&gt;&lt;br /&gt;points = [&lt;br /&gt;	{x: 0, y: 0},&lt;br /&gt;	{x: 0, y: 50},&lt;br /&gt;	{x: 50, y: 10},&lt;br /&gt;	{x: -50, y: -10},&lt;br /&gt;	{x: 0, y: -50},&lt;br /&gt;	{x: 0, y: 0}&lt;br /&gt;];&lt;br /&gt;&lt;br /&gt;alert(isPointInPoly(points, {x: 10, y: 10}) ? "In" : "Out");&lt;br /&gt;&lt;br /&gt;//]]&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Sun, 30 Mar 2008 16:57:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5295</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
    <item>
      <title>HitTest //JavaScript Function</title>
      <link>http://snippets.dzone.com/posts/show/913</link>
      <description>&lt;a href="http://jsfromhell.com/geral/hittest"&gt;&lt;br /&gt;With this it's possible to correct the "SELECT over DIV" IE bug as i showed in the example bellow&lt;br /&gt;&lt;br /&gt;it checks one element (or an array of them) against another one and returns the itens that matched the hit test (if the element superposes the other one in any place)&lt;br /&gt;&lt;br /&gt;[UPDATED CODE AND HELP CAN BE FOUND HERE]&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;code&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com/geral/hittest [v1.0]&lt;br /&gt;&lt;br /&gt;hitTest = function(o, l){&lt;br /&gt;	function getOffset(o){&lt;br /&gt;		for(var r = {l: o.offsetLeft, t: o.offsetTop, r: o.offsetWidth, b: o.offsetHeight};&lt;br /&gt;			o = o.offsetParent; r.l += o.offsetLeft, r.t += o.offsetTop);&lt;br /&gt;		return r.r += r.l, r.b += r.t, r;&lt;br /&gt;	}&lt;br /&gt;	for(var b, s, r = [], a = getOffset(o), j = isNaN(l.length), i = (j ? l = [l] : l).length; i;&lt;br /&gt;		b = getOffset(l[--i]), (a.l == b.l || (a.l &gt; b.l ? a.l &lt;= b.r : b.l &lt;= a.r))&lt;br /&gt;		&amp;&amp; (a.t == b.t || (a.t &gt; b.t ? a.t &lt;= b.b : b.t &lt;= a.b)) &amp;&amp; (r[r.length] = l[i]));&lt;br /&gt;	return j ? !!r.length : r;&lt;br /&gt;};&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;usage&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;style type="text/css"&gt;&lt;br /&gt;#menu{position: absolute; height: 500px; width: 200px; display: none; border: 1px solid #999; background: #eef;}&lt;br /&gt;&lt;/style&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="menu"&gt;&lt;br /&gt;    &lt;input type="button" onclick="hide();" value="Hide Menu" /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;form action=""&gt;&lt;br /&gt;    &lt;fieldset&gt;&lt;br /&gt;    &lt;strong&gt;DIV x SELECT&lt;/strong&gt;&lt;br /&gt;    &lt;br /&gt;&lt;select&gt;&lt;option&gt;DIV OVER SELECT DIV OVER SELECT DIV OVER SELECT&lt;/option&gt;&lt;/select&gt;&lt;br /&gt;    &lt;input type="button" onclick="show();" value="Show Menu" /&gt;&lt;br /&gt;    &lt;/fieldset&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;//&lt;![CDATA[&lt;br /&gt;&lt;br /&gt;var x = document.getElementById("menu");&lt;br /&gt;&lt;br /&gt;//exemplo de como consertar o problema do select em cima do div, como s&#243; acontece no IE, &#233; poss&#237;vel sniffar o browser...&lt;br /&gt;&lt;br /&gt;function show(){&lt;br /&gt;    x.style.display = "block";&lt;br /&gt;    if(!x.ieFix)&lt;br /&gt;        x.ieFix = hitTest(x, document.getElementsByTagName("select"));&lt;br /&gt;    for(var i = x.ieFix.length; i; x.ieFix[--i].style.visibility = "hidden");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function hide(){&lt;br /&gt;    x.style.display = "none";&lt;br /&gt;    for(var i = x.ieFix.length; i; x.ieFix[--i].style.visibility = "visible");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//]]&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 24 Nov 2005 18:55:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/913</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
  </channel>
</rss>
