public void ExtentCloneTest() { Extent e = new Extent(3, 6, 8, 9); Assert.AreEqual(e, e.Clone(), "e is not equal to e.Clone()"); Assert.AreNotSame(e, e.Clone(), "e is the same as e.Clone()"); }
/// <summary>Modifies the extent such that its left edge is normalised into the range [-180..180] degrees. /// Its width remains constant unless it was originally greater than 360 degrees, /// in which case it is scaled to 360 degrees width and retains its aspect ratio.</summary> /// <param name="extent">Extent that gets normalised.</param> /// <returns>The normalised extent.</returns> public static Extent Normalised(this Extent extent) { var newExtent = (Extent)extent.Clone(); if (newExtent.Width > 360.0) { const double NewWidth = 360.0; double newHeight = newExtent.Height * NewWidth / newExtent.Width; double xOffset = (newExtent.Width - NewWidth) / 2.0; double yOffset = (newExtent.Height - newHeight) / 2.0; newExtent.Width = NewWidth; newExtent.Height = newHeight; newExtent.X += xOffset; newExtent.Y -= yOffset; // pinned to top left. } while (newExtent.X < -180) { double x = newExtent.X + 360.0; if (x == newExtent.X) { throw new ArgumentException(MessageStrings.ExtentXIsTooLargeForDegreesToBeSignificant); } newExtent.X = x; } while (newExtent.X > 180) { double x = newExtent.X - 360.0; if (x == newExtent.X) { throw new ArgumentException(MessageStrings.ExtentXIsTooLargeForDegreesToBeSignificant); } newExtent.X = x; } return(newExtent); }
// Modifies the extent such that its left edge is normalised into the range [-180..180] degrees. // It width remains constant unless it was originally greater than 360 degrees, // in which case it is scaled to 360 degrees with and retains its aspect ratio. public static Extent Normalised(this Extent extent) { var new_extent = (Extent)extent.Clone(); if (new_extent.Width > 360.0) { const double new_width = 360.0; double new_height = new_extent.Height * new_width / new_extent.Width; double x_offset = (new_extent.Width - new_width) / 2.0; double y_offset = (new_extent.Height - new_height) / 2.0; new_extent.Width = new_width; new_extent.Height = new_height; new_extent.X += x_offset; new_extent.Y -= y_offset; // pinned to top left. } while (new_extent.X < -180) { double x = new_extent.X + 360.0; if (x == new_extent.X) { throw new ArgumentException("Extent.X is too large for degrees to be significant"); } new_extent.X = x; } while (new_extent.X > 180) { double x = new_extent.X - 360.0; if (x == new_extent.X) { throw new ArgumentException("Extent.X is too large for degrees to be significant"); } new_extent.X = x; } return(new_extent); }