-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API preferences? #5
Comments
@chrispahm Thanks for response and creating this issue!
Yes, sure.
That is really nice idea!
I am not sure whether JavaScript supports something like C++ namespace, but if it's possible in either of definition or import timing, Related with high-level API, I personally prefer class Geometry {
ptr: null,
buffer: function(radius, options),
:
free: function()
} Some other GEOS wrapper libraries seem to have such strategy, but in my understanding, JavaScript has no destructor nor reference counter, so explicit free call will be necessary at somewhere (in above Geometry class or something pointer manager class)...
|
I see the benefits of having a very similar API to shapely, but unfortunately this would still mean that we'd need to write a lot of glue code since it's also an abstraction of the original GEOS API. What I was thinking about is that if this library would export the barebones GEOS C API through e.g. Anyways, if you'd implement a import geos from "geos-wasm/lib/core"
const registry = new FinalizationRegistry((heldValue) => {
geos.free(heldValue);
});
class Geometry {
constructor() {
this.ptr = null,
registry.register(this, this.ptr, this);
}
// define Geometry methods
buffer () {} //...
destroy() { // manual destructor for backup, you don't have to call this
registry.unregister(this);
geos.free(this.ptr);
}
} This way users wouldn't have to deal with it, which makes the code feel more JavaScripty for sure. But as I said in the Background section of the readme, that would be way to much work for me to pull off 😅 |
Okay, sure! 😄
Thanks for the information about JavaScript FinalizationRegistry method. (I didn't know it. 😅) By the way, I missed to read In my understanding, GeoJSON (default) and turf assume that the projection (unit) is longitude/latitude (decimal degree) ( ex. EPSG:4326), but GEOS accepts any projections/units and assumes radius, distance and area .etc as same projection unit. |
@chrispahm After thinking about high-level API more, I remembered that GEOS has and I felt that its interface matches to solve above pointer management and battle-test issues. I will try it on my fork repository's |
@chrispahm Thanks for comments!
Maybe possible, but So, high-level API will be basically same as current
How do you think about the above I/O interface ?
I first heard about it. Thanks for the information! |
More and more agreeing with you that the high-level API should rather resemble Shapely than turf and the like! I guess other solutions are somewhere in between, so I guess Shapely is familiar to many, but also highly flexible! What do you think about these potential next steps:
|
Thanks for confirmation! About the next steps, I feel that it's too early to make decision on above No.1 and No.2. I think that following steps will be possible, but how do you think about these steps ?
|
Well, I set my PR #3 to draft mode and appends some commits, but I noticed that
I felt that high-level About merging steps, rebasing, squashing and separating each parts are okay for me, so if you feel it's too big, let me know about that. |
@chrispahm Thanks for merging WKB PR #6 ! Now I understand that WKB is a lot better than GEOS GeoJSON Reader/Writer.
Anyway, I will do the following No2, except last "Add
|
Closing this since #9 is merged |
@sanak mentions the following in #4 (comment),
I think there are many good arguments for exposing a low-level API of all functions exported by GEOS! These would create little overhead, and should be simple(r) to maintain in the long run. However, at least for a few functions, I'd like to implement a high-level API that brings the convenience of not having to worry about pointers/memory management etc.
API proposal
The package could provide the low-level API (essentially everything wrapped in
allCFunctions
) using a sub-module (not sure if that's the correct term) e.g. geos-wasm/lib/core , as well as a high-level API (everything inallJSFunctions
) for all function where someone contributes an implementation → imported through geos-wasmExample
What do you think about this proposal? Also, are there any preferences towards the naming of functions? Right now, we're just using the function names that we get from Emscripten, but the repeated use of "GEOS" in the function names seems unnecessarily verbose.
The text was updated successfully, but these errors were encountered: