Menu

#975 PMAP() returns biased values

open
nobody
None
compiler
2022-12-19
2022-12-19
No

Expected purpose of 'PMAP':
- 'PMAP' allows to convert the coordinates modified by 'WINDOW' into coordinates in the current viewport, and vice versa.
- The current viewport can be either the declared graphics screen, or only a clipping region in the graphics screen when this one is declared by 'VIEW'.
- In all cases, the minimum coordinate value (xvmin or yvmin) in the current viewport is 0, and the maximum coordinate (xvmax or yvmax) is the offset value of the last pixel of the current viewport relative to the first of the current viewport.
- Example for 'SCREENRES width, height': xvmin=yvmin=0, xvmax=width-1, yvmax=height-1.
- Example for 'VIEW (x1, y1) - (x2, y2)': xvmin=yvmin=0, xvmax=x2-x1, yvmax=y2-y1.
- The modified coordinates declared by 'WINDOW SCREEN (xwmin, ywmin) - (xwmax, ywmax)' can be positive or negative, and xwmin corresponds to xvmin (0), ywmin corresponds to yvmin (0), xwmax corresponds to xvmax, ywmax corresponds to yvmax.

No graphic plotting bias between the different mappings:
Example with 'ScreenRes' mapping, then 'View' mapping, then 'Window Screen' mapping:

ScreenRes 500, 500             '' 'ScreenRes' mapping
Pset (10, 10)                  '' point #1
Pset (55, 55)                  '' point #2
Pset (100, 100)                '' point #3

View (10, 10) - (100, 100)     '' 'View' mapping
Pset (0, 0)                    '' point superimposed well at point #1
Pset (45, 45)                  '' point superimposed well at point #2
Pset (90, 90)                  '' point superimposed well at point #3

Window Screen (0, 0) - (9, 9)  '' 'Window Screen' mapping
Pset (0, 0)                    '' point superimposed well at point #1
Pset (4.5, 4.5)                '' point superimposed well at point #2
Pset (9, 9)                    '' point superimposed well at point #3

Sleep
  • The points: (10, 10) in the 'ScreenRes' mapping, (0, 0) in the 'View' mapping, and (0, 0) in the 'Window Screen' mapping all overlap well.
  • The points: (55, 55) in the 'ScreenRes' mapping, (45, 45) in the 'View' mapping, and (4.5, 4.5) in the 'Window Screen' mapping all overlap well.
  • The points: (100, 100) in the 'ScreenRes' mapping, (90, 90) in the 'View' mapping, and (9, 9) in the 'Window Screen' mapping all overlap well.

But there is a bias (IMHO) for the 'Pmap' function returns, that adds for example +1 pixel offset to the max value for the 'View' mapping:.
Maybe confusion between number of pixels (100 - 10 + 1 = 91) of the viewport, and number of intervals between pixels (100 - 10 = 90).
Example:

ScreenRes 500, 500
View (10, 10) - (100, 100)
Window Screen (0, 0) - (9, 9)

Print "Logical x=0, Physical x="; PMap(0, 0)        '' Expected 0, result: 0 => OK
Print "Logical y=0, Physical y="; PMap(0, 1)        '' Expected 0, result: 0 => OK
Print "Logical x=4.5, Physical x="; PMap(4.5, 0)    '' Expected 45, result: 45.5 => NOK
Print "Logical y=4.5, Physical y="; PMap(4.5, 1)    '' Expected 45, result: 45.5 => NOK
Print "Logical x=9, Physical x="; PMap(9, 0)        '' Expected 90, result: 91 => NOK
Print "Logical y=9, Physical y="; PMap(9, 1)        '' Expected 90, result: 91 => NOK

Print "Physical x=0, Logical x="; PMap(0, 2)        '' Expected 0, result: 0 => OK
Print "Physical y=0, Logical y="; PMap(0, 3)        '' Expected 0, result: 0 => NOK
Print "Physical x=45, Logical x="; PMap(45, 2)      '' Expected 4.5, result: 4.45055 => NOK
Print "Physical y=45, Logical y="; PMap(45, 3)      '' Expected 4.5, result: 4.45055 => NOK
Print "Physical x=45.5, Logical x="; PMap(45.5, 2)  '' Expected 9/90*45.5, result: 4.5 => NOK
Print "Physical y=45.5, Logical y="; PMap(45.5, 3)  '' Expected 9/90*45.5, result: 4.5 => NOK
Print "Physical x=90, Logical x="; PMap(90, 2)      '' Expected 9, result: 8.901099 => NOK
Print "Physical y=90, Logical y="; PMap(90, 3)      '' Expected 9, result: 8.901099 => NOK
Print "Physical x=91, Logical x="; PMap(91, 2)      '' Expected 9/90*91, result: 9 => NOK
Print "Physical y=91, Logical y="; PMap(91, 3)      '' Expected 9/90*91, result: 9 => NOK

Sleep

See also the 'PMAP documentation' example:

ScreenRes 640, 480
Window Screen (0, 0)-(100, 100)
Print "Logical x=50, Physical x="; PMap(50, 0)   '' 320  => NOK IMHO: 639/2 expected instead
Print "Logical y=50, Physical y="; PMap(50, 1)   '' 240  => NOK IMHO: 479/2 expected instead
Print "Physical x=160, Logical x="; PMap(160, 2) '' 25   => NOK IMHO: 100/639*160 expected instead
Print "Physical y=60, Logical y="; PMap(60, 3)   '' 12.5 => NOK IMHO: 100/479*60 expected instead
Sleep

SARG noted an inconsistency in gfxlib between the C code for calculating coordinates for PSET and that for PMAP calculations (expression 'context->view_w/h - 1' for the former, and only 'context->view_w/h' for the second).

See more details in the dedicated topic of the forum ('PMap Does not work correctly?' in General forum):
https://www.freebasic.net/forum/viewtopic.php?t=31991

Discussion


Log in to post a comment.