AnonMiraj / fig

FIG (Fortran Intuitive Graphics)
MIT License
22 stars 2 forks source link

Coordinate space design #30

Closed perazz closed 2 weeks ago

perazz commented 4 weeks ago

This issue wants to support the discussion of how to design a unique coordinate space @AnonMiraj @johandweber @everythingfunctional.

One option could be to have one class that describes coordinates in the drawing space:

type :: point
   real :: x
   real :: y
end type point

All (x,y) coordinates in the drawing space that appear on the canvas would be of type(point) and in range between point(0,0) and point(1,1).

The canvas would instead be described by image coordinates (pixels):

type :: canvas_point
   integer(pixel) :: x
   integer(pixel) :: y
end type canvas_point

type :: canvas_size
   integer(pixel) :: width
   integer(pixel) :: height
end type

A type(canvas_size) :: size variable would be included in every canvas.

A linear mapping can describe the relationship between point and canvas_point: something like

elemental type(canvas_point) function to_canvas(x, size) result(pxl)
   type(point), intent(in) :: x
   type(canvas_size), intent(in) :: size

   pxl%x = nint(x%x*size%width, kind=pixel)
   pxl%y = nint(x%y*size%height, kind=pixel)
end function
AnonMiraj commented 3 weeks ago

I have a question.

Let's say I have a circle centered at (0.5, 0.5) with a radius of 0.25. I would assume that the radius would also be between 0 and 1.

But how would it be translated to, for example, an 800600 canvas? I don't think it really makes sense for the circle to become an ellipse. Should it translate like this: Radius: 0.25 (800+600)/2 = 175 pixels, or is there a better way?

everythingfunctional commented 3 weeks ago

You may want to have distinction between size and position.

AnonMiraj commented 3 weeks ago

So I should leave all size units as pixels?

everythingfunctional commented 3 weeks ago

You may want to support 3 different sizes (one with multiple units):

Note that the conversions between any of them depend on how the size and resolution of the drawing is specified