Skip to content

Instantly share code, notes, and snippets.

@Kas-tle
Last active July 26, 2022 05:39
Show Gist options
  • Save Kas-tle/10c8d1599c11db30a44be12ee603d2a9 to your computer and use it in GitHub Desktop.
Save Kas-tle/10c8d1599c11db30a44be12ee603d2a9 to your computer and use it in GitHub Desktop.
JQ Texture Atlas Grouper
def intersects(a;b): any(a[]; . as $x | any(b[]; . == $x));
def mapatlas(set):
(set | unique) as $unique_set
| (map(if intersects(.; $unique_set) then . else empty end) | add + $unique_set | unique) as $new_set
| map(if intersects(.; $new_set) then empty else . end) + [$new_set];
reduce .[] as $entry ([]; mapatlas($entry))
# | to_entries | .[]? | select(any(.value[]; . == "red")) | .key
#[
# ["red", "black", "orange"],
# ["coral", "green", "blue"],
# ["zzz", "qqq", "xxx"],
# ["7", "qqq", "blue"]
#]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment