Page 1 of 1

IsInsideStroke() misbehaviour or misunderstanding?

Posted: Sun Apr 26, 2020 10:03 pm
by HeX0R
I'm struggling with this since quite a while now, I'm not sure, if I just don't understand it (most likely) or PB makes some mistakes here (unlikely, but not impossible).

Here is a test code, which shows some strange effects, I can't explain.
I have to say, these vector things are not really my world, but I would be happy, if someone could explain the following effects (play with #TEST_ME on top, and see the descriptions of my problems)

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

Re: IsInsideStroke() misbehaviour or misunderstanding?

Posted: Mon Apr 27, 2020 12:03 am
by RASHAD
Hi HeXor
I think if x & y fall on the center axis of the line so you will get 1 no matter if width are greater or smaller
But the width will be important if x and/or y are shifted out of the center

Re: IsInsideStroke() misbehaviour or misunderstanding?

Posted: Mon Apr 27, 2020 3:51 pm
by HeX0R
Yes, this is my interpretation also, but how exactly should that help or explain the result of any of my examples above?
If I draw a few lines, like so:

Code: Select all

"M 10 0.0001 L 20 0.003 L 30 0.0001 L 40 0.003"
How could a test of point "20 0.100" be inside this path?
It is not line centered, not even near by (yes o.k., considering the very small numbers it would be near by, you know what I mean)

Re: IsInsideStroke() misbehaviour or misunderstanding?

Posted: Mon Apr 27, 2020 11:15 pm
by RASHAD
Hi HeXor
Sorry for late
I will need more time to study the impact of ScaleCoordinates()
Because I think that not x & y coordinates will be affected but also the width of the StrokePath()
I have an idea right now to calculate that width but I need more time to investigate that

Have a good day sir

Re: IsInsideStroke() misbehaviour or misunderstanding?

Posted: Mon Apr 27, 2020 11:45 pm
by HeX0R
Hi RASHAD,

first of all: no need to apologize! We are all users, although you are a very helpful guy in this board, in the end you are still "just" a user/customer.
Means: it is not your job to help people, anyway it is much appreciated of course!

It is true, ScaleCoordinates() influences the width of the StrokePath(), I know that already, no need to investigate.

And we also might be able to recalculate x and y and even the width we need, but I'm more interested in some official statement to all my questions.
Because from my point of view there are three possibilities left:
1.) the manual is wrong
2.) the function has a bug
3.) I'm a moron and don't understand anything (might be true, I heard that quite often from my wife ;))

Re: IsInsideStroke() misbehaviour or misunderstanding?

Posted: Tue Apr 28, 2020 12:06 am
by RASHAD
Hi HeXOR
I can not stay doing nothing if I can help somebody beside I have some weird style of thinking (Out of the box as srod states) :P
I think that the manual do not have enough information and I will not in the near time :P

Re: IsInsideStroke() misbehaviour or misunderstanding?

Posted: Tue Apr 28, 2020 4:11 pm
by Little John
I think some information from Fred or Freak is needed here.