[BUGFIX] splitting in parts
This commit is contained in:
parent
f42ec9e116
commit
65e3dc9ef8
13
main.go
13
main.go
|
@ -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
11
part.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue