Skip to content
This repository was archived by the owner on Feb 11, 2026. It is now read-only.
This repository was archived by the owner on Feb 11, 2026. It is now read-only.

largestRect not correct  #108

@bhaktatejas922

Description

@bhaktatejas922

Expected Behavior

I should be getting a max rectangle but I get some really weird results. Why is this happening? Using lat/long for my points as shown

Current Behavior

https://stackoverflow.com/questions/74083520/non-max-rectangle-when-using-d3plus-largestrect

Steps to Reproduce (for bugs)

  1. use this geojson and code here https://stackoverflow.com/questions/74083520/non-max-rectangle-when-using-d3plus-largestrect

When I use d3plus.largestRect it often doesnt return the largest inscribed rectangle. Any ideas whats going on, or what I should do to try to debug?

Someone took it from d3plus and made it its own repo here if its helpful.

https://github.com/rossjs/largest-rect-in-poly-geojson

export function maxRect(polygon, userOptions) {
    // polygon is a geojson polygon and aspectRatio is a number that is the ratio of width to height
    // we want to return a geojson polygon that is the maximum rectangle that fits inside the polygon
    // and has the given aspect ratio
    // we need to convert the geojson polygon to an array of points
    var points = polygon.coordinates[0].map(function (coord) {
        return [coord[0], coord[1]];
    });
    if (userOptions) {
        console.log("userOptions", userOptions)
        var options = userOptions;
    } else {
        var options = {
        };
    }
    // we use d3plus to calculate the rectangle
    // aspect ratio is the ratio of width to height
    // var rect = largestRectInPoly(points, options);
    var rect = largestRect(points, options);
    console.log(rect)
    return rect;
}

Example where rectangle is wrong. This happens regardless of which options I pass to it

{
                    "type": "Polygon",
                    "coordinates": [
                        [
                            [
                                -121.498361304,
                                38.622343198
                            ],
                            [
                                -121.498593986,
                                38.622343198
                            ],
                            [
                                -121.498593986,
                                38.622508322
                            ],
                            [
                                -121.498565407,
                                38.622508355
                            ],
                            [
                                -121.498565823,
                                38.622465787
                            ],
                            [
                                -121.498410255,
                                38.622463692
                            ],
                            [
                                -121.498409129,
                                38.622508534
                            ],
                            [
                                -121.498361664,
                                38.622508588
                            ],
                            [
                                -121.498361304,
                                38.622343198
                            ]
                        ]
                    ]
                }

Some examples:

example above in geojson format
more
more

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions