Math Problem/(Buffer coord to screen coords)vice verca

I have a linear buffer coordinate, i am to print onto a screen coordinate.

Say maxy = 20, maxx = 10, bufferx = 20, y, x,
Buffer coordinates to screen coordinates:
Algorithm: So for each maxx'th of bufferx, y will +1 and x will reset.
Mathematical: y = int bufferx / maxx,
const double averageIncr = int (maxx+1/maxx) - double (maxx+1/maxx);
So the amount of averageIncr in (int bufferx / maxx - float bufferx / maxx)
is the screen x coordinate. Then
(int bufferx / maxx - float bufferx / maxx) / averageIncr = x

Screen coordinates to buffer coordinates:
bufferx, y = 21, x = 10, maxy = 20, maxx = 10,

y * x would be the case if bufferx <= max screen coordinate.
There is no max bufferx.

I need to go.
Can anyone help me find the transition from screen coordinates to buffer coordinates?
Also, can anyone say if the algorithm within a for loop, or that the mathematical way would be slower or not? I rarely touch floating point stuff.
Last edited on
So you basically want to map two-dimensional array to one-dimensional and vice-versa?
So you basically want to map two-dimensional array to one-dimensional and vice-versa?

I didn't think of it like that, but yes.

But i already got the from one dimensional to two dimensional, all i need now is the from two dimensional to one dimensional.
Actually, now this method is no longer relevant.

I need a mathematical way to convert buffer coordinates to screen coordinates
whose maxx is undefined.

I just started working on an IDE using ncurses.
The previous method would work if i did multiple windows, but i don't want to do that.
I need to have the memory consume as low as possible.
The reason why the previous method won't work, is because i don't use multiple windows which means i will have to do all printing in a single window, which eliminates the use of a new line as soon as i want to do all text editing above the start of coordinate x. (The new line will automatically append the content beginning on coordinate x 0, instead of coordinate x 1).

The reason why the coordinate maxx is undefined is because, i use a single buffer, and in that buffer the user can add a newline character anywhere. (And each new line is a new y coordinate)
Topic archived. No new replies allowed.