{"id":28546552,"url":"https://github.com/benmakesgames/hexgrid","last_synced_at":"2025-07-07T06:31:16.271Z","repository":{"id":65593111,"uuid":"306074434","full_name":"BenMakesGames/HexGrid","owner":"BenMakesGames","description":"A .NET library that helps perform a variety of hex-grid functions, such as computing distance, getting directions, and drawing various shapes (rings, circles, lines, asterisks...)","archived":false,"fork":false,"pushed_at":"2023-04-16T18:35:39.000Z","size":36,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-09T22:40:34.228Z","etag":null,"topics":["hexagonal-grids","hexagonal-tiles","tile-based","tile-based-game"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BenMakesGames.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-21T15:50:12.000Z","updated_at":"2024-10-09T14:04:59.000Z","dependencies_parsed_at":"2023-01-30T23:40:11.347Z","dependency_job_id":null,"html_url":"https://github.com/BenMakesGames/HexGrid","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BenMakesGames/HexGrid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenMakesGames%2FHexGrid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenMakesGames%2FHexGrid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenMakesGames%2FHexGrid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenMakesGames%2FHexGrid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BenMakesGames","download_url":"https://codeload.github.com/BenMakesGames/HexGrid/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenMakesGames%2FHexGrid/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264027537,"owners_count":23546093,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hexagonal-grids","hexagonal-tiles","tile-based","tile-based-game"],"created_at":"2025-06-09T23:39:46.361Z","updated_at":"2025-07-07T06:31:16.266Z","avatar_url":"https://github.com/BenMakesGames.png","language":"C#","funding_links":["https://ko-fi.com/A0A12KQ16"],"categories":[],"sub_categories":[],"readme":"HexGrid is a library that helps perform a variety of hex-grid functions, such as computing distance, getting directions, and drawing various shapes: lines, asterisks, arcs, rings, circles, and rectangles.\n\nThis library assumes a hex grid of the following orientation:\n\n```\no o o o\n o o o o\no o o o\n o o o o\n```\n\n* (0, 0) is the top-left cell\n* (1, 0) is the second cell in the first row\n* (0, 1) is the first cell in the second row\n* etc.\n\nThe `Direction` enum contains the six directions of movement allowed in a grid of this orientation: `NorthWest`, `NorthEast`, `East`, `SouthEast`, `SouthWest`, and `West`.\n\nThis library does not make any assumptions or have any requirements about how you store your tiles, however the above orientation was chosen because it is easy to represent using a traditional 2D array. All the methods provided by this library use `(int x, int y)` tuples to represent coordinates, accepting and returning coordinates in that form.\n\n* nuget package: https://www.nuget.org/packages/BenMakesGames.HexGrid\n* GitHub repo: https://github.com/BenMakesGames/HexGrid\n\n[![Buy Me a Coffee at ko-fi.com](https://raw.githubusercontent.com/BenMakesGames/AssetsForNuGet/main/buymeacoffee.png)](https://ko-fi.com/A0A12KQ16)\n\n---\n\n## int HexGrid.Distance((int x, int y) p1, (int x, int y) p2)\n\nReturns the number of cells needed to travel between two points (**p1** and **p2**) on a hex grid.\n\nExample usage:\n\n```c#\nint distance = HexGrid.Distance((0, 0), (4, 7));\n```\n\n## (int x, int y) HexGrid.Move((int x, int y) origin, Direction d, int distance = 1)\n\nReturns the coordinates for a point **distance** tiles away from **origin**, in the given direction, **d**.\n\n* **origin**: The starting location.\n* **d**: The direction to move in, from the Direction enum.\n* **distance**: The number of tiles to move; optional, defaulting to 1.\n\nExample usage:\n\n```c#\n(int x, int y) currentLocation = (4, 4);\n\ncurrentLocation = HexGrid.Move(currentLocation, Direction.NorthEast);\n```\n\n## int HexGrid.ComputeLeftRightOrientation((int x, int y) origin, (int x, int y) target)\n\nReturns -1 if **target** is left of **origin**; 1 if **target** is right of **origin**; 0 if they are in the same visual column.\n\nRemember, with hex grids aligned in the following orientation, this is not a trivial problem:\n\n```\no o o o\n o o o o\no o o o\n o o o o\n```\n\n* **origin**: The tile to compute the direction FROM.\n* **target**: The tile to compute the direction TOWARDS.\n\nExample usage:\n\n```c#\n(int x, int y) origin = (1, 1);\n(int x, int y) target = (1, 2);\n\nint orientation = HexGrid.ComputeLeftRightOrientation(origin, target);\n\nif(orientation \u003c 1)\n    Console.WriteLine(\"Target is to the left of Origin.\");\nelse if(orientation \u003e 1)\n    Console.WriteLine(\"Target is to the right of Origin.\");\nelse\n    Console.WriteLine(\"Target and Origin are directly above/below one another.\");\n```\n\n## Direction? HexGrid.ComputeDirection((int x, int y) origin, (int x, int y) destination)\n\nReturns a the Direction you would need to travel, from **origin**, in a straight line, to reach **destination**. If it is not possible to go in a straight line, returns null, instead.\n\n* **origin**: The starting tile.\n* **destination**: The theoretical ending cell.\n\nExample usage:\n\n```c#\n(int x, int y) origin = (1, 1);\n(int x, int y) target = (1, 2);\n\nDirection d = HexGrid.ComputeDirection(origin, target);\n\nif(d == null)\n    Console.WriteLine(\"Origin and Target are not in a straight line.\");\nelse\n    Console.WriteLine(\"Origin can move \" + d.ToString() + \" in a straight line to reach Target.\")\n```\n\n## Direction HexGrid.Rotate(Direction direction, int turns)\n\nIn a hex grid, a straight line can be rotated 60 degrees left or right.\n\nThis method returns a new Direction which represents the given **direction** rotated 60 degrees clockwise **turns** times. (A negative value for **turns** represents counter-clockwise rotation.)\n\n```c#\nDirection newDirection = HexGrid.Rotate(Direction.NorthWest, 2);\n\nConsole.WriteLine(newDirection.ToString()); // outputs \"East\"\n```\n\n## List\u003c(int x, int y)\u003e HexGrid.ComputeLine((int x, int y) origin, Direction direction, int minDistance, int maxDistance)\n\nReturns a list of coordinates that represent a line, starting at the **origin** and extending **maxDistance** cells away in the given **direction**. If a **minDistance** is given, then that many cells from the start of the line are skipped.\n\nExample usage:\n\n```c#\nvar line = HexGrid.ComputeLine((0, 0), Direction.SouthEast, 0, 4);\n```\n\n## List\u003c(int x, int y)\u003e HexGrid.ComputeAsterisk((int x, int y) origin, int minDistance, int maxDistance)\n\nReturns a list of coordinates that represents an asterisk (6 straight lines) emanating from the **origin**. Each line will start **minDistance** cells away from the origin, and end **maxDistance** cells away from it. (A **minDistance** of 0 makes a complete asterisk.)\n\nExample usage:\n\n```c#\nvar asterisk = HexGrid.ComputeAsterisk((2, 2), 1, 2);\n```\n\nThe above code would return a list of coordinates representing the following asterisk (the upper-left tile is (0, 0)). Note that the center tile is skipped, because a **minDistance** of 1 was used:\n\n```\no X o X o\n o X X o o\nX X o X X\n o X X o o\no X o X o\n```\n\n## List\u003c(int x, int y)\u003e HexGrid.ComputeArc((int x, int y) origin, Direction direction, int sideLength)\n\nAn \"arc\" is formed by connecting two lines at the **origin**, such that the two lines form an arrowhead pointing in the given **direction**. The length of each side of the arrow head will be **sideLength**.\n\nExample usage:\n\n```\nvar arc = HexGrid.ComputeArc((4, 3), Direction.East, 3);\n```\n\nThe above code would return a list of coordinates representing the following arc (the upper-left tile is (0, 0)):\n\n```\no o o o o o\n o o o X o o\no o o o X o\n o o o o X o\no o o o X o\n o o o X o o\n```\n\n## List\u003c(int x, int y)\u003e HexGrid.ComputeRing((int x, int y) origin, int distance)\n\nReturns a list of coordinates that represent a ring (hexagon) centered on the **origin**, with a radius of **distance**.\n\n## List\u003c(int x, int y)\u003e HexGrid.ComputeRing((int x, int y) origin, int minDistance, int maxDistance)\n\nReturns a list of coordinates that represent a solid donut or circle (hexagon) centered on the **origin**, with an inner radius of **minDistance** and an outer radius of **maxDistance**. A **minDistance** of 0 results in a solid circle with no hole.\n\n## List\u003c(int x, int y)\u003e HexGrid.ComputeRectangle((int x, int y) origin, int w, int h)\n\nReturns a list of coordinates that represent a solid rectangle whose upper-left coordinate is **origin**, having width **w** and height **h**.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenmakesgames%2Fhexgrid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenmakesgames%2Fhexgrid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenmakesgames%2Fhexgrid/lists"}