profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/zeeyang/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.
Zee Yang zeeyang Apple Cupertino, CA

zeeyang/share-kit 4

Swift client for ShareDB (SwiftNIO + Combine). Realtime data sync with Operational Transform (OT).

zeeyang/cheap-eval 1

Dependency free object evaluation engine for JavaScript. 5-30x faster than validate.js.

zeeyang/curv 0

a language for making art using mathematics

zeeyang/Euclid 0

A Swift library for creating and manipulating 3D geometry

zeeyang/minimum-awesome 0

A Vim setup that will get you into Vim and make it so that you don't want to pull your hair out.

zeeyang/Yc 0

C bindings for Yrs (https://github.com/yjs/yrs)

issue commentlibfive/libfive

Rust binding?

I think you could do something like your first implementation (Tree1), but without the phantom data marker and 'static lifetime: just hold a libfive_tree (which is an opaque pointer), and call libfive_tree_delete in the impl Drop.

Internally, the libfive_tree object is already a reference-counted DAG; it frees itself (and any children that become orphans) when the last copy is deleted with libfive_tree_delete. Since it's reference-counted inside the libfive API, you can't make it Copy, but it could be Clone by adding something like this to libfive.cpp:

void libfive_tree_clone(libfive_tree ptr)
{
    // Build a new tree (increasing the refcount), then release it (without
    // decrementing the refcount) to create a spare raw pointer.  This must
    // be deleted with `libfive_tree_delete` to avoid memory leaks.
    Tree(ptr).release()
}

I'd vote against re-implementing the DAG + stdlib in Rust: the DAG already exists behind the scenes, and the whole point of the C++ stdlib + C API is to avoid rewriting it in every language 😛 .

virtualritz

comment created time in an hour

issue commentlibfive/libfive

Rust binding?

So I now have two implementations for Tree in Rust.

Using references with (mandatory) lifetimes:

pub struct Tree1<'a> {
    tree: sys::libfive_tree,
    _marker: PhantomData<*mut &'a ()>,
}

impl Tree<'static> {
    pub fn x() -> Self {
        Self {
            tree: unsafe { sys::libfive_tree_x() },
            _marker: PhantomData,
        }
    }

    ...
}

impl<'a> Tree<'a> {
    pub fn union_self<'b>(&'b self, b: &'b Tree) -> Tree<'b> {
        Tree {
            tree: unsafe { sys::libfivestd_union(self.tree, b.tree) },
            _marker: PhantomData,
        }
    }
    
    ...
}

impl<'a> Drop for Tree1<'a> {
    fn drop(&mut self) {
        unsafe { sys::libfive_tree_delete(self.tree) };
    }
}

This variant is straightforward. Everything takes references; including any operators. This is reasonably easy to implement. Leaf nodes have 'static lifetimes. Everything else is tracked with individual lifetimes.

This all works. But everything being references, issues arise once you want to move Tree1s around because of Rust's move semantics. I.e. great for quick results and demo apps but probably not so much for a real CAD app.

The 2nd variant uses Rc and basically creates a copy of the tree to track ownership for getting deallocations right. Also this allows to easily keep copies of (sub)Tree2s and move them around in an app:

pub struct Tree2 {
    tree: Rc<sys::libfive_tree>,
    child_a: Option<Rc<Tree2>>,
    child_b: Option<Rc<Tree2>>,
}

impl Tree2 {
    pub fn x() -> Self {
        Self {
            tree: Rc::new(unsafe { sys::libfive_tree_x() }),
            child_a: None,
            child_b: None,
        }
    }
    
    pub fn union(self, b: Tree2) -> Self {
        Self {
            tree: Rc::new(unsafe { sys::libfivestd_union(*self.tree, *b.tree) }),
            child_a: Some(Rc::new(self)),
            child_b: Some(Rc::new(b)),
        }
    }
    
    ...
}

impl Clone for Tree2 {
    fn clone(&self) -> Self {
        Self {
            tree: Rc::new(*self.tree.as_ref()),
            child_a: self.child_a.as_ref().map(|t| t.clone()),
            child_b: self.child_b.as_ref().map(|t| t.clone()),
        }
    }
}

impl Drop for Tree2 {
    fn drop(&mut self) {
        if 1 == Rc::strong_count(&self.tree) {
            unsafe { sys::libfive_tree_delete(*self.tree) };
        }
    }
}

The second variant is modeled so that a tree has full ownership of all children. Subtrees can be cloned and deallocation happens as expected because of the use of Rc.

The issue here is the standard lib. Many operators take more than two operands. So if I want to wrap that I have two options:

  1. Swap out child_a & child_b for a children: Vec<Tree2> and use the stdlib.h header.
  2. Just RRIR, stdlib_impl.cpp that is.

I'm currently leaning towards 2. as that is probably also just 1h of search & replace, mostly.

Any thoughts/suggestions/ideas?

virtualritz

comment created time in 4 hours

push eventcurv3d/curv

Doug Moen

commit sha dacb5a5d609f9214703af6e2f0947d4cdf37c3db

ideas:language:next: user defined data types

view details

push time in a day

pull request commentcurv3d/curv

Add 2D polyline

Thank you!!! Will check

On Fri, May 7, 2021 at 9:18 AM Doug Moen ***@***.***> wrote:

Merged #127 https://github.com/curv3d/curv/pull/127 into master.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/curv3d/curv/pull/127#event-4701827191, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFMFLVVF6HHQB7WJS37S4WLTMPRY3ANCNFSM44IUFFEA .

zeeyang

comment created time in a day

push eventcurv3d/curv

Zee Yang

commit sha 885bf81fefa1934051f748b53995e55f57b0909c

Add 2D polyline

view details

Doug Moen

commit sha 7bcb1ae525759230f2e1a4ccab27bc6956a477ca

Merge pull request #127 from zeeyang/2d-polyline Add 2D polyline

view details

push time in a day

PR merged curv3d/curv

Add 2D polyline

Justification

I was trying to model a bridge truss and it was slow unioning a number of strokes. Polyline was derived from IQ's polygon function, sans the signed internal function and added stroke size (d).

How to test

polyline {d:0.1, v:[[0,0],[1,0],[1,1],[0,0]]}  // right triangle

Screen Shot 2021-05-06 at 8 23 21 PM

polyline {d:0.1, v:[[0,0],[1,0],[1,1],[0,0]]} >> extrude 0.2

Screen Shot 2021-05-06 at 8 23 47 PM

+31 -2

1 comment

3 changed files

zeeyang

pr closed time in a day

pull request commentcurv3d/curv

Add 2D polyline

Hey @Xiaoyuew check out this new shape primitive. It solves the performance problem of "large union", in the specific case of a set of stroke primitives.

zeeyang

comment created time in a day

push eventcurv3d/curv

Doug Moen

commit sha b2f417966c6b13b9c838c19d7864590b6929faeb

ideas:language:next: data abstraction

view details

push time in 2 days

push eventcurv3d/curv

Doug Moen

commit sha de2c3c53e0316d8b9a1895111fea02cf82a3c1d4

ideas: next gen language

view details

push time in 2 days

push eventlibfive/libfive

Matt Keeter

commit sha 9aa20520497636659b8d5bda25057631837e998a

Switch to C99-compatible syntax for deprecation (fixes #430)

view details

push time in 3 days

issue closedlibfive/libfive

Deprecation block makes C compiler fall over

This is from line 236 in libfive.h:

[[deprecated("use libfive_tree_nullary instead")]]
libfive_tree libfive_tree_nonary(int op);

Which makes clang fall over with:

  /Users/moritz/code/libfive/build/libfive/include/libfive.h:236:2: error: expected expression
  /Users/moritz/code/libfive/build/libfive/include/libfive.h:237:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
  /Users/moritz/code/libfive/build/libfive/include/libfive.h:237:1: error: redefinition of 'libfive_tree' as different kind of symbol
  /Users/moritz/code/libfive/build/libfive/include/libfive.h:188:31: note: previous definition is here
  /Users/moritz/code/libfive/build/libfive/include/libfive.h:237:13: error: expected ';' after top level declarator
  /Users/moritz/code/libfive/build/libfive/include/libfive.h:236:2: error: expected expression, err: true
  /Users/moritz/code/libfive/build/libfive/include/libfive.h:237:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int], err: false
  /Users/moritz/code/libfive/build/libfive/include/libfive.h:237:1: error: redefinition of 'libfive_tree' as different kind of symbol, err: true
  /Users/moritz/code/libfive/build/libfive/include/libfive.h:237:13: error: expected ';' after top level declarator, err: true

I think this [[...]] stuff is C++14 and later but a C compiler can't understand it?

closed time in 3 days

virtualritz

issue commentlibfive/libfive

Prefix stdlib.h functions?

What I have done in my fork is to prefix every function in stdlib.h with libfivestd_. I also changed the gen_c.py to do the right thing already. I.e. generated files hav no diff with previous ones except signatures in C API.

Would you accept a PR for this if I changed the the other binding generator scripts accordingly and everything builds/runs/tests fine?

virtualritz

comment created time in 3 days

issue commentlibfive/libfive

Why does _union() start with an underscore in stdlib.h?

Yeah, I get it. I wrote a gen_rust.py and there I have the issue with move (Rust keyword). I swap that out for moveit.

virtualritz

comment created time in 3 days

push eventcurv3d/curv

Zee Yang

commit sha 3ac261e2e8fd7c4c38f56dfba5bb835f1b092f4e

Add github action for macos build

view details

Doug Moen

commit sha ac861e67b0032392cfc542a53cc4bf5ea07ad806

Merge pull request #126 from zeeyang/macos-build Add github action for macos build

view details

push time in 3 days

PR merged curv3d/curv

Add github action for macos build

Justification

Run make test and make release build in macos environment for PR and master builds. See https://github.com/curv3d/curv/pull/125#issuecomment-832831058

How to test

  • go to github Actions tab
  • verify workflow logs
+26 -6

0 comment

1 changed file

zeeyang

pr closed time in 3 days

issue commentlibfive/libfive

Why does _union() start with an underscore in stdlib.h?

Not quite – this is because the C and C++ union need to be distinguished by the bindings generator, and functions which take zero arguments but return different types aren't allowed.

virtualritz

comment created time in 3 days

issue commentlibfive/libfive

Why does _union() start with an underscore in stdlib.h?

union is a keyword in C/C++, so the name union() would not work.

virtualritz

comment created time in 3 days

pull request commentcurv3d/curv

Continue march backward when inside shape

Thanks for isolating this 1 line change in a separate pull request. Processing this change was a big deal for me.

zeeyang

comment created time in 3 days

issue openedlibfive/libfive

Why does _union() start with an underscore in stdlib.h?

See subject.

created time in 3 days

pull request commentcurv3d/curv

Continue march backward when inside shape

make test contains unit tests that ensure that the *.gpu files generated by the examples do not change. Because I don't want to break the GPU code generator by accident when I am refactoring code. But when there is a deliberate change (as in this pull request) then I need to regenerate all of the files in tests/gpu/*.gpu.

Ideally, I would create a github action to run 'make test' after every change to libcurv/* or curv/*. Then we would have received automatic notification of the test faiure after you created the pull request. But I haven't got around to learning how github actions work. There is a github action for rebuilding Curv on windows, but it wasn't my contribution.

zeeyang

comment created time in 3 days

issue commentlibfive/libfive

Rust binding?

So I abandoned my tries to get the C++ header through bindgen for the time being.

I have a rough version of the Rust API in place – https://github.com/virtualritz/libfive-rs.

This contains libfive itself as a subrepo under libfive-sys. This is built from source. Currently this tracks my fork as I have added a libfivestd_ prefix to the stdlib.h functions (see #432).

Feedback welcome. Probably best to build the docs to get an idea.

cargo doc -p libfive --no-deps --open

Not sure how to ever get this published on docs.rs since that is sandboxed so all dependencies must be part of the package.

With boost being one that is pretty much impossible due to crates.io size constraints, I guess.

virtualritz

comment created time in 3 days

issue commentlibfive/libfive

Deprecation block makes C compiler fall over

Yes, that fixes it for me.

virtualritz

comment created time in 3 days

issue commentlibfive/libfive

[stdlib.h] Missing typedef makes C compiler fall over

Thanks, fixed!

virtualritz

comment created time in 4 days

push eventlibfive/libfive

Matt Keeter

commit sha 26e0d0abf8dac30fb2be7ab006be13886f58fcdd

Add typedefs (fixes #431)

view details

push time in 4 days

issue closedlibfive/libfive

[stdlib.h] Missing typedef makes C compiler fall over

I get several dozens of those:

libfive/libfive-sys/libfive/libfive/stdlib/stdlib.h:80:37: error: must use 'struct' tag to refer to type 'tvec3'

Adding two typedefs to stdlib.h fixes this:

typedef struct tvec2 tvec2;
struct tvec2 {
    libfive_tree x, y;
};
typedef struct tvec3 tvec3;
struct tvec3 {
    libfive_tree x, y, z;
};

closed time in 4 days

virtualritz

issue commentlibfive/libfive

Deprecation block makes C compiler fall over

Does this work with

__attribute__((deprecated("deprecated", "libfive_tree_nullary")))
libfive_tree libfive_tree_nonary(int op);

?

virtualritz

comment created time in 4 days

issue openedlibfive/libfive

Prefix stdlib.h functions?

When using something like bindgen it is preferable to use whitelisting (allowlisting).

Unfortunately the stdlib functions do not have a prefix so if one wants to generate bindings for those, only blacklisting (blocklisting) is possible which is tedious and never really prevents everything unrelated to be filtered out from the bindings, unless one starts blacklisting individual items.

Would is be possible to also prefix the stdlib.h functions with libfive_?

created time in 4 days

issue openedlibfive/libfive

[stdlib.h] Missing typedef makes C compiler fall over

I get several dozens of those:

libfive/libfive-sys/libfive/libfive/stdlib/stdlib.h:80:37: error: must use 'struct' tag to refer to type 'tvec3'

Adding two typedefs to stdlib.h fixes this:

typedef struct tvec2 tvec2;
struct tvec2 {
    libfive_tree x, y;
};
typedef struct tvec3 tvec3;
struct tvec3 {
    libfive_tree x, y, z;
};

created time in 4 days

push eventcurv3d/curv

Doug Moen

commit sha 8fc802195bcf6fd52e4f8fadfb543d167615ea0e

ideas:language: metaprogramming

view details

push time in 4 days

pull request commentcurv3d/curv

Continue march backward when inside shape

'make test' now passes all tests again. I think we are done.

zeeyang

comment created time in 4 days