a Previous forum bug post back in 2004 for $onpoly() can be read here about dealing with polygons with zero volume.

I'm not sure if $onpoly() by design is supposed to only report if two polygons overlap on any of the linesegments that connect the dots intersect, or also include if a polygon is completely within another polygon without any intersections.

I assumed onpoly was supposed to treat one within another as overlapping. As is now, onpoly only returns true if a polygon inside another polygon has volume. I've setup a simple script to demonstrate these cases.

If this way is wrong, and it's a bug for a polygon to report true if it's completely contained inside another polygon, maybe we need an $insidepoly() test case or a .inside prop for $onpoly()? Can't be $inpoly() since this already exists and is for if a point is within a defined polygon...

I'd actually prefer it if it returned true for these cases for my usage, because in all reality the polygon in question is on the surface of another polygon. To me, two polygons overlap if ANY points within the surface (including it's permiter) of each polygon share the same space. I spent hours debugging a project to find out it's $Onpoly() and not my code smile

Although the simplest solution here is to just check if both endpoints are inside the polygon, this introduces heavy latency, especially with large polygon definitions because now I have to test the same polygon 3 times. once to see if it returns false with $onpoly(), once to see if endpoint A is within $inpoly(), and once to see if endpoint B is within $inpoly().

Definitions about colors here suggest you have'nt altered your mIRC's color pallettes in alt+k, if you have, these distinctions by color may not make sense to you.

If you start up "/onpolytest" when you move the mouse, it tells you if two polygons overlap, and highlights the polygon in orange. It then tries to break down the polygon and report which line segments (polygons with zero volume) are causing the overall polygon to return true.

Points within a polygon are highlighted in green, and linesegments are highlighted in red to show what regions are affected.

Since mIRC is NOT reporting a lineseg polygon as overlapping when it's completely contained within the polygon, these are highlighted in yellow.

Move your mouse around the default test case, and test a "short line" that fits within the mouse's polygon to illustrate.

Furthermore to illustrate that this onpoly test fails, you can right click and change the "Mouse" polygon to line, and put it within the bounds of the main polygon, and the main polygon will NEVER highlight in orange.

You can also test other polygons by changing either the Poly, or the Mouse poly in the right click dropdown menu.

Code:
menu @OnPolyTest {
  mouse {
    var %hw = $window($active).dw / 2 , %hh = $window($active).dh / 2
    var %x = $mouse.x - %hw , %y = $mouse.y - %hh

    tokenize 32 $window($active).title
    var %Poly = $1 , %Mouse = $2

    var %Polygon = $OPT.TranslatePolygon($OPT.Polygons(%Poly),0,0,0,2) , %P44 = $regsubex(%Polygon,/\s/g,$chr(44))
    var %PolyClosed = %Polygon $gettok(%Polygon,1-2,32)
    var %PCount = $numtok(%Polygon,32) , %Points = %PCount / 2    

    var %Cursor = $OPT.TranslatePolygon($OPT.Polygons(%Mouse),0,%x,%y,2) , %C44 = $regsubex(%Cursor,/\s/g,$chr(44))
    var %CCount = $numtok(%Cursor,32) , %CPoints = %CCount / 2    

    .onpolytest
    if ($onpoly(%CPoints,%Points, [ %C44 ] , [ %P44 ] )) {
      drawtext -n $active 0 0 0 *** Bounding Box on polygon
      var %np = $OPT.TranslatePolygon(%Polygon,0,%hw,%hh)
      drawline -n @OnpolyTest 7 1 %np $gettok(%np,1-2,32)

      var %c = 1 , %d = 4
      while (%c <= %PCount) {
        var %Seg = $gettok(%PolyClosed,$+(%c,-,%d),32)
        tokenize 32 %Seg
        if ($onpoly(%CPoints,2, [ %C44 ] , [ $regsubex($1-,/\s/g,$chr(44)) ] )) { drawline -n @OnPolyTest 4 1 $regsubex($1-,/([^ ]+) ([^ ]+)/g,$calc(\1 + %hw) $calc(\2 + %hh)) }
        elseif ($inpoly($1,$2, [ %C44 ] ) || $inpoly($3,$4, [ %C44 ] )) { drawline -n @OnPolyTest 8 3 $regsubex($1-,/([^ ]+) ([^ ]+)/g,$calc(\1 + %hw) $calc(\2 + %hh)) }

        if ($inpoly($1,$2, [ %C44 ] )) { drawdot -n @OnPolyTest 3 4 $calc($1 + %hw) $calc($2 + %hh) }
        if ($inpoly($3,$4, [ %C44 ] )) { drawdot -n @OnPolyTest 3 4 $calc($3 + %hw) $calc($4 + %hh) }
        var %c = %c + 2 , %d = %d + 2
      }
    }
    drawdot @OnPolyTest
  }
  Polygon
  .Box:opt.changepoly 1 box
  .largeRock1:opt.changepoly 1 largeRock1
  .largeRock2:opt.changepoly 1 largeRock2
  .largeRock3:opt.changepoly 1 largeRock3
  .medRock1:opt.changepoly 1 medRock1
  .medRock2:opt.changepoly 1 medRock2
  .medRock3:opt.changepoly 1 medRock3
  .smallRock1:opt.changepoly 1 smallRock1
  .smallRock2:opt.changepoly 1 smallRock2
  .smallRock3:opt.changepoly 1 smallRock3
  Mouse
  .line:opt.changepoly 2 line
  .Box:opt.changepoly 2 box
  .largeRock1:opt.changepoly 2 largeRock1
  .largeRock2:opt.changepoly 2 largeRock2
  .largeRock3:opt.changepoly 2 largeRock3
  .medRock1:opt.changepoly 2 medRock1
  .medRock2:opt.changepoly 2 medRock2
  .medRock3:opt.changepoly 2 medRock3
  .smallRock1:opt.changepoly 2 smallRock1
  .smallRock2:opt.changepoly 2 smallRock2
  .smallRock3:opt.changepoly 2 smallRock3
}
alias onpolytest {
  if (!$window(@OnPolyTest)) { 
    window -dpf @OnPolyTest -1 -1 640 480 
    titlebar @OnPolyTest largeRock1 box
  }
  tokenize 32 $window(@OnPolyTest).title
  var %Poly = $1 , %Mouse = $2
  var %w = $window(@OnPolyTest).dw , %h = $window(@OnPolyTest).dh , %hw = %w / 2 , %hh = %h / 2
  drawrect -nf @OnPolytest 1 1 0 0 %w %h
  var %Poly = $OPT.TranslatePolygon($OPT.Polygons(%Poly),0,%hw,%hh,2)
  drawline -n @OnpolyTest 0 1 %poly $gettok(%poly,1-2,32)

  var %poly = $OPT.TranslatePolygon($OPT.Polygons(%Mouse),0,$Mouse.x,$Mouse.y,2)
  drawline -n @OnpolyTest 0 1 %poly $gettok(%poly,1-2,32)
  if ($show) { drawdot @OnPolyTest }
}
alias -l OPT.changepoly {
  var %target = $1 , %val = $2
  tokenize 32 $window(@OnPolyTest).title
  var %Poly = $1 , %Mouse = $2
  if (%target = 1) { %Poly = %val }
  else { %Mouse = %val }
  titlebar @OnPolyTest %Poly %Mouse
}
alias -l OPT.Polygons {
  if ($1 = line) { return -10 0 10 0 }
  if ($1 = box) { return -10 -10 10 -10 10 10 -10 10 }
  if ($1 = largeRock1) { return -39 -25 -33 -8 -38 21 -23 25 -13 39 24 34 38 7 33 -15 38 -31 16 -39 -4 -34 -16 -39 }
  if ($1 = largeRock2) { return -32 35 -4 32 24 38 38 23 31 -4 38 -25 14 -39 -28 -31 -39 -16 -31 4 -38 22 }
  if ($1 = largeRock3) { return 12 -39 -2 -26 -28 -37 -38 -14 -21 9 -34 34 -6 38 35 23 21 -14 36 -25 }
  if ($1 = medRock1) { return -7 -19 -19 -15 -12 -5 -19 0 -19 13 -9 19 12 16 18 11 13 6 19 -1 16 -17 }
  if ($1 = medRock2) { return 9 -19 18 -8 7 0 15 15 -7 13 -16 17 -18 3 -13 -6 -16 -17 }
  if ($1 = medRock3) { return 2 18 18 10 8 0 18 -13 6 -18 -17 -14 -10 -3 -13 15 }
  if ($1 = smallRock1) { return -8 -8 -5 -1 -8 3 0 9 8 4 8 -5 1 -9 }     
  if ($1 = smallRock2) { return -6 8 1 4 8 7 10 -1 4 -10 -8 -6 -4 0 }
  if ($1 = smallRock3) { return -8 -9 -5 -2 -8 5 6 8 9 6 7 -3 9 -9 0 -7 }
}
alias -l OPT.TranslatePolygon {  
  var %dx = $cos($2).deg , %dy = $sin($2).deg , %ox = $3 , %oy = $4 , %scale = $iif($5,$5,1)
  return $regsubex($1,/([^ ]+) ([^ ]+)/g,$calc(((\1 * %dx + \2 * (%dy * -1)) * %scale) + %ox) $calc(((\1 * %dy + \2 * %dx) * %scale) + %oy))
}