Page 1 of 1

flipcoordinates

Posted: Thu Apr 15, 2021 12:11 pm
by William Van Hoecke
I am in the process of converting my commercial desktop c.a.d app written in PureBasic to a webapp.
Its going smooth up til now .... FlipCoordinatesX() and FlipCoordinatesY() seem to be missing in SpiderBasic.

As a workaround I could write my own routine to recalculate all the svg vectors to get a flipped drawing.... but that would be a severe slow down

Someone with a solution or fast workarround for that :?:?

Re: flipcoordinates

Posted: Thu Apr 29, 2021 4:57 pm
by KianV
Hi William.
It's hard to be precise without seeing exactly what you are trying to do, but a combination of TranslateCoordinates and ScaleCoordinates should do the trick.

Code: Select all

If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 0, 0, 400, 200)    
  
  If StartVectorDrawing(CanvasVectorOutput(0))
    
    ;normal coordinates (blue)
    VectorSourceColor(RGBA(0, 0, 255, 128))
    MovePathCursor(40, 20)
    For i = 1 To 4
      AddPathLine(80, 0, #PB_Path_Relative)
      AddPathLine(0, 40, #PB_Path_Relative)
    Next i
    StrokePath(10, #PB_Path_RoundCorner)
    
    ;FlipCoordinatesX(xflip)
    xflip=200
    MovePathCursor(0, 0)
    TranslateCoordinates(xflip*2,0)	;for yflip use (0,yflip*2)
    ScaleCoordinates(-1, 1)		;for yflip use (1,-1)
    
    ;flipped coordinates (red)
    VectorSourceColor(RGBA(255, 0, 0, 128))
    MovePathCursor(40, 20)
    For i = 1 To 4
      AddPathLine(80, 0, #PB_Path_Relative)
      AddPathLine(0, 40, #PB_Path_Relative)
    Next i
    StrokePath(10, #PB_Path_RoundCorner)
    
    ;Draw mirror line
    MovePathCursor(xflip,0)
    AddPathLine(0,200, #PB_Path_Relative)
    VectorSourceColor(RGBA(0,255, 0, 128))
    DashPath(3,10, #PB_Path_RoundCorner)
    
    StopVectorDrawing()
  EndIf
EndIf
Please be aware that this behaves a little strangely with vector text, since the coordinates appear to reference the top left of the first character.
I hope that this is useful.
Kian

Re: flipcoordinates

Posted: Wed May 05, 2021 10:12 pm
by William Van Hoecke
OF COURSE.....GR@#!çPM?grml.....why couldn't I think of that.
Negative scaling IS in fact mirroring. Forgot all about negative coordinates.
Very very much thanks Kian.

Converting my Purebasic desktop C.A.D. program that draws predefined symbols made up in svg
The symbols should be able to be moved, resized, rotated and .... taraaaa .... mirrored.

No details yet, but having some other vector drawing issues (behaving different from PB)

https://photos.app.goo.gl/WSbZAxWJfUZHgu3KA

Re: flipcoordinates

Posted: Thu May 06, 2021 4:47 pm
by KianV
Glad to be of help.
I don't know why I didn't do this before, but the two lines:

Code: Select all

MovePathCursor(0, 0)
TranslateCoordinates(xflip*2,0)
could just be replaced with:

Code: Select all

MovePathCursor(xflip, 0)
since the current PathCursor position is used as the origin of the scaling.

Kian