Last active
July 26, 2022 05:39
-
-
Save Kas-tle/10c8d1599c11db30a44be12ee603d2a9 to your computer and use it in GitHub Desktop.
JQ Texture Atlas Grouper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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