Skip to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[2.3.81] Area#getPositions fails if the Area is constructed using a position array

Featured Replies

Description of the bug / error:

If an Area is constructed using x and y boundaries like so:

final Area boundedArea = new Area(3094,3241,3095,3243);

Then boundedArea.getPositions(0) correctly returns the 6 positions. (This is a rectangular area of 6 squares in Draynor bank).

 

But if the Area is constructed using an array of Positions like so:

    final Area positionArrayArea = new Area(new Position[] {new Position(3094,3243,0), new Position(3094,3242,0), new Position(3094,3241,0), new Position(3095,3243,0), new Position(3095,3242,0), new Position(3095,3241,0)});

Then positionArrayArea.getPositions(0) returns just 1 position, which is (0,0,0).

 

SSCCE to reproduce:

import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.Area;

import java.awt.*;

@ScriptManifest(author="Normangorman", info="", name="Test script", version=2, logo="")
public class TestScript extends Script {

    final Area boundedArea = new Area(3094,3241,3095,3243);
    final Area positionArrayArea = new Area(new Position[] {new Position(3094,3243,0), new Position(3094,3242,0), new Position(3094,3241,0), new Position(3095,3243,0), new Position(3095,3242,0), new Position(3095,3241,0)});

    public void onStart() {
        log("SCRIPT STARTING");
    }

    @Override
    public int onLoop() {
        // Logs 6:
        log("boundedArea.getPositions(0).size() = " + boundedArea.getPositions(0).size());

        // Logs 1:
        log("positionArrayArea.getPositions(0).size() = " + positionArrayArea.getPositions(0).size());
        return 100;
    }

    @Override
    public void onPaint(Graphics2D g) {
        super.onPaint(g);
        g.setColor(Color.yellow);
        // This works correctly
        /*
        for (Position p : boundedArea.getPositions(0)) {
            log("drawing position x:" + p.getX() + " y:" + p.getY());
            g.drawPolygon(p.getPolygon(bot));
        }
        */

        // This does not draw anything. The position that is returned is (0,0,0).
        for (Position p : positionArrayArea.getPositions(0)) {
            log("drawing position x:" + p.getX() + " y:" + p.getY());
            g.drawPolygon(p.getPolygon(bot));
        }
    }
}

Screenshot of the correct area that is drawn using boundedArea:

 

post-175480-0-76439000-1436704867_thumb.png

  • Administrator

Area.getPositions() actually relies on minX/Y/etc to calculate the areas. The contains() methods should work. I'll look into a few possible fixes when I get the chance.

 

@Alek

Any thoughts on this?

  • Author

Area.getPositions() actually relies on minX/Y/etc to calculate the areas. The contains() methods should work. I'll look into a few possible fixes when I get the chance.

 

@Alek

Any thoughts on this?

 

When you say this, do you mean that the list of positions given isn't actually 'remembered' so to speak - but rather just the minimum / maximum x and y values? Does this mean that OSBot areas are always modelled as rectangles?

 

In a project I'm working on I've reimplemented the Area class using a more efficient, immutable data structure (http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/ImmutableSet.html). I have found the performance to be better especially when the contains() method needs to be checked very frequently. If you are interested then I will send you this code.

  • Administrator

When you say this, do you mean that the list of positions given isn't actually 'remembered' so to speak - but rather just the minimum / maximum x and y values? Does this mean that OSBot areas are always modelled as rectangles?

 

In a project I'm working on I've reimplemented the Area class using a more efficient, immutable data structure (http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/ImmutableSet.html). I have found the performance to be better especially when the contains() method needs to be checked very frequently. If you are interested then I will send you this code.

 

The class is backed by the Area class. Area calculations date back to Laz's code and probably when it used to just be rectangles.

I asked for Alek's input because he knows the API far better than I do. I'd be interested in seeing your code, but I don't know if we'll end up using it or implementing a different solution.

I actually wrote a chunk of the Area class, in specific the method you are talking about. Areas are modeled as rectangles whereas PolygonArea allows you to make, polygon areas. I'll look over both the classes in an hour or so.

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.