How can I normalize Rect coordinates in my database?

Q:

I have a variety of annotation information persisted to my database. I need to normalize all the Rect coordinates so that, when I convert them to XFDF and import them to Acrobat, they display correctly. How can I do so?

A:

If you have coordinates in a PDFNet Rect object, you can simply call Rect.Normalize().

Note, however, that Normalization is very simple, so you could easily write your own code to normalize coordinates in your database.

The code would look something like

if (x1 > x2) swap(x1, x2);
if (y1 > y2) swap(y1, y2);

in an imperative programming language, and would look something like

UPDATE Rects
SET x1=(@temp:=x1),
x1 = x2,
x2 = @temp
WHERE x1 > x2

UPDATE Rects
SET y1=(@temp:=y1),
y1 = y2,
y2 = @temp
WHERE y1 > y2

in MySQL.