Skip to content

chore(Rs2Walker): isInArea#1464

Merged
chsami merged 2 commits intochsami:developmentfrom
Sunny-P:chore(Rs2Walker)_isInArea
Sep 4, 2025
Merged

chore(Rs2Walker): isInArea#1464
chsami merged 2 commits intochsami:developmentfrom
Sunny-P:chore(Rs2Walker)_isInArea

Conversation

@Sunny-P
Copy link
Contributor

@Sunny-P Sunny-P commented Sep 3, 2025

The logic for the isInArea() methods are backwards.
This change doesn't change the actual logic, but changes the method description to properly reflect the logic that's applied.

The overloaded isInArea() method that takes in a centre point and a range previously created a rectangle with larger offsets on the x value, rather than an equally sided square with the calculated corners. This is now changed to create an equally sided square around the centre point. Was there a reason we were creating horizontally favoured rectangle areas?

These pedantic changes better reflect the applied logic without changing the original logic (besides creating an equal-sided area, instead of a horizontally favoured rectangle), so this shouldn't have any affect on the current usages of these methods in other scripts/plugins.

I originally became aware of this flawed logic when I tried to use the isInArea(WorldPoint... worldPoints) method to determine if I had the player in a certain area using custom points, instead of the simpler to use overloaded method isInArea(WorldPoint centerOfArea, int range), and of course I ran into problems before looking into how the methods were operating.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 3, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

  • In Rs2Walker.java, updated comments for isInArea(WorldPoint...) to state parameters are SE and NW corners.
  • Modified isInArea(WorldPoint... worldPoints) so worldPoints[0] is treated as SE and worldPoints[1] as NW, with corresponding boundary checks adjusted.
  • Updated isInArea(centerOfArea, int range) to compute seCorner and nwCorner accordingly and call isInArea(seCorner, nwCorner).
  • No public method signatures changed; updates are limited to documentation and internal logic.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/walker/Rs2Walker.java (2)

1954-1956: Clarify parameter order and bounds in Javadoc.

Explicitly state indexing and inclusivity to avoid ambiguity.

- * @param worldPoints an array of two world points of the SE and NW corners of the area
+ * @param worldPoints exactly two points: worldPoints[0] = SE, worldPoints[1] = NW; bounds are inclusive
+ * @throws IllegalArgumentException if fewer than two points are provided or any point is null

1975-1977: Handle negative range defensively.

Using Math.abs avoids inverted corners from accidental negative input.

-        WorldPoint seCorner = new WorldPoint(centerOfArea.getX() + range, centerOfArea.getY() - range, centerOfArea.getPlane());
-        WorldPoint nwCorner = new WorldPoint(centerOfArea.getX() - range, centerOfArea.getY() + range, centerOfArea.getPlane());
+        int r = Math.abs(range);
+        WorldPoint seCorner = new WorldPoint(centerOfArea.getX() + r, centerOfArea.getY() - r, centerOfArea.getPlane());
+        WorldPoint nwCorner = new WorldPoint(centerOfArea.getX() - r, centerOfArea.getY() + r, centerOfArea.getPlane());
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bcb803e and 142b89e.

📒 Files selected for processing (1)
  • runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/walker/Rs2Walker.java (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/walker/Rs2Walker.java (1)
runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/player/Rs2Player.java (1)
  • Rs2Player (67-2070)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build

Comment on lines 1957 to 1962
public static boolean isInArea(WorldPoint... worldPoints) {
WorldPoint playerLocation = Rs2Player.getWorldLocation();
return playerLocation.getX() <= worldPoints[0].getX() && // NW corner x
playerLocation.getY() >= worldPoints[0].getY() && // NW corner y
playerLocation.getX() >= worldPoints[1].getX() && // SE corner x
playerLocation.getY() <= worldPoints[1].getY(); // SE corner Y
return playerLocation.getX() <= worldPoints[0].getX() && // SE corner x
playerLocation.getY() >= worldPoints[0].getY() && // SE corner y
playerLocation.getX() >= worldPoints[1].getX() && // NW corner x
playerLocation.getY() <= worldPoints[1].getY(); // NW corner Y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add input validation and make corner order robust (prevents AIOOBE/NPE and avoids subtle call-site breakage).

Currently this will throw if fewer than two points are passed; also strictly requiring SE/NW order is brittle. Compute min/max instead.

-    public static boolean isInArea(WorldPoint... worldPoints) {
-        WorldPoint playerLocation = Rs2Player.getWorldLocation();
-        return playerLocation.getX() <= worldPoints[0].getX() &&   // SE corner x
-                playerLocation.getY() >= worldPoints[0].getY() &&   // SE corner y
-                playerLocation.getX() >= worldPoints[1].getX() &&   // NW corner x
-                playerLocation.getY() <= worldPoints[1].getY();     // NW corner Y
-        // draws box from 2 points to check against all variations of player X,Y from said points.
-    }
+    public static boolean isInArea(WorldPoint... worldPoints) {
+        if (worldPoints == null || worldPoints.length < 2 || worldPoints[0] == null || worldPoints[1] == null) {
+            throw new IllegalArgumentException("isInArea requires two WorldPoints (SE, NW).");
+        }
+        final WorldPoint playerLocation = Rs2Player.getWorldLocation();
+        final WorldPoint a = worldPoints[0];
+        final WorldPoint b = worldPoints[1];
+        final int minX = Math.min(a.getX(), b.getX());
+        final int maxX = Math.max(a.getX(), b.getX());
+        final int minY = Math.min(a.getY(), b.getY());
+        final int maxY = Math.max(a.getY(), b.getY());
+        return playerLocation.getX() >= minX && playerLocation.getX() <= maxX
+            && playerLocation.getY() >= minY && playerLocation.getY() <= maxY;
+        // draws box from 2 points to check against all variations of player X,Y from said points.
+    }

Optional: also require planes to match if that’s the intended semantic for “area” on multi-level maps.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public static boolean isInArea(WorldPoint... worldPoints) {
WorldPoint playerLocation = Rs2Player.getWorldLocation();
return playerLocation.getX() <= worldPoints[0].getX() && // NW corner x
playerLocation.getY() >= worldPoints[0].getY() && // NW corner y
playerLocation.getX() >= worldPoints[1].getX() && // SE corner x
playerLocation.getY() <= worldPoints[1].getY(); // SE corner Y
return playerLocation.getX() <= worldPoints[0].getX() && // SE corner x
playerLocation.getY() >= worldPoints[0].getY() && // SE corner y
playerLocation.getX() >= worldPoints[1].getX() && // NW corner x
playerLocation.getY() <= worldPoints[1].getY(); // NW corner Y
public static boolean isInArea(WorldPoint... worldPoints) {
if (worldPoints == null || worldPoints.length < 2 || worldPoints[0] == null || worldPoints[1] == null) {
throw new IllegalArgumentException("isInArea requires two WorldPoints (SE, NW).");
}
final WorldPoint playerLocation = Rs2Player.getWorldLocation();
final WorldPoint a = worldPoints[0];
final WorldPoint b = worldPoints[1];
final int minX = Math.min(a.getX(), b.getX());
final int maxX = Math.max(a.getX(), b.getX());
final int minY = Math.min(a.getY(), b.getY());
final int maxY = Math.max(a.getY(), b.getY());
return playerLocation.getX() >= minX && playerLocation.getX() <= maxX
&& playerLocation.getY() >= minY && playerLocation.getY() <= maxY;
// draws box from 2 points to check against all variations of player X,Y from said points.
}
🤖 Prompt for AI Agents
In
runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/walker/Rs2Walker.java
around lines 1957 to 1962, the isInArea(WorldPoint... worldPoints) method lacks
input validation and assumes the two points are provided in SE/NW order; add a
check that worldPoints is non-null and has at least two non-null elements and
throw IllegalArgumentException (or return false) on invalid input, then compute
int minX = Math.min(p0.getX(), p1.getX()), maxX = Math.max(p0.getX(),
p1.getX()), and similarly minY/maxY and test playerLocation.getX()/getY()
against those bounds so corner order is irrelevant; optionally also compare
getPlane() for equality if multi-level area semantics are required.

Checks to ensure two world points are used. Cached values from getter methods to keep as performant as possible.
Updated method parameter description again to the more naturally read: NW then SE.
@Sunny-P
Copy link
Contributor Author

Sunny-P commented Sep 3, 2025

New commit should make isInArea(WorldPoint... worldPoints) more robust as it no longer matters which order we pass through our points.
Cache values from getter methods to keep calls to this method as performant as we can.

@Krulvis
Copy link
Contributor

Krulvis commented Sep 4, 2025

New commit should make isInArea(WorldPoint... worldPoints) more robust as it no longer matters which order we pass through our points. Cache values from getter methods to keep calls to this method as performant as we can.

damn nice coderabbitai fix <3 that really makes this PR golden

@Sunny-P
Copy link
Contributor Author

Sunny-P commented Sep 4, 2025

damn nice coderabbitai fix <3 that really makes this PR golden

Haha yeah, wasn't a bad suggestion. Tweaked it a little, but it was reasonable

@Krulvis
Copy link
Contributor

Krulvis commented Sep 4, 2025

damn nice coderabbitai fix <3 that really makes this PR golden

Haha yeah, wasn't a bad suggestion. Tweaked it a little, but it was reasonable

Reasonable is putting it very lightly

@chsami chsami merged commit fd75934 into chsami:development Sep 4, 2025
2 checks passed
*/
@Deprecated(since = "1.5.5", forRemoval = true)
public static boolean isInArea(WorldPoint centerOfArea, int range) {
WorldPoint nwCorner = new WorldPoint(centerOfArea.getX() + range + range, centerOfArea.getY() - range, centerOfArea.getPlane());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we not change it here to follow the logic of WorldArea, calculating the
northeast corner

ne = new WorldPoint(centerOfArea.getX() + radius, centerOfArea.getY() + radius, centerOfArea.getPlane()); 

and
southwest corner

sw  =  new WorldPoint(centerOfArea.getX() - radius, centerOfArea.getY() - radius,  centerOfArea.getPlane()); 

range -> radius ?
or better directly use use WorldArea

*/
public static boolean isInArea(WorldPoint... worldPoints) {
WorldPoint playerLocation = Rs2Player.getWorldLocation();
return playerLocation.getX() <= worldPoints[0].getX() && // NW corner x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the logic here too.

playerLocation.getX() >= worldPoints[0].getX() &&   // SW corner x
playerLocation.getY() >= worldPoints[0].getY() &&   // SW corner y
playerLocation.getX() <= worldPoints[1].getX() &&   // NE corner x
playerLocation.getY() <= worldPoints[1].getY();     // NE corner Y

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the logic here too.

playerLocation.getX() >= worldPoints[0].getX() &&   // SW corner x
playerLocation.getY() >= worldPoints[0].getY() &&   // SW corner y
playerLocation.getX() <= worldPoints[1].getX() &&   // NE corner x
playerLocation.getY() <= worldPoints[1].getY();     // NE corner Y

Im confused as to what you're referring to here. This was changed to not be so static in its approach.

@coderabbitai coderabbitai bot mentioned this pull request Oct 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants