S2Geometry Library Release v0.2
Vijay Nayar
madric at gmail.com
Sat May 25 20:50:34 UTC 2019
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.
More information about the Digitalmars-d-announce
mailing list