Skip to content

Instantly share code, notes, and snippets.

@all2one
all2one / bowyer_watson_dt.txt
Created July 13, 2017 02:42
Bowyer-Watson Delaunay triangulation
Create a super-triangle encompassing all points and add its three points to the point cloud
For each point (except the last three coming from the super-triangle), insert it to the mesh:
Find all the triangles that are no longer valid due to this insertion (a lot of point-in-circumcircle checks happen in this step)
Find one by searching from the end of the face list to take advantage of potential spatial locality (The benefit of Hilbert curve sort is reaped here.)
Extend the search from it using adjacency info to find all invalid ones
Find the boundary of a polygonal hole formed by the invalid triangles
Accumulate edges of each invalid triangles while filtering any internal edge by checking if it's shared by two triangles (i.e. checking if its opposing edge is being added, too)
Re-triangulate the hole to maintain the Delaunay property (create a triangular fan centered at the inserted point)
Remove every triangle that has a super-triangle point as one of its points and apply alpha-shape if you
@all2one
all2one / hilbert_curve_sort.txt
Last active July 13, 2017 02:37
Hilbert curve sort
If this leaf has a fewer points than a threshold or the recursion depth is big enough, exit (the base case of recursion)
Count-sort points in a given range by its distance on the Hilbert Curve
A detail level (iteration) of Hilbert Curve is determined by the current recursion depth.
You can use xy2d() function in https://en.wikipedia.org/wiki/Hilbert_curve to compute the distance.
Recurse into each subcell while passing through a new subrange of points that belong to it, a curve offset which indicates a curve section that needs to be further refined, and an incremented recursion depth

Keybase proof

I hereby claim:

  • I am all2one on github.
  • I am jj1 (https://keybase.io/jj1) on keybase.
  • I have a public key ASBx-D6bmKafbQPOB-CVMeA3uSVNw4hkNJegrIxF5RseGgo

To claim this, I am signing this object:

<a href="http://www.google.com/reader/link?url=http://gl3d.net[##_article_rep_link_##]&title=[##_article_rep_title_##]&srcURL=http://gl3d.net" target="_blank" rel="nofollow external"><img
src="http://img2.pict.com/15/da/3e/2809374/0/googlebuzz.png" width="50" height="58" alt="" /></a>
module Main where
import System.IO
import System.Environment (getArgs)
import System.FilePath.Windows (takeBaseName, replaceBaseName)
import Data.List (isInfixOf)
main = do
args <- getArgs
let fileName = args !! 0
class StorableShape : Shape {
private class MyDBObject : DBObject {
override void saveState() {
// access DBObject and StorableShape
. . .
}
}
private MyDBObject _store;
alias _store this;
this( ) {
class DBObject {
private:
. . . // state
public:
void saveState() { . .. }
void loadState() { . .. }
. . .
}
class StorableShape : Shape {
class Date {
private:
uint year, month, day;
invariant() {
assert(1 <= month && month <= 12);
switch (day) {
case 29:
assert(month ! = 2 | | leapYear(year) );
break;
case 30:
double sqrt( double x)
// Precondition
in {
assert( x >= 0);
}
// Postcondition
out(result) {
assert( result >= 0 && approxEqual(result * result, x) );
}
body {
int foo();
pure int bar();
int x;
immutable int y = 7;
pure int sum(int v, immutable(int)[] array)
{
int i = x; // error, cannot access mutable global state
int s = y; // ok, y is immutable
foo(); // error, foo() is impure