GithubHelp home page GithubHelp logo

thi-ng / c-thing Goto Github PK

View Code? Open in Web Editor NEW
108.0 15.0 5.0 6.17 MB

Geometry related data structures (C11)

License: Apache License 2.0

C 94.22% Shell 1.34% JavaScript 0.61% Clojure 2.00% HTML 0.24% Lua 1.09% C++ 0.52%

c-thing's Introduction

c.thi.ng

Contents

Overview

WIP

Data structures

Memory management

Math

Simulation

Geometry

TBD

Requirements

Dependencies

The library itself has no 3rd party dependencies. Some of the examples however use these additional libs:

Examples

Build all examples

git clone --recursive https://github.com/thi-ng/c-thing

premake5 gmake
make config=release_sse

1D/2D Cellular automata

Source (1D) | Source (2D)

./assets/ca1d.png

# build library & example app
make config=release_sse ex-ca1d

# 1D sample invocation w/ Wolfram Rule 105
# Result will be written to /assets/ca-105.svg
# args: rule states kernelwidth res
bin/release/ex-ca1d 105 2 1

# Output all 255 wolfram rules
for i in {1..255}; do bin/release/ex-ca1d $i 2 1 128; done

# Another example w/ bigger kernel size
bin/release/ex-ca1d 522530942 32 3 128

# build 2D example app
make config=release_sse ex-ca2d

# frames will be written to /assets
bin/release/ex-ca2d

Convex Hull

Source

./assets/chull.png

# build library & example app
make config=release_sse ex-chull && bin/release/ex-chull > assets/chull.svg

Diffusion-Limited Aggregation

Source

./assets/dla.png

./assets/dla-color.png

# build library & example app
make config=release_sse ex-dla && bin/release/ex-dla > assets/dla.svg

GLFW (desktop & emscripten)

Source | Online demo

./assets/glfw01.jpg

See dependencies for details…

# build library & example app
make config=release_sse ex-glfw01 && bin/release/ex-glfw01

Note: Desktop version currently only has build settings for OSX.

To compile with Emscripten & open in browser: http://localhost:8000/glfw.html

# build LLVM bitcode of library (./obj/libcthing.bc)
./compile-bc

# compile example for browser & link with lib
emcc -O2 -DCT_FEATURE_LOG -DCT_NO_EXPORT -DNDEBUG \
     -s 'USE_GLFW=3' \
     -s 'ELIMINATE_DUPLICATE_FUNCTIONS=1' \
     -s 'NO_EXIT_RUNTIME=1' \
     --llvm-lto 1 \
     --closure 1 \
     --preload-file assets/suzanne.stl \
     -Isrc -Iext \
     -o glfw.html \
     examples/glfw/*.c obj/libcthing.bc

# launch server
python -m SimpleHTTPServer

Poisson disc sampling image conversion

Source

./assets/iris-poisson.png

# build library & example app
make config=release_sse ex-poisson

# show usage
bin/release/ex-poisson
# Missing input file
# Usage:  ex-poisson [options] image [ > out.svg ]
#   -b HEX    bg color (default: ffffff)
#   -f HEX    fg color (default: 0000ff)
#   -g FLOAT  gamma (default: 3.00)
#   -i        invert (also swaps fg/bg) (default: no)
#   -m FLOAT  min distance (default: 2.00)
#   -x FLOAT  max distance (default: 10.00)
#   -r FLOAT  dot radius (default: 1.00)
#   -q INT    quality (default: 100)
#   -t        output points as text only (default: no)

# concrete example (for image size roughly 700x1000px)
bin/release/ex-poisson -g 1.25 -q 500 -m 1.5 -x 16 assets/iris.jpg > assets/iris.svg

Polygon clipping (Greiner-Hormann)

Source

./assets/polyclip.png

# build library & example app
make config=release_sse ex-polyclip && bin/release/ex-polyclip > polyclip.svg

Polygon offsetting

Source

./assets/polyoffset-all-small.png

# build library & example app
make config=release_sse ex-polyclip && bin/release/ex-polyoffset > polyoffset.svg

Verlet physics

Source | Video example 1 | Video example 2

./assets/verlet.png

# build library & example app
make config=release_sse ex-verlet && bin/release/ex-verlet

# ouputs are stored as SVG sequence in /assets
# use script below to convert to mp4 (requires rsvg & ffmpeg) -> out.mp4
./makevideo verlet

Voronoi

Source

./assets/poisson-voronoi.png

# build library & example app
make config=release_sse ex-voronoi && bin/release/ex-voronoi

Piping in points from external process

./assets/iris-voronoi.png

The image above was generated by first sampling a JPG with the poisson example tool (configured to output points as text) and then piping these points into the voronoi example.

bin/release/ex-poisson -b 00ffff -f 0000ff -q 500 -m 2 -x 16 -t assets/iris.jpg | \
bin/release/ex-voronoi -p -w 757 -h 450 > iris-voronoi.svg

Build & test

Get further help for autogenerated Makefile:

# checkout with submodules
git clone --recursive https://github.com/thi-ng/c-thing

# generate Makefiles
premake5 gmake

make help
# Usage: make [config=name] [target]
# CONFIGURATIONS:
#   debug_sse
#   debug_no_sse
#   release_sse
#   release_no_sse
# 
# TARGETS:
#    all (default)
#    clean
#    test
#    test_asan
#    lib
#    ex-ca1d
#    ex-ca2d
#    ex-chull
#    ex-dla
#    ex-poisson
#    ex-verlet
#    ex-verlet-pack
#    ex-polyclip
#    ex-polyoffset
#    ex-voronoi
#    ex-glfw01
# build & run tests manually
make config=debug_sse test && bin/debug/test
# or
make config=release_sse test && bin/release/test

# ...or use auto test w/ file watcher
# tests re-run automatically if files in /src or /test are changed
# if no args given, compiles w/ address sanitizer enabled
./autotest
# ...or provide build config (target config profile)
# (only test_msan requires linux & clang, other profiles also build w/ gcc etc.)
./autotest test_msan
./autotest test_asan debug
./autotest test release no_sse

Build static library

make config=debug_sse lib
# or
make config=release_sse lib

Build source x-ref

brew install cscope

./browse

Disassemble & list symbols

# display disassembly (OSX)
otool -jtV bin/release/libcthing.a | less

# display global symbols defined in lib
nm -g -j bin/release/libcthing.a | grep --color=never _ct_

Compile with emscripten

Build as library for emcc

Also see GLFW example for further details…

# build LLVM bitcode version for future linking with other sources
./compile-bc

Run test suite in browser

# help / usage
./compile -h
# Usage:
#   -a     : separate asm.js output
#   -c     : enable Closure compiler step
#   -d     : remove duplicate functions
#   -D SYM : add define
#   -h     : show this help
#   -k     : enable runtime checks
#   -m     : enable memory checks
#   -s     : enable SSE (SIMD.js)
#   -t     : include tests

# compile with tests, closure pass & remove duplicate fns
./compile -tdc

python3 -m http.server

# in browser dev console - http://localhost:8000/
cthing(); cthing._main()

Build customization

This project utilizes feature macros defined in the thi.ng/ct-head project. Please see documentation there for further reference to customize behavior.

Contributors

NameRoleWebsite
Karsten Schmidtinitiator & principal developerthi.ng

License

This project is open source and licensed under the Apache Software License 2.0.

c-thing's People

Contributors

postspectacular avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

c-thing's Issues

Unable to run build/run tests

On 64bit Linux - Ubuntu 16.04:

make config=debug_sse test && bin/debug/test fails with:

==== Building lib (release_sse) ====
Creating bin/release
Creating obj/sse/release/lib
adjacency.c
In file included from src/data/adjacency.c:6:0:
src/math/math.h: In function ‘ct_clz8’:
src/math/math.h:60:6: error: #elif with no expression
 #elif
      ^
lib.make:202: recipe for target 'obj/sse/release/lib/adjacency.o' failed
make[1]: *** [obj/sse/release/lib/adjacency.o] Error 1
Makefile:56: recipe for target 'lib' failed
make: *** [lib] Error 2

changing line 60 in math.h from #elif to #else clears the above issue.

After making this fix tests still won't build and following issue is reported:

==== Building test (debug_sse) ====
object.c
In file included from src/common/dbg.h:6:0,
                 from src/data/object.c:5:
src/data/object.c: In function ‘ct_object_tostring’:
src/config.h:27:21: error: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 6 has type ‘int’ [-Werror=format=]
 #define CT_ANSI_RED "\x1b[31;1m"
                     ^
src/common/dbg.h:26:11: note: in expansion of macro ‘CT_ANSI_RED’
           CT_ANSI_RED "[ERROR] (%s:%d, err: %s) " M CT_ANSI_RESET "\n", \
           ^~~~~~~~~~~
src/common/dbg.h:52:5: note: in expansion of macro ‘CT_ERROR’
     CT_ERROR(M, ##__VA_ARGS__); \
     ^~~~~~~~
src/data/object.c:86:3: note: in expansion of macro ‘CT_CHECK’
   CT_CHECK(__impls_itostring[o->tag.type].tostring != NULL,
   ^~~~~~~~
cc1: all warnings being treated as errors
test.make:237: recipe for target 'obj/sse/debug/test/object.o' failed
make[1]: *** [obj/sse/debug/test/object.o] Error 1
Makefile:50: recipe for target 'test' failed
make: *** [test] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.