Skip to content
This repository was archived by the owner on May 26, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "GitHub Codespaces",
"name": "libgeohex",
"customizations": {
"vscode": {
"extensions": [
Expand All @@ -13,5 +13,6 @@
}
},
"dockerComposeFile": "./../compose.yaml",
"service": "shell"
"service": "shell",
"workspaceFolder": "/workspaces/libgeohex"
}
21 changes: 0 additions & 21 deletions .devcontainer/local/devcontainer.json

This file was deleted.

84 changes: 76 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,100 @@ on:
pull_request:
jobs:
Linux:
runs-on: ubuntu-latest
name: Linux (${{ matrix.display_platform }})
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
platform: ['linux/amd64', 'linux/arm64/v8', 'linux/s390x', 'linux/arm/v7']
include:
- display_platform: linux/amd64
platform: linux/amd64
runner: ubuntu-24.04
native_platform: linux/amd64
qemu_platforms: ""
run_sanitizers: "true"
- display_platform: linux/arm64
platform: linux/arm64
runner: ubuntu-24.04-arm
native_platform: linux/arm64
qemu_platforms: ""
run_sanitizers: "true"
- display_platform: linux/s390x
platform: linux/s390x
runner: ubuntu-24.04
native_platform: linux/amd64
qemu_platforms: s390x
run_sanitizers: "false"
- display_platform: linux/arm/v7
platform: linux/arm/v7
runner: ubuntu-24.04
native_platform: linux/amd64
qemu_platforms: arm
run_sanitizers: "false"
- display_platform: linux/i386
platform: linux/386
runner: ubuntu-24.04
native_platform: linux/amd64
qemu_platforms: "386"
run_sanitizers: "false"
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
submodules: true
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
if: matrix.qemu_platforms != ''
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
with:
platforms: "arm64,s390x,arm"
platforms: ${{ matrix.qemu_platforms }}
- name: Setup buildx
uses: docker/setup-buildx-action@v3
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- name: Build container
run: |
docker build --pull --no-cache --build-arg PLATFORM="${{ matrix.platform }}" --tag "test" .
docker buildx build \
--pull \
--no-cache \
--load \
--platform "${{ matrix.platform }}" \
--build-arg PLATFORM="${{ matrix.platform }}" \
--tag "test" \
.
- name: Test
run: |
docker run \
--platform "${{ matrix.platform }}" \
--privileged \
--cap-add SYS_ADMIN \
--security-opt seccomp:unconfined \
-e NATIVE_PLATFORM="linux/amd64" \
-e NATIVE_PLATFORM="${{ matrix.native_platform }}" \
-e RUN_SANITIZERS="${{ matrix.run_sanitizers }}" \
-v "$(pwd):/workspaces/libgeohex" \
-w "/workspaces/libgeohex" \
-i "test" \
./ci.sh
macOS:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Configure
run: cmake -S . -B build -DBUILD_TESTS=ON
- name: Build
run: cmake --build build --parallel
- name: Test
run: ctest --test-dir build --output-on-failure
Windows:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Configure
run: cmake -S . -B build -DBUILD_TESTS=ON
- name: Build
run: cmake --build build --config Debug --parallel
- name: Test
run: ctest --test-dir build --build-config Debug --output-on-failure
24 changes: 21 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.10)
project(libgeohex VERSION 1.1.1 LANGUAGES C)
project(libgeohex VERSION 2.0.0 LANGUAGES C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
Expand All @@ -15,6 +15,15 @@ option(BUILD_STATIC_LIBS "Build static libraries" ON)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)

set(GEOHEX_TARGETS)
set(GEOHEX_MATH_LIBRARIES)

if(NOT WIN32)
list(APPEND GEOHEX_MATH_LIBRARIES m)
endif()

if(WIN32)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endif()

if (BUILD_STATIC_LIBS)
add_library(geohex_static STATIC
Expand All @@ -28,7 +37,10 @@ if (BUILD_STATIC_LIBS)
$<INSTALL_INTERFACE:include>
)

target_link_libraries(geohex_static PUBLIC m)
target_compile_definitions(geohex_static PUBLIC GEOHEX_STATIC_DEFINE)
if(GEOHEX_MATH_LIBRARIES)
target_link_libraries(geohex_static PUBLIC ${GEOHEX_MATH_LIBRARIES})
endif()

list(APPEND GEOHEX_TARGETS geohex_static)
endif()
Expand All @@ -39,13 +51,19 @@ if(BUILD_SHARED_LIBS)
)

set_target_properties(geohex_shared PROPERTIES OUTPUT_NAME geohex)
if(WIN32)
set_target_properties(geohex_shared PROPERTIES ARCHIVE_OUTPUT_NAME geohex_shared)
endif()

target_include_directories(geohex_shared PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_link_libraries(geohex_shared PUBLIC m)
target_compile_definitions(geohex_shared PRIVATE GEOHEX_BUILDING_LIBRARY)
if(GEOHEX_MATH_LIBRARIES)
target_link_libraries(geohex_shared PUBLIC ${GEOHEX_MATH_LIBRARIES})
endif()

list(APPEND GEOHEX_TARGETS geohex_shared)
endif()
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG PLATFORM=${BUILDPLATFORM:-linux/amd64}

FROM --platform=${PLATFORM} debian:bookworm
FROM --platform=${PLATFORM} debian:trixie

ARG PLATFORM

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Go Kudo
Copyright (c) 2024-2026 Go Kudo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
20 changes: 18 additions & 2 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,31 @@ build_and_test() {
rm -rf "build"
}

should_run_sanitizers() {
if test "x${RUN_SANITIZERS}" = "xtrue"; then
return 0
fi

if test "x${RUN_SANITIZERS}" = "xfalse"; then
return 1
fi

if test "x${NATIVE_PLATFORM}" = "x"; then
return 0
fi

test "x${PLATFORM}" != "xlinux/s390x" && test "x${PLATFORM}" = "x${NATIVE_PLATFORM}"
}

build_and_test "clang" false false false
if test "x${NATIVE_PLATFORM}" = "x" || (test "x${PLATFORM}" != "xlinux/s390x" && test "x${PLATFORM}" = "x${NATIVE_PLATFORM}"); then
if should_run_sanitizers; then
build_and_test "clang" true false false
build_and_test "clang" false true false
build_and_test "clang" false false true
fi

build_and_test "gcc" false false false
if test "x${NATIVE_PLATFORM}" = "x" || (test "x${PLATFORM}" != "xlinux/s390x" && test "x${PLATFORM}" = "x${NATIVE_PLATFORM}"); then
if should_run_sanitizers; then
build_and_test "gcc" true false false
build_and_test "gcc" false true false
fi
Expand Down
32 changes: 32 additions & 0 deletions include/geohex/compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* SPDX-License-Identifier: MIT */
/*
* libgeohex
*
* Copyright (c) 2024-2026 Go Kudo Kudo (https://github.com/zeriyoshi)
*
* GeoHex original implementation by @sa2da (http://twitter.com/sa2da)
* https://www.geohex.org/
*
* Released under the MIT license.
* see https://opensource.org/licenses/MIT
*/
#ifndef GEOHEX_COMPAT_H
#define GEOHEX_COMPAT_H

#if defined(_WIN32) || defined(__CYGWIN__)
# if defined(GEOHEX_STATIC_DEFINE)
# define GEOHEX_API
# elif defined(GEOHEX_BUILDING_LIBRARY)
# define GEOHEX_API __declspec(dllexport)
# else
# define GEOHEX_API __declspec(dllimport)
# endif
#elif defined(__GNUC__) && __GNUC__ >= 4
# define GEOHEX_API __attribute__((visibility("default")))
#else
# define GEOHEX_API
#endif

#define GEOHEX_PI 3.14159265358979323846

#endif /* GEOHEX_COMPAT_H */
18 changes: 10 additions & 8 deletions include/geohex/geohex.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* libgeohex
*
* Copyright (c) 2024 Go Kudo (https://github.com/zeriyoshi)
* Copyright (c) 2024-2026 Go Kudo Kudo (https://github.com/zeriyoshi)
*
* GeoHex original implementation by @sa2da (http://twitter.com/sa2da)
* https://www.geohex.org/
Expand All @@ -16,11 +16,13 @@
#include <stdint.h>
#include <stdbool.h>

#include "geohex/compat.h"

#ifdef __cplusplus
extern "C" {
#endif

#define LIBGEOHEX_VERSION "1.1.1"
#define LIBGEOHEX_VERSION "2.0.0"
#define GEOHEX_COMPLIANT_VERSION "3.2"

#define MAX_LEVEL 15
Expand All @@ -47,12 +49,12 @@ typedef struct {
geohex_code_t code;
} zone_t;

bool adjust_xy(int32_t x, int32_t y, uint32_t level, xy_t *out);
bool get_xy_by_location(const loc_t *location, uint32_t level, xy_t *out);
bool get_xy_by_code(const geohex_code_t code, xy_t *out);
bool get_zone_by_location(const loc_t *location, uint32_t level, zone_t *out);
bool get_zone_by_code(const geohex_code_t code, zone_t *out);
bool get_zone_by_xy(const xy_t *xy, uint32_t level, zone_t *out);
GEOHEX_API bool adjust_xy(int32_t x, int32_t y, uint32_t level, xy_t *out);
GEOHEX_API bool get_xy_by_location(const loc_t *location, uint32_t level, xy_t *out);
GEOHEX_API bool get_xy_by_code(const geohex_code_t code, xy_t *out);
GEOHEX_API bool get_zone_by_location(const loc_t *location, uint32_t level, zone_t *out);
GEOHEX_API bool get_zone_by_code(const geohex_code_t code, zone_t *out);
GEOHEX_API bool get_zone_by_xy(const xy_t *xy, uint32_t level, zone_t *out);

#ifdef __cplusplus
}
Expand Down
Loading
Loading