TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: TG – Fast geometry library for C

201 点作者 tidwall超过 1 年前

11 条评论

s2mcallis超过 1 年前
Howdy, I work on S2 [1] so I have questions! How do you deal with polygons that cross the antimeridian?<p>The indexing structure you&#x27;ve come up with seems very interesting. In spherical coordinates line sweep algorithms like that are a little less intuitive because there&#x27;s not really a min and max y value to work with. Does your index support multiple polygons indexed together?<p>The lack of exact predicates worries me a little bit. It&#x27;s tricky because it will work right until it doesn&#x27;t for mysterious reasons, and it&#x27;s very hard to test for if you haven&#x27;t built it on a foundation of exact predicates. You&#x27;ll periodically fall into the fractal foam around edges when testing if you cross them or not ([2] has some good pictures). We do this in S2 by relying on a set of predicates [3] that fall all the way back to symbolic perturbation if they have to. We simply don&#x27;t have to think about colinear points in S2 for that reason.<p>[1] <a href="https:&#x2F;&#x2F;s2geometry.io&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;s2geometry.io&#x2F;</a> [2] <a href="https:&#x2F;&#x2F;github.com&#x2F;mourner&#x2F;robust-predicates">https:&#x2F;&#x2F;github.com&#x2F;mourner&#x2F;robust-predicates</a> [3] <a href="https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;s2geometry&#x2F;blob&#x2F;master&#x2F;src&#x2F;s2&#x2F;s2predicates.h">https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;s2geometry&#x2F;blob&#x2F;master&#x2F;src&#x2F;s2&#x2F;s2pr...</a>
评论 #37626046 未加载
hgs3超过 1 年前
Nice library. +1 for the excellent visualizations [1]. Will you keep it focused on intersections or might you dabble with triangulation?<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;tidwall&#x2F;tg&#x2F;blob&#x2F;main&#x2F;docs&#x2F;POLYGON_INDEXING.md">https:&#x2F;&#x2F;github.com&#x2F;tidwall&#x2F;tg&#x2F;blob&#x2F;main&#x2F;docs&#x2F;POLYGON_INDEXIN...</a>
ginko超过 1 年前
Rather than creating new geometric primitives on the heap, wouldn&#x27;t it be more flexible if the caller can provide the memory to initialize the structure in?<p>Then instead of<p><pre><code> struct tg_geom *geom = tg_geom_new_point(-112, 33); if (!geom) { &#x2F;&#x2F; System is out of memory. } </code></pre> you could do<p><pre><code> struct tg_geom geom; tg_geom_init_point(&amp;geom, -112, 33); </code></pre> without need for error checking or cleanup. You can still allocate on the heap if you want but you wouldn&#x27;t have to.
评论 #37622187 未加载
评论 #37622114 未加载
pasabagi超过 1 年前
Hey, this looks really great, but I couldn&#x27;t really see anything in the docs about robustness (how you handle floating point inaccuracy, etc) - what approach did you use?
评论 #37622546 未加载
simonw超过 1 年前
This is a really great README - clearly explained the benefits of the library and anticipated all of my questions about it.
simonw超过 1 年前
This looks really interesting. It implements pretty much the exact subset of geospatial stuff that I care about, in a single C file (an amalgamation that includes its dependencies).<p>This could make for a really neat SQLite extension, as a much lighter alternative to SpatiaLite.
评论 #37625077 未加载
unnah超过 1 年前
It looks like the coordinates are 64-bit doubles. How accurate and repeatable are the implementations of geometry operations here?
MoSarwatSpatial超过 1 年前
This is awesome! I wonder how feasible is it to include TG in Apache Sedona (<a href="https:&#x2F;&#x2F;github.com&#x2F;apache&#x2F;sedona">https:&#x2F;&#x2F;github.com&#x2F;apache&#x2F;sedona</a>)<p>Although Sedona runs as a distributed system, but TG may speed local in-memory geometrical computation for each worker node. Let me know your thoughts!
Waterluvian超过 1 年前
Very nice! I wonder if I can compile this to wasm. I’ve been badly needing spatial predicates in a web environment that are faster and less clunky than JSTS.<p>Does it assume a flat Cartesian world or does it handle ellipsoids or even map projections? (Or does it avoid the complexity altogether by not doing any work that cares about distances?)
评论 #37621213 未加载
评论 #37621987 未加载
评论 #37620599 未加载
评论 #37620574 未加载
评论 #37620530 未加载
aquarin超过 1 年前
I am curious, what exactly &quot;feq&quot; is calculating?<p>&gt; return !((x &lt; y) | (x &gt; y));<p>Is it supposed to avoid x == y. If yes, why?
评论 #37621082 未加载
评论 #37621106 未加载
评论 #37626073 未加载
sylware超过 1 年前
The author should consider some assembly versions of parts of it (ofc, without abusing the assembler pre-processor).