Results 1 to 5 of 5

Thread: SPS.isInPolygon();

  1. #1
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default SPS.isInPolygon();

    This has been added to SPS-RS3, so no need to copy into your scripts


    A function that checks whether you are inside a polygon. This is more customisable than using a simple pointInBox. The polygon can have 3+ vertices, as demonstrated with the SPS Path Generator:







    Just declare your polygon as a TPA, exactly the same way you do when making a SPS path (you can just copy the TPA from the path generator):

    Simba Code:
    function TSPSArea.isInPolygon(const poly: array of TPoint): boolean;
    var
      p: TPoint;
      i, j: integer;
    begin
     result := false;
     p := self.getPlayerPos();
     j := high(poly);

     for i := low(poly) to high(poly) do
     begin
      if ((((poly[i].y <= p.y) and (p.y < poly[j].y)) or ((poly[j].y <= p.y) and
         (p.y < poly[i].y)) ) and (p.x < ((poly[j].x - poly[i].x) *
         (p.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x))) then
         result := not result;

      j := i;
     end;
    end;


    Some test code would look something like:

    Simba Code:
    var
      Polygon: array of TPoint;

    begin
      clearDebug();
      setupSRL();
      sps.setup('DRAYNOR_01', RUNESCAPE_OTHER);

      Polygon := [Point(159, 259), Point(117, 345), Point(224, 346), Point(173, 271)];

      repeat
        writeLn(sps.isInPolygon(Polygon));
      until false;
    end.
    Last edited by The Mayor; 05-22-2015 at 08:05 PM.

  2. #2
    Join Date
    Sep 2012
    Location
    Netherlands
    Posts
    2,752
    Mentioned
    193 Post(s)
    Quoted
    1468 Post(s)

    Default

    Gj mayor

  3. #3
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Nice work, mate.

  4. #4
    Join Date
    Feb 2013
    Location
    Rimmington
    Posts
    319
    Mentioned
    33 Post(s)
    Quoted
    183 Post(s)

    Default

    Quote Originally Posted by The Mayor View Post
    A function that checks whether you are inside a polygon. This is more customisable than using a simple pointInBox. The polygon can have 3+ vertices, as demonstrated with the SPS Path Generator:







    Just declare your polygon as a TPA, exactly the same way you do when making a SPS path (you can just copy the TPA from the path generator):

    Simba Code:
    function TSPSArea.isInPolygon(const poly: array of TPoint): boolean;
    var
      p: TPoint;
      i, j: integer;
    begin
     result := false;
     p := self.getPlayerPos();
     j := high(poly);

     for i := low(poly) to high(poly) do
     begin
      if ((((poly[i].y <= p.y) and (p.y < poly[j].y)) or ((poly[j].y <= p.y) and
         (p.y < poly[i].y)) ) and (p.x < ((poly[j].x - poly[i].x) *
         (p.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x))) then
         result := not result;

      j := i;
     end;
    end;


    Some test code would look something like:

    Simba Code:
    var
      Polygon: array of TPoint;

    begin
      clearDebug();
      setupSRL();
      sps.setup('DRAYNOR_01', RUNESCAPE_OTHER);

      Polygon := [Point(159, 259), Point(117, 345), Point(224, 346), Point(173, 271)];

      repeat
        writeLn(sps.isInPolygon(Polygon));
      until false;
    end.
    Nice, would you mind if I steal this for OSRS? (sometime in the future)

  5. #5
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •