[BUGFIX] splitting in parts

This commit is contained in:
Martin/Geno 2018-12-31 23:59:33 +01:00
parent f42ec9e116
commit 65e3dc9ef8
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
2 changed files with 15 additions and 9 deletions

13
main.go
View File

@ -51,10 +51,15 @@ func main() {
// transform
pixelmatrix = getPart(pixelmatrix, partCount, partTotal, partBegin)
pixelmatrix, sx, sy := getPart(pixelmatrix, partCount, partTotal, partBegin)
startx += sx
starty += sy
for s := 0; s < socketCount; s++ {
conn := createSocket(getPart(pixelmatrix, 1, socketCount, s))
pm, sx, sy := getPart(pixelmatrix, 1, socketCount, s)
sx += startx
sy += starty
conn := createSocket(pm, sx, sy)
defer conn.Close()
}
@ -66,7 +71,7 @@ func main() {
}
func createSocket(pixelmatrix [][][4]uint32) net.Conn {
func createSocket(pixelmatrix [][][4]uint32, xstart, ystart int) net.Conn {
// connection(s)
conn, err := net.Dial("tcp", targetAddr)
if err != nil {
@ -76,7 +81,7 @@ func createSocket(pixelmatrix [][][4]uint32) net.Conn {
// start painting
for s := 0; s < goProc; s++ {
go paint(conn, pixelmatrix, startx, starty)
go paint(conn, pixelmatrix, xstart, ystart)
}
return conn
}

11
part.go
View File

@ -4,17 +4,18 @@ import (
log "github.com/sirupsen/logrus"
)
func getPart(pixelmatrix [][][4]uint32, partCount, partTotal, partBegin int) [][][4]uint32 {
func getPart(pixelmatrix [][][4]uint32, partCount, partTotal, partBegin int) ([][][4]uint32, int, int) {
xLength := len(pixelmatrix)
if xLength < partTotal {
log.Fatal("more parts then rows not possible")
return nil
return nil, 0, 0
}
partSize := (xLength / partTotal)
partStep := (xLength / partTotal)
start := partBegin * partStep
// last part should return last rows
if partBegin + partCount == partTotal {
return pixelmatrix[ partBegin * partSize : ]
return pixelmatrix[start: ], start, 0
}
return pixelmatrix[ partBegin * partSize : (partBegin + partCount) * partSize]
return pixelmatrix[ start : (partBegin + partCount) * partStep], start, 0
}