private void CheckPoint(Rectangle rect, PointD point)
{
if (point.X < rect.X) {
point.X = rect.X;
} else if (point.X > rect.X + rect.Width) {
point.X = rect.X + rect.Width;
}
if (point.Y < rect.Y) {
point.Y = rect.Y;
} else if (point.Y > rect.Y + rect.Height) {
point.Y = rect.Y + rect.Height;
}
}