Poly Outline Bug

Monkey Forums/Monkey Programming/Poly Outline Bug

malublu(Posted 2016) [#1]
Anybody find my outline bug?
Function DrawPolyLine:Void(drawlist:DrawList, vert:Float[], material:Material = Null)
	Local len:Int = vert.Length()
	If len < 4 Return
	
	Local startx:Float
	Local starty:Float
	Local stopx:Float
	Local stopy:Float
	
	For Local i:Int = 0 Until len / 2 Step 2
		startx = vert[i]
		starty = vert[i+1]
		stopx = vert[i+2]
		stopy = vert[i+3]
		drawlist.DrawLine(startx, starty, stopx, stopy, material)
	Next
	
	startx = vert[len-2]
	starty = vert[len-1]
	stopx = vert[0]
	stopy = vert[1]
	drawlist.DrawLine(startx, starty, stopx, stopy, material)
End


Thanks :D
My brain does not want ^^.

A example for rect.



It ignores one line.
On complexer poygones it ignores more lines.


Jesse(Posted 2016) [#2]
change the "Until" to "To"


Gerry Quinn(Posted 2016) [#3]
Change the For line to:

For Local i:Int = 0 Until len - 4 Step 2



malublu(Posted 2016) [#4]
I mix both solutions xD and it fix it :D
Function DrawPolyLine:Void(drawlist:DrawList, vert:Float[], material:Material = Null)
	Local len:Int = vert.Length()
	If len < 4 Return
	For Local i:Int = 0 To len - 4 Step 2
		drawlist.DrawLine(vert[i], vert[i+1], vert[i+2], vert[i+3], material)
	Next
	drawlist.DrawLine(vert[len-2], vert[len-1], vert[0], vert[1], material)
End



Gerry Quinn(Posted 2016) [#5]
You are right, of course, it should be "To len - 4" or else "Until len - 2"

My habit is to avoid using To except in rare case, because Until tends to match up better with the way we count in code, Similar to zero-indexing. Early Basics used to often index from 1, perhaps on the assumption that zero-indexing was too confusing for coders. Later many of them offered a choice. And eventually, indexing from 1 kind of died.