Skip to content

Conversation

@Gambitnl
Copy link
Owner

@Gambitnl Gambitnl commented Aug 4, 2025

Fixes "Bad walled area shape!" error by correcting the contains method in web/src/types/polygon.ts.

The CurtainWall.buildGates method was failing because patchByVertex was not finding any valid entrances. This was due to an incorrect implementation of the contains method in web/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.


Open in Cursor Open in Web

Learn more about Cursor Agents

Co-authored-by: cranenre <cranenre@gmail.com>
@vercel
Copy link

vercel bot commented Aug 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Project Deployment Preview Comments Updated (UTC)
town-generator-os Ready Preview Comment Aug 12, 2025 9:35pm

Copy link

@gemini-code-assist gemini-code-assist bot left a 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.buildGates method failing to identify valid entrances, which was traced back to an incorrect polygon containment check.
  • Core Logic Correction: The contains method within the Polygon class in web/src/types/polygon.ts has 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

  1. 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.

@Gambitnl Gambitnl marked this pull request as ready for review August 4, 2025 21:04
Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines 65 to 77
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;
}

Choose a reason for hiding this comment

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

high

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>
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.

3 participants