Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maplibre/geometry.hpp
C++ geometry types
https://github.com/maplibre/geometry.hpp
Last synced: 5 days ago
JSON representation
C++ geometry types
- Host: GitHub
- URL: https://github.com/maplibre/geometry.hpp
- Owner: maplibre
- License: isc
- Created: 2024-10-14T23:15:46.000Z (29 days ago)
- Default Branch: main
- Last Pushed: 2024-10-21T22:18:59.000Z (22 days ago)
- Last Synced: 2024-11-04T12:27:08.480Z (9 days ago)
- Language: C++
- Homepage:
- Size: 150 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE-OF-CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
[![MapLibre Logo](https://maplibre.org/img/maplibre-logo-big.svg)](https://maplibre.org/)
# geometry.hpp
Provides header-only, generic C++ interfaces for geometry types, geometry collections, and features.
- `maplibre::geometry::point`
- `maplibre::geometry::multi_point`
- `maplibre::geometry::line_string`
- `maplibre::geometry::multi_line_string`
- `maplibre::geometry::polygon`
- `maplibre::geometry::multi_polygon`
- `maplibre::geometry::geometry_collection`
- `maplibre::feature::feature`Dependency of [MapLibre Native](https://github.com/maplibre/maplibre-native).
### Design
These types are designed to be easy to parse and serialize to [GeoJSON](http://geojson.org/).
They should also be a robust and high performance container for data processing and conversion.
### Goals
- Header-only
- Fast compile
- C++20
- No external dependencies for usage of core types (point, line_string, etc)
- No dependencies for usage of enclosing `geometry` type
- Easily [adaptable to `boost::geometry`](http://www.boost.org/doc/libs/1_56_0/libs/geometry/doc/html/geometry/examples/example__adapting_a_legacy_geometry_object_model.html)### Usage
Using a single type directly:
```cpp
#include
#includeusing maplibre::geometry::point;
int main() {
point pt(1.0,0.0);
std::clog << "x: " << pt.x << " y: " << pt.y << "\n";
}
```Creating a geometry collection:
```cpp
#include
#include
#includeusing maplibre::geometry::geometry_collection;
using maplibre::geometry::geometry;
using maplibre::geometry::point;using point_type = point;
struct printer
{
printer() {}void operator()(point_type const& pt) const
{
std::clog << "x: " << pt.x << " y: " << pt.y << "\n";
}template
void operator()(T const& g) const
{
std::clog << "encountered non-point geometry\n";
}
};int main() {
geometry_collection gc;
gc.emplace_back(point_type(1.0,0.0));
geometry const& geom = gc.at(0);
printer visitor;
std::visit(visitor, geom);
}
```