TS implementation of defineShape

This works pretty well, is much more memory- (and probably CPU-) efficient than the previous implementation because it gets rid of quite a few buffer copies, and makes the acid test a lot more similar to what it's supposed to look like.