Repository navigation
Releases
v0.2.2-spatial
Experimental. Spatial may change or be removed. The other four libraries are the same code as v0.2.0.
New
- Travel fields over the tree. A large part's field keeps one distance for each open cube and brick, under 1 MB for a 450 × 49 × 450 m area, where a field per cell would take about 160 MB. A follower asks for the next point to fly to, and a body that reads several fields finds its places once.
- Cost tables. A table of 256 entries says what each cost byte costs one kind of agent, so several kinds read one layer differently. In the Unity package,
CostTablemakes one from a danger weight and a fog weight. Costs work over counts and over the tree. - A faster search over the tree. Bricks are searched a ring of cells at a time, and the tree's default leeway is 1. With costs, the slowest route on a 300 m piece of the area went from 134 ms to 28 ms.
- How it works. A new page explains each idea in plain words: wall distance, the tree, regions, routes, travel fields, cost tables and heightfields.
Fixed
- The route search's heap could take a place out too early when its rank rose.
- Sampling a field over counts had become slower since fields over the tree; it is back to the plain sample.
Changed
- Over a tree a field has no per-cell
Distance; checkKeepsCells, and askTryTravelandTryNext. - A field keeps the costs it was built with. Rebuild it when costs change; routes read the current costs.
Full Changelog: v0.2.1-spatial...v0.2.2-spatial
v0.2.1-spatial
Experimental. Spatial may change or be removed. The other four libraries are the same code as v0.2.0.
New
- Terrain as heightfields. Ground is stored as heights, kept within 0.25 m above the real surface. The collector can take only the colliders inside a part's box, so far scenery stays out.
- Wall distance as a tree. A large, mostly open grid keeps its wall distance in a 64-way tree of 4×4×4 bricks, at four bits a cell. A 450 × 49 × 450 m area fits in about 4 MB, where a count a cell takes 79 MB. A stored tree is checked against the shapes it was built from.
- Regions and routes over the tree. Size classes, regions and routes work on a grid that keeps a tree, with a route search of fixed size.
- Visualizer. The Spatial grid tab is simpler: four modes, a few actions, tables of values. A "Keep as a tree" switch and an Outdoors scene show the tree beside the dense grid. Spatial tabs are tinted.
- Docs. Shorter READMEs with pictures; the rules moved to reference pages. Every public member of Spatial is documented.
Changed
Shapes.Versionchanged: stored shape blocks must be baked again.- The Unity package needs the Terrain and Terrain Physics modules.
Full Changelog: v0.2.0-spatial...v0.2.1-spatial
v0.2.0
New
- An edit budget for the diffs. New overloads of
MyersDiff,HeckelDiffandGroupedDiff.Refinetake a limit on how many edits one search looks for. Past it the search splits where it got furthest: the script stays valid but may be longer, andcutShortsays so.HistogramDiffhas none, since its cost is in finding anchors. The Visualizer's Diffing tab has a Budget box. - XML documentation in the packages. Every public member of Algorithms, Collections, Packables and Packables.Newtonsoft is documented, including the rules callers depend on: Tarjan's search order (the contract of
ContractVersion1), how therefoverloads treat the arrays they are given, and what each Packables refusal means. Editors show it as IntelliSense. - The Visualizer for Linux, as a self-contained linux-x64 tarball beside the Windows build.
Changed
Graph.AddEdgeandAddEdgesthrowArgumentOutOfRangeExceptionfor a negative vertex.AddEdgesthen adds none of its edges.TwoWayDictionary.GetEnumeratorreturns the dictionary's own struct enumerator, so aforeachdoesn't allocate. The interface versions are explicit.- The
TwoWayDictionaryconstructor throwsArgumentExceptionfor a key or a value that comes twice. It did before; it is now documented and tested.
Downloads
AlgorithmsVisualizer-v0.2.0-win-x64.zip,AlgorithmsVisualizer-v0.2.0-linux-x64.tar.gz: the desktop Visualizer, self-contained, withBUILD.txtnaming the commit and SDK.Yewnyx.Algorithms,Yewnyx.Collections,Yewnyx.Packables,Yewnyx.Packables.Newtonsoft0.2.0: NuGet packages for netstandard2.1 and net8.0, with symbol packages.
The browser Visualizer at https://yewnyx.github.io/Algorithms/ is now built from the spatial branch, and so also has the Spatial tabs. See v0.2.0-spatial.
Full Changelog: v0.1.1...v0.2.0
v0.2.0-spatial
Experimental. Spatial is a work in progress: its API and its baked format may change, or it may be removed if it doesn't work out. Everything else here is the same code as v0.2.0, versioned 0.2.0-spatial.
Spatial answers questions about space from Unity jobs or plain .NET, without allocating: which of many boxes are near a point, and, for geometry that doesn't move, how much room there is and how a body gets from here to there. The same source builds as a .NET library and inside a Unity package, and gives the same bytes on .NET 8, Unity's Mono, Burst and IL2CPP.
Boxes
- A scan and a box tree find the boxes within a radius of a point and the nearest ones. The tree sorts boxes along a Hilbert curve, so each node is one compact lump of space: against a Morton order, a third fewer nodes visited per query on boxes spread through a volume.
- BoxSet (Unity) holds items by your id in native arrays. Add, Remove and Move only note a change;
Scheduleapplies them in one Burst job and rebuilds the tree, and queries run as jobs after it.
A grid of fixed geometry
Four layers, each built on the one before:
| Layer | Answers |
|---|---|
| Wall distance | How much room at this point? RoomAt reads eight cells and gives a distance the nearest shape is proven to be at least. Shapes (boxes, spheres, capsules, triangles) are baked once into a block of bytes. |
| Regions | Where can a body of this radius be, and which of those places join? Doors narrower than the body cut rooms off. |
| Travel fields | Which way to a goal, for many bodies at once? Fast marching gives a distance near the straight line; per-cell costs bend it. |
| Routes | The way for one body, as a few straight legs, each proven clear for the body's full radius. A leeway (a tenth by default) trades a little length for far less searching. |
In Unity, WallGrid owns the grid in native arrays and fills it in Burst jobs; ColliderShapes turns colliders into shapes; WallGridField and WallGridRoute serve fields and routes from jobs.
Downloads
xyz.yewnyx.spatial-0.2.0-spatial.tgz: the Unity package (Unity 6000.3, Burst, Collections, Mathematics). In the Package Manager: + → Add package from tarball…. It includes a sample with moving boxes.Yewnyx.Spatial0.2.0-spatial: the NuGet package for netstandard2.1 and net8.0, with a symbol package. The other four libraries are here at 0.2.0-spatial too, the same code as 0.2.0.AlgorithmsVisualizer-v0.2.0-spatial-win-x64.zip,…-linux-x64.tar.gz: the desktop Visualizer with the Spatial and Spatial grid tabs. The same build runs in the browser at https://yewnyx.github.io/Algorithms/.
Not every public member of Spatial has XML documentation yet.
Full Changelog: v0.2.0...v0.2.0-spatial
v0.1.1
The libraries are now available as NuGet packages, attached to this release. There are no code changes since 0.1.0.
Packages
| Package | What it is |
|---|---|
Yewnyx.Algorithms |
graphs and diffing |
Yewnyx.Collections |
TwoWayDictionary |
Yewnyx.Packables |
versioned saving and loading of object graphs |
Yewnyx.Packables.Newtonsoft |
JSON text for Packables, which depends on Yewnyx.Packables and Newtonsoft.Json |
Each package targets net8.0 and netstandard2.1, and has Source Link to this commit. The .snupkg files hold the debug symbols.
The packages aren't on nuget.org. To use one, put the .nupkg files in a folder and add it as a package source:
dotnet nuget add source <folder> --name yewnyx-local
dotnet add package Yewnyx.Algorithms --version 0.1.1
Visualizer
AlgorithmsVisualizer-v0.1.1-win-x64.zip is the same self-contained Windows build as 0.1.0, rebuilt at this tag. It holds the PDBs and BUILD.txt. The exe isn't code-signed, so Windows SmartScreen may warn on first run: choose "More info", then "Run anyway".
Full Changelog: v0.1.0...v0.1.1
v0.1.0
Visualizer app to demo/test the graph, diffing, and packable libraries (haven't gotten around to packaging those for nuget). Windows, not signed - just good enough to run and you can check it out on the GitHub Pages site anyway at https://yewnyx.github.io/Algorithms/.
This release doubles as an AI disclosure as well as a brief explanation of what the library contains. I'm not here to convince anyone that this is a good or a bad thing - it's useful to me alone, and I've put the time in to make sure of that, before and after AI.
The Graphs library's highlight is the Tarjan algorithm which I've used in the past to great effect in a game's logic system to linearize a graph of logic elements into a set of subgraphs that can be independently scheduled. This was handwritten, though as of recently the AI did some optimization and testing passes and bugfixes.
Graphs also includes a FloydWarshall shortest-paths algorithm that I threw in to poke at it and explore. This was done primarily by AI.
Diffing, particularly the Myers diff and patching abstraction, comes from some ancient code from 2015 or so that I wrote in a Starbucks over the course of a summer carried forward from Swift to C#, but originally inspired by a Java implementation and a couple of long-forgotten blog posts. The rest of it is stuff I never got around to trying, and was done by AI.
Packables, particularly v1, I designed by hand to serialize/deserialize object graphs, potentially with cycles, whose object lifecycles were not necessarily owned purely by C#, for example in the case of MonoBehaviours and ScriptableObjects, which are constructed by Unity in part in native code. The format is rather straightforward so I reimplemented it from scratch, also by hand. I used AI to build a newer version that shored up some of the deficiencies that I never got around to in the first or second versions I built, MIT licensed but lost to a private repository beyond my reach..
Collections contains TwoWayDictionary. It's kind of trash, but it did the job for something I needed. :)
Visualizer is pretty much vibe-coded as a whole. I'm not trying to make a visualizer app but it's a useful demo of the algorithms and that's as far as it's intended to go. By far the sloppiest thing in here. Sorry 🤷
Full Changelog: https://github.com/yewnyx/Algorithms/commits/v0.1.0