Line and Origin bug.

Archives Forums/Blitz3D Bug Reports/Line and Origin bug.

Floyd(Posted 2007) [#1]
Here is a very obscure bug with lines which have start and end points the same.
; Blitz3D Line bug, draws in wrong location.

; This seems to happen only if Origin is used and the line is a single pixel.
; Example code draws one-pixel lines in red, all else in blue.

; Uncomment the Origin command to see it go wrong.

Graphics 800, 600, 0, 2
HidePointer

;Origin 100, 100

Draw_Circle 250, 150, 125, 1200   ; Very short line segments, only one or two pixels.

WaitKey 


Function Draw_Circle( center_x#, center_y#, radius#, nPoints )

	delta# = 360.0 / nPoints
	
	For n = 0 To nPoints - 1
	
		angle# = n * delta 
	
		x1# = center_x + radius * Cos( angle )
		y1# = center_y + radius * Sin( angle ) 
	
		x2# = center_x + radius * Cos( angle + delta )
		y2# = center_y + radius * Sin( angle + delta ) 
		
		If Int(x1) = Int(x2) And Int(y1) = Int(y2)
			Color 255, 0, 0                            ; Red if screen points are the same.
		Else
			Color 0, 0, 255                            ; Blue if different.
		End If
		
		Line x1, y1,   x2, y2
		
		Delay 2
		
	Next

End Function



big10p(Posted 2007) [#2]
That's an odd one. This bug could feasibly affect my current project, too. :/


TomToad(Posted 2007) [#3]
After some experimenting, it seems the origin command is being doubled for single pixel length lines.
What's also weird is that as Origin gets closer to 0, some of the lines are not even drawn.
ETA: Actually that isn't weird at all. Apparently the lines are still getting clipped properly even though they are drawn at the wrong location.

Shown in this example. Blue is pixels drawn with plot, and red are pixels drawn with Line. Click and drag the left mouse button to change the origin.
Graphics 800,600,32,2
SetBuffer BackBuffer()

While Not KeyHit(1)
	Cls
	If MouseDown(1)
		Origin MouseX(),MouseY()
	End If
	
	For t = 0 To 360
		x = Cos(t)*100
		y = Sin(t)*100
		Color 0,0,255
		Plot x,y
		Color 255,0,0
		Line x,y,x,y
	Next
	Flip
Wend