-
Notifications
You must be signed in to change notification settings - Fork 2
Debug bad walled area shape in town scene #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Debug bad walled area shape in town scene #4
Conversation
Co-authored-by: cranenre <cranenre@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @Gambitnl, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request addresses a critical bug related to scene generation by fixing an incorrect geometric calculation. The core change involves updating the point-in-polygon logic to ensure accurate spatial reasoning, which in turn resolves issues with walled area shapes in the town scene.
Highlights
- Bug Fix: This pull request resolves the 'Bad walled area shape!' error encountered in the town scene. The error stemmed from the
CurtainWall.buildGatesmethod failing to identify valid entrances, which was traced back to an incorrect polygon containment check. - Core Logic Correction: The
containsmethod within thePolygonclass inweb/src/types/polygon.tshas been fundamentally corrected. Previously, it only checked if a point was one of the polygon's vertices, leading to incorrect geometric evaluations. It now employs a robust ray casting algorithm to accurately determine if a point lies within the polygon's boundaries.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request fixes a bug in the Polygon.contains method by replacing a simple vertex check with a proper ray-casting algorithm for point-in-polygon testing. The change is correct for identifying points inside a polygon. My review focuses on a subtle change in behavior for points on the polygon's boundary, which are no longer considered "contained". I've suggested an improvement to handle vertices correctly to avoid potential regressions, making the method more robust.
| public contains(v: Point): boolean { | ||
| return this.vertices.some(p => p.x === v.x && p.y === v.y); | ||
| // Ray casting algorithm for point-in-polygon test | ||
| let inside = false; | ||
| for (let i = 0, j = this.vertices.length - 1; i < this.vertices.length; j = i++) { | ||
| const xi = this.vertices[i].x, yi = this.vertices[i].y; | ||
| const xj = this.vertices[j].x, yj = this.vertices[j].y; | ||
|
|
||
| const intersect = ((yi > v.y) !== (yj > v.y)) && | ||
| (v.x < (xj - xi) * (v.y - yi) / (yj - yi) + xi); | ||
| if (intersect) inside = !inside; | ||
| } | ||
| return inside; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new implementation correctly identifies points strictly inside the polygon, which fixes the described bug. This is a great improvement!
However, there's a subtle change in behavior for points on the boundary. The previous implementation returned true for vertices, but the new ray-casting algorithm will return false for all points on the boundary, including vertices.
This could lead to unexpected behavior if other parts of the code rely on contains being true for vertices.
To restore the previous behavior for vertices while keeping the new, correct check for interior points, I suggest adding the vertex check back at the beginning of the method. This is a minimal change that addresses the regression for vertices.
Note that with this change, points on an edge that are not vertices will still be considered outside. A full boundary check would be more robust but also more complex.
public contains(v: Point): boolean {
// The previous implementation returned true for vertices. To maintain this behavior
// for vertices while correctly checking for interior points, we can check for
// vertex containment first. Note that other points on the boundary will still
// be considered outside with this approach.
if (this.vertices.some(p => p.x === v.x && p.y === v.y)) {
return true;
}
// Ray casting algorithm for point-in-polygon test
let inside = false;
for (let i = 0, j = this.vertices.length - 1; i < this.vertices.length; j = i++) {
const xi = this.vertices[i].x, yi = this.vertices[i].y;
const xj = this.vertices[j].x, yj = this.vertices[j].y;
const intersect = ((yi > v.y) !== (yj > v.y)) &&
(v.x < (xj - xi) * (v.y - yi) / (yj - yi) + xi);
if (intersect) inside = !inside;
}
return inside;
}Co-authored-by: cranenre <cranenre@gmail.com>
Co-authored-by: cranenre <cranenre@gmail.com>
…n logic Co-authored-by: cranenre <cranenre@gmail.com>
…design Co-authored-by: cranenre <cranenre@gmail.com>
Fixes "Bad walled area shape!" error by correcting the
containsmethod inweb/src/types/polygon.ts.The
CurtainWall.buildGatesmethod was failing becausepatchByVertexwas not finding any valid entrances. This was due to an incorrect implementation of thecontainsmethod inweb/src/types/polygon.ts, which only checked if a point was a vertex, not if it was inside the polygon. The fix replaces this with a proper ray casting algorithm for point-in-polygon testing.Learn more about Cursor Agents