Skip to content

isRightHandRule function #4

Description

@perrygeo

It looks like the current implementation only exports a rewind function that returns (and sometimes mutates) a geojson object.

I need a function that will check for the "Right Hand Rule" - ensure polygon geoms have counter-clockwise external rings, clockwise internal rings. I don't have any need for the altered geometry, just the boolean.

The best I've got so far:

var rewind = require("geojson-rewind");
function isRightHandRule(geom) {
    // Hack to deepcopy geom and avoid mutation
    geomstring = JSON.stringify(geom);
    geomcopy = JSON.parse(geomstring);

    // Does the original geometry match the clockwise-wound geometry
    return geomstring === JSON.stringify(rewind(geomcopy, true));
}

But this has some major flaws: it needs to deepcopy the geom via JSON strings, it relies on string comparison and it needs to rewind the entire geometry rather than failing fast on the first linear ring that doesn't match.

Any ideas on a better way to implement this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions