mirror of
https://github.com/omniscale/magnacarto.git
synced 2025-09-28 04:03:33 +02:00
29 lines
643 B
Go
29 lines
643 B
Go
package mapserver
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strconv"
|
|
)
|
|
|
|
type transformation struct {
|
|
scale float64
|
|
rotate float64
|
|
}
|
|
|
|
var svgTransformRe = regexp.MustCompile(`(rotate|scale)\((-?\d*\.?\d+)\)`)
|
|
|
|
func parseTransform(transform string) (transformation, error) {
|
|
tr := transformation{}
|
|
for _, match := range svgTransformRe.FindAllStringSubmatch(transform, -1) {
|
|
switch match[1] {
|
|
case "rotate":
|
|
tr.rotate, _ = strconv.ParseFloat(match[2], 64)
|
|
case "scale":
|
|
tr.scale, _ = strconv.ParseFloat(match[2], 64)
|
|
default:
|
|
return tr, fmt.Errorf("unsupported transform function %s in %s", match[1], transform)
|
|
}
|
|
}
|
|
return tr, nil
|
|
}
|