Skip to content

Instantly share code, notes, and snippets.

View haxiomic's full-sized avatar

George Corney haxiomic

View GitHub Profile
@haxiomic
haxiomic / EvalConstExpr.hx
Last active May 8, 2021 18:48
Return a value for an expression passed into a macro, even if that expression references other variables (so long as those variables are declared with inline). Originally from this thread https://community.haxe.org/t/macro-constant-arg-inline-final/3007
/**
Return a value for an expression passed into a macro, even if that expression references other variables (so long as those variables are declared with inline)
**/
function evalConstExpr(x: Expr) {
return try {
ExprTools.getValue(Context.getTypedExpr(Context.typeExpr(x)));
} catch (e) {
Context.error("Must be a constant expression (i.e. and expression containing only constants or variables declared with `inline`", x.pos);
}
}
@haxiomic
haxiomic / scrollDirectionDisambiguation.hx
Last active June 6, 2021 11:58
scrollDirectionDisambiguation
/**
* Tries to isolate vertical or horizontal scrolling with a continuous mapping.
* Originally written for valis
* @author haxiomic (George Corney)
*/
inline function scrollDirectionDisambiguation(event: WheelEvent): {x: Float, y: Float} {
// gesture disambiguation; when dominantly zooming we want to reduce panning speed
// normalize scroll vector
var scrollVectorLengthSq = event.deltaX * event.deltaX + event.deltaY * event.deltaY;
// avoid divide by 0 normalization issues
@haxiomic
haxiomic / UnitTestFramework.hx
Last active December 2, 2021 16:31
Super simple unit testing powered by haxe macros
#if macro
import haxe.macro.Context;
import haxe.macro.PositionTools;
import haxe.macro.Expr;
import haxe.macro.ComplexTypeTools;
#end
/**
Pass in a boolean expression, if test fails (expression evaluates to false) the expression itself will be printed with the line number and failure reason
@haxiomic
haxiomic / gist:d9cfa0f94c9f555a5dd39f70cfdeec38
Created July 26, 2020 12:45
@skylerparr lldb stack trace for StandaloneMain-debug
* thread #2, stop reason = EXC_BAD_ACCESS (code=2, address=0x700000897ca0)
frame #0: 0x0000000100004df4 StandaloneMain-debug`hx::ObjectPtr<hx::Object>::ObjectPtr(this=0x0000700000897ca0, inObj=0x0000000103ea850c) at Object.h:333:36
330 typedef OBJ_ *Ptr;
331
332 inline ObjectPtr() : mPtr(0) { }
-> 333 inline ObjectPtr(OBJ_ *inObj) : mPtr(inObj) { }
334 inline ObjectPtr(const null &inNull) : mPtr(0) { }
335 inline ObjectPtr(const ObjectPtr<OBJ_> &inOther) : mPtr( inOther.mPtr ) { }
336 template<typename T>
Target 0: (StandaloneMain-debug) stopped.
@haxiomic
haxiomic / fxaa.glsl
Created July 15, 2020 14:00
Mirror of NVIDIA FXAA 3.11 by TIMOTHY LOTTES
/*============================================================================
NVIDIA FXAA 3.11 by TIMOTHY LOTTES
------------------------------------------------------------------------------
COPYRIGHT (C) 2010, 2011 NVIDIA CORPORATION. ALL RIGHTS RESERVED.
------------------------------------------------------------------------------
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
// https://www.shadertoy.com/view/dlfXDN
// 2023 myth0genesis
// 4D Simplex Noise Gradient
// I saw that Stefan Gustavson didn't seem to have published any shader
// with an analytic solution for the gradients of his variant
// of 4D simplex noise, so I thought I'd try solving it myself
// and publish it here for anyone who finds it useful.
// Compares the analytic solution to the numerically approximated one (for a sanity check)
// and shows the results of all four derivatives with respect to each dimension.
// Top : Analytic gradient | Bottom: Forward differences approximated gradient
static function relativePath(relativeTo: String, path: String) {
// make both absolute
path = Path.removeTrailingSlashes(FileSystem.absolutePath(path));
relativeTo = Path.removeTrailingSlashes(FileSystem.absolutePath(relativeTo));
var aPath = path.split('/');
var aRelativeTo = relativeTo.split('/');
// find shared part of path
var matchesUpToIndex = 0;
// Author: @patriciogv
// Title: Simple Voronoi
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
@haxiomic
haxiomic / setHaxeVersion.sh
Created September 11, 2019 16:59
set haxe version bash
#folders should be named like: haxe-3.1.3, and the regular haxe folder should be removed
alias setHaxeVersion=_set_haxe_version
function _set_haxe_version(){
HAXE_PARENT="$(dirname "$HAXE_HOME")"
FIND_RESULT="`find $HAXE_PARENT -maxdepth 1 -name "haxe-*$1"`"
NUM_RESULTS=`echo "$FIND_RESULT" | wc -l`
if [[ $NUM_RESULTS -eq 1 ]] && [[ -n $FIND_RESULT ]] ; then
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
vec2 rotate(vec2 p, float radians) {
float c = cos(radians);