Skip to content

Instantly share code, notes, and snippets.

@finscn
finscn / remove-t-junctions.js
Created June 28, 2026 14:29 — forked from mourner/remove-t-junctions.js
Post-processing fix for Earcut's non-comforming output
// Post-processing fix for Earcut's issue https://github.com/mapbox/earcut/issues/74
// Split triangle edges wherever another vertex lies strictly on them (exact-coordinate input).
export function removeTJunctions(data, tri) {
const n = data.length / 2;
// bucket every vertex into a uniform spatial hash so edge lookups stay local
let minx=Infinity,miny=Infinity,maxx=-Infinity,maxy=-Infinity;
for (let i=0;i<n;i++){const x=data[2*i],y=data[2*i+1];if(x<minx)minx=x;if(y<miny)miny=y;if(x>maxx)maxx=x;if(y>maxy)maxy=y;}
const size = Math.max(maxx-minx, maxy-miny) / Math.max(1, Math.sqrt(n)) || 1;
const key = (cx,cy) => cx*73856093 ^ cy*19349663;
@finscn
finscn / tiledmap-types.ts
Last active November 19, 2025 11:48
a simple type declaration file for `Tiled Map JSON` (.tmj).
declare module 'TiledMap' {
export namespace TMX {
// cSpell:disable
export interface Map {
backgroundcolor?: string;
class?: string;
compressionlevel: number;
height: number;
@finscn
finscn / Toucher.ts
Last active January 25, 2020 18:49
Touch lib for cocos creator 2.x
// export { default as Tap } from "./Tap";
// export { default as DoubleTap } from "./DoubleTap";
// export { default as Swipe } from "./Swipe";
const { ccclass, property } = cc._decorator;
@ccclass
export default class Toucher extends cc.Component {
@property
@finscn
finscn / TouchWrapper.ts
Created January 23, 2020 19:25
TouchWrapper for cocos creator 2.3
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const { ccclass, property } = cc._decorator;
@ccclass
@finscn
finscn / wx-minigame-error.js
Last active May 5, 2019 08:11
load the error list of weixin minigame
// 需要设置正确的 token
var token = 985700508;
// 开始时间 [年,月,日,时] , 设置为null, 则为今天的整点时刻往前7天.
var startTime = null; // [2019, 4, 28, 14];
// 结束时间 [年,月,日,时] , 设置为null, 则为今天的整点时刻.
var endTime = null; // [2019, 5, 5, 14];
// 关键字 (微信有bug, 不是所有出现在错误信息里的字符串都能被检索)
@finscn
finscn / update-git-repos.sh
Last active May 5, 2019 07:32
update local git repositories in directory
#!/bin/bash
CURRENT=$PWD
echo $CURRENT
function ergodic(){
if [ -n "$1" ] ;then
echo '>>>>>> ENTER [' $1 '] >>>>>>'
cd $1
else
// From http://baagoe.com/en/RandomMusings/javascript/
function Alea() {
return (function(args) {
// Johannes Baagøe <baagoe@baagoe.com>, 2010
var s0 = 0;
var s1 = 0;
var s2 = 0;
var c = 1;
if (args.length == 0) {
// From http://baagoe.com/en/RandomMusings/javascript/
function Alea() {
return (function(args) {
// Johannes Baagøe <baagoe@baagoe.com>, 2010
var s0 = 0;
var s1 = 0;
var s2 = 0;
var c = 1;
if (args.length == 0) {
@finscn
finscn / .bash_profile
Last active April 27, 2016 19:31
My .bash_profile
export TERM=xterm-color
# for color
export CLICOLOR=1
export LSCOLORS=gxfxaxdxcxegedabagacad
# grep
alias grep='grep --color=always'
export COLOR_NC='\\e[0m' # No Color
export COLOR_WHITE='\\e[1;37m'
@finscn
finscn / NewFile.py
Created June 19, 2015 07:39
A plugin of SublimeText 3 : Let the FOLDER of a new untitled file be as same as the folder of current activated file.
# NewFileAtCurrentFolder
import sublime_plugin
import os.path
class NewFileListener(sublime_plugin.EventListener):
def on_new_async(self, view):
if not view.window().active_view():
print("NF: no view")
return