I am trying to store a rectangle inside a table.
At the moment i have 4 seperate columns:
I noticed that PostgreSql offers a datatype called box.
However this datatype automatically reorders the values based on:
Any two opposite corners can be supplied on input, but the values will be reordered as needed to store the upper right and lower left corners, in that order.
I tried using the box datatype for rectangles but as stated it sometimes mixes upperright and bottomleft, so it is not suitable for storing top, left, width and height.
I am writing a C# application that handles those values. Therefore it would be nice if i have a datatype that is equivalent to the C# Rectangle type.
I am wondering how to implement a rectangle / rect datatype. Maybe even write an own datatype based on four integers (array[4])?
It doesn't mix the points, it stores them with the top right values first. You will just have to read out these and work out the other 2 points yourself if you need them.
That's not exactly complicated stuff - at the least you can read the top/right point and take the top value, and the bottom/left point and take the left point to obtain the top/left point you want. Similarly, reading width is just right minus left.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With