Thread overview
S2Geometry Library Release v0.2
May 25
Greetings everyone.

I wanted to announce here the v0.2 release of the S2 Geometry Library in the D language. The DUB page should be updated to show v0.2 shortly.

https://code.dlang.org/packages/s2geometry-d

What is it?
=============
The S2 Geometry library is an extremely high precision and performant library for geometry on the surface of the Earth. It is useful for dealing with areas, boundaries, lines, polygons, etc. As a practical example, it can answer very quickly if thousands of driving paths would pass through the arbitrary boundaries of an airport and thus need to pay a toll.

It was originally created by Eric Veach and the library is used in Google. I have converted this library in the D programming language.

What's New?
=============
This release is now nearly feature complete with the C++ library. Only encoding/decoding of geometric objects is missing.

What's in Store Next?
================
* More work is needed to improve performance further. The full D test suite runs in 139 seconds while the C++ full test suite only needs 112 seconds.
* Encoding/Decoding support for transmitting geometric objects in binary form.
* Work on this library will slow down, as I plan to start using it instead of writing it.

Why does this matter?
====================
Currently only C++ and D have this level of feature support, which cannot be found in Java, Python, Go, Rust, or any other languages today.

Part of the reason for this is that it's a very very very large and complex project that makes use of a large set of C++ features.

---------------------------------------------------------------
Language           files        blank      comment         code
---------------------------------------------------------------
C++                  177         6082        12820        37378
C/C++ Header         164         6385        18691        21935
Python                 1           35           24          188
CMake                  1            0            0           16
---------------------------------------------------------------
SUM:                 343        12502        31535        59517
---------------------------------------------------------------

D's philosophy of having a large tool-box makes this work doable by a single person while other languages have spent many years with many contributors.
May 25
On Saturday, 25 May 2019 at 11:48:12 UTC, Vijay Nayar wrote:
> I wanted to announce here the v0.2 release of the S2 Geometry Library in the D language. The DUB page should be updated to show v0.2 shortly.
>
> https://code.dlang.org/packages/s2geometry-d

Today I learned that released versions must be 3 digits in order to be picked up by DUB. The release is now v0.2.0.
May 25
On Saturday, 25 May 2019 at 18:55:04 UTC, Vijay Nayar wrote:
> Today I learned that released versions must be 3 digits in order to be picked up by DUB. The release is now v0.2.0.

Yes, DUB uses semver (https://semver.org) for versions.
May 25
On Saturday, 25 May 2019 at 11:48:12 UTC, Vijay Nayar wrote:
> D's philosophy of having a large tool-box makes this work doable by a single person while other languages have spent many years with many contributors.

Great work! Can you tell something about how you converted the code and how you plan to stay up-to-date?


May 25
On Saturday, 25 May 2019 at 19:34:50 UTC, Sebastiaan Koppe wrote:
> On Saturday, 25 May 2019 at 11:48:12 UTC, Vijay Nayar wrote:
>> D's philosophy of having a large tool-box makes this work doable by a single person while other languages have spent many years with many contributors.
>
> Great work! Can you tell something about how you converted the code and how you plan to stay up-to-date?

I would say that this library is a bit of a special case in most regards. The code base is quite complicated not only in subject matter and mathematics, but also in the actual dependencies between modules as well. The code itself has numerous circular dependencies, but when you factor in the unit-tests as well, the case becomes much more severe. The original code also passes around references to stack objects frequently, and manual changes had to be made to replace that logic. This will give C++ a slight edge in performance, but I think the gain in safety is worth it.

The actual conversion was entirely by hand, making appropriate replacements for many parts of the algorithms. Where the original logic became nearly impossibly complex to understand, debugging was mostly done by following this procedure:

1. Find a failing test.
2. Instrument the D code with print statements leading up to the failing logic.
3. Instrument the C++ code with the equivalent print statements.
4. Run both tests and compare the output.
5. Add more print statements if there are no differences or if the code is not yet identified.
6. Cleanup.

If that approach sounds kinda silly, it's because it is. However, what it means is that the library is actually capable of being converted into D without me having to get a PhD in mathematics first :P

On the question of keeping the library up to date, this is also a bit of a special case. Previously I've used the Java version of this library which is already 8 years old, and it is extremely useful even today. The actual library itself is fairly complete, and even if it were to never get another update, it would continue to be very useful for a long time.