Vector Graphice inaccurate?

Post bugreports for the Windows version here
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Vector Graphice inaccurate?

Post by collectordave »

Just trying the code below.

get screen DPI.

Resize canvasgadget to a width of 210mm

Drawline 200mm long.

Canvas gadget shows with a width of 200mm and a little bit

the line is drawn with a length of 185mm more or less.

Are the vector graphics functions inaccurate?

Code: Select all


Global Window_0

Global Canvas_0,ScreenDPI

Macro mm2px(mm)
    Round(ScreenDPI/25.4 * mm, #PB_Round_Nearest) 
  EndMacro
  
  Procedure GetScreenDPI()
  
  StartVectorDrawing(CanvasVectorOutput(Canvas_0,#PB_Unit_Pixel))
  ScreenDPI = VectorResolutionX()
  StopVectorDrawing()

EndProcedure

  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_Maximize)
  Canvas_0 = CanvasGadget(#PB_Any, 10, 10,100, 80)
  
  GetScreenDPI()

  ResizeGadget(Canvas_0, 10,10,mm2px(210),80)

  StartVectorDrawing(CanvasVectorOutput(Canvas_0,#PB_Unit_Millimeter))
  MovePathCursor(5,10)
  AddPathLine(200,10)
  StrokePath(1)

  StopVectorDrawing()

Repeat
  
  event = WaitWindowEvent()

Until event = #PB_Event_CloseWindow
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
mhs
Enthusiast
Enthusiast
Posts: 101
Joined: Thu Jul 02, 2015 4:53 pm
Location: Germany
Contact:

Re: Vector Graphice inaccurate?

Post by mhs »

Confirmed

It seems to be a calculation error, the longer the line. If you use 10mm or 1inch it seems to be ok.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Vector Graphice inaccurate?

Post by wilbert »

collectordave wrote:Drawline 200mm long.
The default for AddPathLine is absolute coordinates so you are drawing a 195 mm long line (200 - 5).
Windows (x64)
Raspberry Pi OS (Arm64)
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Vector Graphice inaccurate?

Post by collectordave »

Just changed drawline code to

Code: Select all

  StartVectorDrawing(CanvasVectorOutput(Canvas_0,#PB_Unit_Millimeter))
  MovePathCursor(10,10)
  AddPathLine(200,10)
  MovePathCursor(200,10)
  AddPathLine(200,100)
  StrokePath(1)
So now realizing that it is absolute coordinates the first horizontal line should be 190mm long. Starting at 10mm from the left edge that should reach a point 200mm from the left edge. It actually reaches a point 190mm from the left edge and is only 180mm in length.

The vertical line should start 10mm from the top edge and reach a point 100mm below the top edge. It only reaches 95mm from the top edge.

This still leaves the canvas gadget sizing. The screen resolution is 96DPI so the calculation finds the number of pixels needed to represent 210mm on the screen and it actually draws to a width of 200mm on screen.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Vector Graphice inaccurate?

Post by wilbert »

I compared OSX against Windows on my Mac.
OSX returns a value of 103 PPI (right), Windows a value of 96 PPI (wrong).
So the problem is that VectorResolutionX() does return the wrong value on Windows.

It seems to be really problematic (impossible ?) on Windows to get information about the physical screen size.
Maybe this helps although I'm not sure if it is supported for non Metro apps http://dwcares.com/actual-size/
Windows (x64)
Raspberry Pi OS (Arm64)
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Vector Graphice inaccurate?

Post by collectordave »

Tried an online dpi calculator for my screen and it returned 100dpi. Put this in and it works on the canvas sizing. It does appear that windows reports the wrong DPI.

Also looked at the importance of this. Unless you need accurate measurments on screen. As long as the error is the same for all operations then you still get an accurate picture of whatever you are drawing just not real life (scale is off by the error).

The most important time is when the output is printed. Has anyone tried printing accurately? I have done some printing work with the vector graphics but never measured the finished article.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: Vector Graphice inaccurate?

Post by helpy »

collectordave wrote:It does appear that windows reports the wrong DPI.
Windows returns the DPI which is set in the Windows settings.
See: http://www.techrepublic.com/blog/window ... i-scaling/

Change the DPI setting in windows and it probably should work.

guido
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Vector Graphice inaccurate?

Post by collectordave »

Thanks. Changed the DPI setting to my actual DPI and it reports back to PB correctly and the screen and gadgets etc are all drawn to scale.

However change the resolution of the screen and the DPI setting does not change so back to square one.

PB is OK just windows reporting a setting instead of the actual DPI at whatever screen resolution set by user.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: Vector Graphice inaccurate?

Post by helpy »

Consider the following:

==> Not each monitor is able to report the hardware resolution of the display!

==> It seems that only Windows 8 and 10 are prepared for reading display resolution
--> https://msdn.microsoft.com/en-us/librar ... nformation
--> https://msdn.microsoft.com/en-us/librar ... on.rawdpix
--> http://blogs.windows.com/windowsexperie ... hancements
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Vector Graphice inaccurate?

Post by collectordave »

Yes

Was reading and searching and found an article explaining this. It is possible under windows 8 hopefully someone can test that with the vector graphics commands?
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
mhs
Enthusiast
Enthusiast
Posts: 101
Joined: Thu Jul 02, 2015 4:53 pm
Location: Germany
Contact:

Re: Vector Graphice inaccurate?

Post by mhs »

I'm using Win 8.1... it's not working with my monitor.

The monitor has 90 dpi and I get a return value of 96.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Vector Graphice inaccurate?

Post by collectordave »

The basic answer is that windows reports a setting. This setting is not updated when the resolution is changed, not even to apply the PPI to DPI scaling factor. Something windows has missed.

There is a difference between PPI and DPI which seems to have confused Microsoft. they seem to be trying to simply satisfy as many people as possible and saying sod it to the truth.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Post Reply