- From: Orion Reed via GitHub <noreply@w3.org>
- Date: Sun, 06 Jul 2025 13:18:52 +0000
- To: public-fxtf-archive@w3.org
As someone who's spent quite some time with geometry libraries I can speak a little to the utilities commonly found in these libraries. These would apply to `DOMRect`, `DOMQuad` and a future `DOMPolygon` but not `DOMPoint` or a speculative `DOMPath/DOMPolyline` (the names hare are just for illustration, not a specific proposal) ### Geometric Properties - `getArea()` - polygon area (these are sometimes [signed to indicate winding](https://en.wikipedia.org/wiki/Shoelace_formula) as a natural consequence of algorithms used) - `getPerimeter()` - total edge length - `getCentroid()` - geometric center point - `getBounds()` - axis-aligned bounding rect - `getWinding() - whether the vertices are ordered clockwise or counterclockwise *also common but can be more expensive:* - `isConvex()` - [convexity](https://en.wikipedia.org/wiki/Convex_polygon) test - `isSimple()` - true if there is no self-intersection - misc validity checks are also common for ensuring winding and so on, but the convention for existing geometry interfaces is to not do any of those checks so I'm omitting them here ### Spatial Queries/Testing - `containsPoint(point)` - point-in-polygon testing - in the case of separate overlap/touch tests, something like a `containsStrict(point)` would make sense to match those tests (see comment below) - `contains(polygon)` - polygon-in-polygon testing - `intersects(polygon)` - any contact/relationship between polygons - `overlaps(polygon)` - shared interior area (excludes boundary-only contact) - `touches(polygon, tolerance)` - shares boundary but no interior overlap - `getClosestPoint(point)` - nearest point on polygon boundary - `distanceTo(point | polygon)` - shortest distance between shapes ^ there are certainly plenty of libraries where touches vs overlaps vs intersects are combined into something like an `intersects` but I wanted to split them here for clarity on common patterns and to help avoid future footguns if we pick a subset for initial implementation. See for example [turfjs](https://turfjs.org/docs/api/booleanTouches) or [PostGIS](https://en.wikipedia.org/wiki/PostGIS) whose conventions are followed in other libraries too. ### Geometric Operations - `union(polygon)` - boolean union (returns new polygon) - `intersection(polygon)` - boolean intersection - `difference(polygon)` - boolean subtraction - `buffer(distance)` - expand/contract polygon by distance ^ these would not be recommended without a `DOMPolygon` interface, because combining `DOMRect` and `DOMQuad` here would not always produce rects or quads. -- GitHub Notification of comment by OrionReed Please view or discuss this issue at https://github.com/w3c/fxtf-drafts/issues/602#issuecomment-3041491334 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Sunday, 6 July 2025 13:18:53 UTC