func (p *PathData) ShortenPathData(b []byte) []byte {
	if 100000 < len(b) {
		return b
	}
	var cmd byte
	p.x, p.y = 0.0, 0.0
	p.coords = p.coords[:0]
	p.coordFloats = p.coordFloats[:0]
	p.state = PathDataState{}
	j := 0
	for i := 0; i < len(b); i++ {
		c := b[i]
		if c == ' ' || c == ',' || c == '\n' || c == '\r' || c == '\t' {
			continue
		} else if pathCmds[c] && (cmd == 0 || cmd != c || c == 'M' || c == 'm') {  
			if cmd != 0 {
				j += p.copyInstruction(b[j:], cmd)
			}
			cmd = c
			p.coords = p.coords[:0]
			p.coordFloats = p.coordFloats[:0]
		} else if (cmd == 'A' || cmd == 'a') && (len(p.coordFloats)%7 == 3 || len(p.coordFloats)%7 == 4) {
			if c == '1' {
				p.coords = append(p.coords, b[i:i+1])
				p.coordFloats = append(p.coordFloats, 1.0)
			} else if c == '0' {
				p.coords = append(p.coords, b[i:i+1])
				p.coordFloats = append(p.coordFloats, 0.0)
			} else {
				cmd = 0  
			}
		} else if n := parse.Number(b[i:]); n > 0 {
			f, _ := strconv.ParseFloat(b[i : i+n])
			p.coords = append(p.coords, b[i:i+n])
			p.coordFloats = append(p.coordFloats, f)
			i += n - 1
		}
	}
	if cmd == 0 {
		return b
	}
	j += p.copyInstruction(b[j:], cmd)
	return b[:j]
}
ShortenPathData takes a full pathdata string and returns a shortened version. The original string is overwritten.
It parses all commands (M, A, Z, ...) and coordinates (numbers) and calls copyInstruction for each command.
package svg
import (
	"math"
	strconvStdlib "strconv"
	"github.com/tdewolff/minify/v2"
	"github.com/tdewolff/parse/v2"
	"github.com/tdewolff/parse/v2/strconv"
)
type PathData struct {
	o *Minifier
	x, y        float64
	x0, y0      float64
	coords      [][]byte
	coordFloats []float64
	cx, cy      float64  
	qx, qy      float64  
	state       PathDataState
	curBuffer   []byte
	altBuffer   []byte
	coordBuffer []byte
}
type PathDataState struct {
	cmd            byte
	prevDigit      bool
	prevDigitIsInt bool
	prevFlag       bool
}
func NewPathData(o *Minifier) *PathData {
	return &PathData{
		o:  o,
		cx: math.NaN(),
		cy: math.NaN(),
		qx: math.NaN(),
		qy: math.NaN(),
	}
}
var pathCmds = map[byte]bool{
	'M': true,
	'm': true,
	'L': true,
	'l': true,
	'H': true,
	'h': true,
	'V': true,
	'v': true,
	'Q': true,
	'q': true,
	'T': true,
	't': true,
	'C': true,
	'c': true,
	'S': true,
	's': true,
	'A': true,
	'a': true,
	'Z': true,
	'z': true,
}