shortened for loops

This commit is contained in:
Daniel Suh 2024-05-16 23:41:50 -04:00
parent c2347859a2
commit 99f5596e8d
No known key found for this signature in database
GPG key ID: 7548E646186EFE39
2 changed files with 10 additions and 9 deletions

View file

@ -3,6 +3,7 @@
#### Improvements 🧹 #### Improvements 🧹
- Opacity 0 shapes no longer have a label mask which made any segment of connections going through them lower opacity [#1940](https://github.com/terrastruct/d2/pull/1940) - Opacity 0 shapes no longer have a label mask which made any segment of connections going through them lower opacity [#1940](https://github.com/terrastruct/d2/pull/1940)
- Bidirectional connections are now animated in opposite directions rather than one direction [#1939](https://github.com/terrastruct/d2/pull/1939)
#### Bugfixes ⛑️ #### Bugfixes ⛑️

View file

@ -539,8 +539,9 @@ func getPathStringIncrement(pathType *string) (int, error) {
func pathLength(pathData []string) (float64, error) { func pathLength(pathData []string) (float64, error) {
var x, y, pathLength float64 var x, y, pathLength float64
var prevPosition geo.Point var prevPosition geo.Point
var increment int
for i := 0; i < len(pathData); { for i := 0; i < len(pathData); i += increment {
switch pathData[i] { switch pathData[i] {
case "M": case "M":
x, _ = strconv.ParseFloat(pathData[i+1], 64) x, _ = strconv.ParseFloat(pathData[i+1], 64)
@ -565,13 +566,13 @@ func pathLength(pathData []string) (float64, error) {
} }
prevPosition = geo.Point{X: x, Y: y} prevPosition = geo.Point{X: x, Y: y}
increment, err := getPathStringIncrement(&pathData[i])
incr, err := getPathStringIncrement(&pathData[i])
increment = incr
if err != nil { if err != nil {
return 0, err return 0, err
} }
i += increment
} }
return pathLength, nil return pathLength, nil
@ -582,6 +583,7 @@ func splitPath(path string, percentage float64) (string, string, error) {
var sumPathLens, curPathLen, x, y float64 var sumPathLens, curPathLen, x, y float64
var prevPosition geo.Point var prevPosition geo.Point
var path1, path2 string var path1, path2 string
var increment int
pastHalf := false pastHalf := false
pathData := strings.Split(path, " ") pathData := strings.Split(path, " ")
@ -591,9 +593,7 @@ func splitPath(path string, percentage float64) (string, string, error) {
return "", "", err return "", "", err
} }
i := 0 for i := 0; i < len(pathData); i += increment {
for i < len(pathData) {
switch pathData[i] { switch pathData[i] {
case "M": case "M":
@ -670,13 +670,13 @@ func splitPath(path string, percentage float64) (string, string, error) {
pastHalf = true pastHalf = true
} }
increment, err := getPathStringIncrement(&pathData[i]) incr, err := getPathStringIncrement(&pathData[i])
increment = incr
if err != nil { if err != nil {
return "", "", err return "", "", err
} }
i += increment
prevPosition = geo.Point{X: x, Y: y} prevPosition = geo.Point{X: x, Y: y}
} }