When interacting with a PlanarRectangle, its sides are somtimes not perfectly horizontal / vertical, but have are slightly tilted. THis is probably a rounding problem: for calculating the remaining 2 corner points from the given 2 corner points, unsigned ints are used to represent the coordinates, but floating point should be used here.
Alternatively, I think a better option would even be to use 2 active corner control points (e.g. upper left and lower right) to model the rectangle, and calculate the remaining 2 corners only for the polyline.