IsInsideStroke() and coordinate systems

Post bugreports for the Windows version here
User avatar
HeX0R
Addict
Addict
Posts: 980
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

IsInsideStroke() and coordinate systems

Post by HeX0R »

I don't seem to get any dev-attendance here, so sorry for that clone, but I need some answers otherwise my current project is frozen.
Feel free to move it back to coding questions, or delete it and anwer in the original post, no problem.

Code: Select all


#TEST_ME = 0
; IsInsideStroke seems to always return 1, even if the point to check is far away from the path.
; Looks like IsInlineStroke() has problems working with numbers smaller than 1?
;#TEST_ME = 1
; Due to the manual the device coordinates (#PB_Coordinate_Device) should be fixed/unchangable
; no matter how much you extend/shrink the user coordinates via ScaleCoordinates/Translatecoordinates
; Why is the IsInsideStroke then not working with the mouse coordinates?
;#TEST_ME = 2
; Adding a simple ResetCoordinates() will make the Cursor selection work again
; Why is it like this, shouldn't the device coordinates be indepenant of any squeezing/extracting of the user coordinates and always work with the mouse coordinates??




Procedure draw()
	Protected x, y
	Static Once
	
	If StartVectorDrawing(CanvasVectorOutput(0))
		VectorSourceColor($FFFFFFFF)
		FillVectorOutput()
		ResetCoordinates()
		ScaleCoordinates(10, 100000)
		TranslateCoordinates(0.1, 0.0013)
		AddPathSegments("M 10 0.0001 L 20 0.003 L 30 0.0001 L 40 0.003")
		CompilerIf #TEST_ME = 0
			Debug "Testing (in User Coordinate system) if point 20 / 0.003 is on path (should be, see AddPathSegments)"
			Debug IsInsideStroke(20, 0.003, 0.01, #PB_Path_Default, #PB_Coordinate_User)
			Debug "Now testing (in User Coordinate system) if point 20 / 0.1 is on path (for sure not, I even used a ridiculous small width to test!)"
			Debug IsInsideStroke(20, 0.100, 0.000001, #PB_Path_Default, #PB_Coordinate_User)
			Debug "???"
			VectorSourceColor(RGBA(255, 0, 0, 255))
		CompilerElse
			x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
			y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
			If Once = 0
				Once = 1
				Debug "Move cursor and when you are above the path, the color should switch to blue"
			EndIf
			CompilerIf #TEST_ME = 2
				ResetCoordinates()
			CompilerEndIf
			If IsInsideStroke(x, y, 8, #PB_Path_Default, #PB_Coordinate_Device)
				VectorSourceColor(RGBA(0, 0, 255, 255))
			Else
				VectorSourceColor(RGBA(255, 0, 0, 255))
			EndIf
		CompilerEndIf
		StrokePath(0.01)
		StopVectorDrawing()
	EndIf
EndProcedure

If OpenWindow(0, 0, 0, 1000, 500, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	CanvasGadget(0, 0, 0, 1000, 500)
	draw()
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_CloseWindow
				Break
			Case #PB_Event_Gadget
				CompilerIf #TEST_ME > 0
					If EventGadget() = 0 And EventType() = #PB_EventType_MouseMove
						draw()
					EndIf
				CompilerEndIf
		EndSelect
	ForEver
EndIf
User avatar
HeX0R
Addict
Addict
Posts: 980
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: IsInsideStroke() and coordinate systems

Post by HeX0R »

I need to know if this will be fixed (or at least explained) in 5.73, otherwise I have to cancel that whole project or move to something else.

It's quite frustrating to get no single response from the devs for half a year, I still have no idea if I'm doing something wrong or it is a wrong behaviour.
User avatar
HeX0R
Addict
Addict
Posts: 980
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: IsInsideStroke() and coordinate systems

Post by HeX0R »

I didn't want to push this, let's see it as an ongoing monolog out of frustration.
I just thought I give it a trial with the latest PB6 Beta 7 version (although my project is dead anyway).
As expected the behaviour is still the same, but while playing I came up with a different example.
Maybe it helps.
There seems to be something wrong with StrokeWidth (see comment line 16) or I'm still too stupid to make things right, ...howsoever.
Take it or leave it, I don't care

Code: Select all

Structure _TEST_
	Path$
	ScaleX.d
	ScaleY.d
	StrokeWidth.d
EndStructure

Global Dim T._TEST_(2)
Global Show = 1


;non working one
T(0)\Path$       = "M 10 0.0001 L 20 0.003 L 30 0.0001 L 40 0.003"
T(0)\ScaleX      = 20
T(0)\ScaleY      = 100000
T(0)\StrokeWidth = 0.04419421  ;add 0.00000001 and you will see a big box instead of thin lines!
                               ;seems the problem is here somehow
;working one (all y * 10000)
T(1)\Path$       = "M 10 1 L 20 30 L 30 1 L 40 30"
T(1)\ScaleX      = 20
T(1)\ScaleY      = 10
T(1)\StrokeWidth = 0.5



Procedure draw()
	Protected x, y
	
	If StartVectorDrawing(CanvasVectorOutput(0))
		VectorSourceColor($FFFFFFFF)
		FillVectorOutput()
		ResetCoordinates()
		ScaleCoordinates(T(Show)\ScaleX, T(Show)\ScaleY)
		AddPathSegments(T(Show)\Path$)
		
		x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
		y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
		
		If IsInsideStroke(x, y, T(Show)\StrokeWidth, #PB_Path_Default, #PB_Coordinate_Device)
			VectorSourceColor(RGBA(0, 0, 255, 255))
		Else
			VectorSourceColor(RGBA(255, 0, 0, 255))
		EndIf
		StrokePath(T(Show)\StrokeWidth)
		StopVectorDrawing()
	EndIf
EndProcedure

If OpenWindow(0, 0, 0, 1000, 500, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	CanvasGadget(0, 0, 0, 1000, 400)
	TextGadget(1, 5, 405, 800, 24, "Move cursor and when you are above the path, the color should switch to blue")
	ButtonGadget(2, 5, 435, 200, 24, "Now Showing Working Version")
	draw()
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_CloseWindow
				Break
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 0
						If EventType() = #PB_EventType_MouseMove
							draw()
						EndIf
					Case 2
						Show ! 1
						draw()
						If Show = 0
							SetGadgetText(2, "Now Showing NON-Working Version")
						Else
							SetGadgetText(2, "Now Showing Working Version")
						EndIf
				EndSelect
		EndSelect
	ForEver
EndIf
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: IsInsideStroke() and coordinate systems

Post by STARGÅTE »

Hi HeXOR,

I think your problem has something do to with the following behavior.
In GDI+ (the base of the VectorDrawing lib) it is not possible to draw line thicknesses below 1.5. All these lines are always just 1 pixel.
In a scaled coordinate system, the thickness is scaled somehow with the smallest value in scaling.
This means, the switch between 1 pixel rendering and real thickness can be observed and more drastically when using different values for X and Y scaling.

Since, VectorDrawing is just a wrapper for GDI+, I see no chance to fix the bug in PureBasic.

Code: Select all

Enumeration
	#Window
	#Gadget
EndEnumeration

OpenWindow(#Window, 0, 0, 640, 640, "GDI+", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
CanvasGadget(#Gadget, 0, 0, WindowWidth(#Window), WindowHeight(#Window))

Define I.i
If StartVectorDrawing(CanvasVectorOutput(#Gadget))
	
	ScaleCoordinates(1, 1) ; Change here the scaling to e.g. (1, 0.5)
	
	For I = 1 To 30
		
		VectorSourceColor($FF000000)
		MovePathCursor(I*20+15, 15)
		DrawVectorText(StrF(I*0.1, 1))
		MovePathCursor(I*20+20.5, 40)
		AddPathLine(I*20+20.5, 250)
		StrokePath(I*0.1)
		
		MovePathCursor(10, I*20+15)
		DrawVectorText(StrF(I*0.1, 1))
		MovePathCursor(40, I*20+20.5)
		AddPathLine(250, I*20+20.5)
		StrokePath(I*0.1)
		
	Next
	StopVectorDrawing()
EndIf

Repeat
	Select WaitWindowEvent()
		Case #PB_Event_CloseWindow
			End
	EndSelect
ForEver
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Post Reply