public static void width() { var a = new Mbr(1, 6, 3, 5); var b = new Mbr(3, 6, -1, 5); Assert.Equal(2, a.Width); Assert.Equal(4, b.Width); }
private ColumnMetadataCollection ScanClass(Type clsType) { var Res = new ColumnMetadataCollection(); var Members = clsType.GetMembers(BindingFlags.Instance | BindingFlags.GetField | BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Public); foreach (MemberInfo Mbr in Members) { var ColAttrs = Mbr.GetCustomAttributes(typeof(Attributes.Column), true); if (ColAttrs.Length == 1) { var NewCol = ColumnMetadataFromColumnAttribute(Mbr, ColAttrs[0] as Attributes.Column); var IdAttrs = Mbr.GetCustomAttributes(typeof(Attributes.Id), true); if (IdAttrs.Length == 1) { NewCol.Id = true; } var AssocAttrs = Mbr.GetCustomAttributes(typeof(Attributes.Association), true); if (AssocAttrs.Length == 1) { NewCol.AssociationMetada = AssociationMetadataFromAttribute(AssocAttrs[0] as Attributes.Association); } Res.Add(NewCol); } } return(Res); }
public static void xmax() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(4, 3, 2, 1); Assert.Equal(3, a.XMax); Assert.Equal(4, b.XMax); }
public static void xmin() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(4, 3, 2, 1); Assert.Equal(1, a.XMin); Assert.Equal(2, b.XMin); }
public static void height() { var a = new Mbr(1, 2, 6, 5); var b = new Mbr(1, 5, 6, -2); Assert.Equal(3, a.Height); Assert.Equal(7, b.Height); }
private bool PrintColoredMBRinSteps(ref Mbr anMbr, int StepNumber) { if (aStepsPrinter == null) { aStepsPrinter = new HexPrinter(ref richTextBox1, 32, anMbr.StartAddress, ref aLogger); } if (StepNumber == 1) { aStepsPrinter.Initialize(); } var aUnit = (from u in anMbr.Structure where u.Order == StepNumber select u).FirstOrDefault(); if (aUnit == null) { aLogger.LogMessage( $"in {MethodBase.GetCurrentMethod().Name}, the structure unit @ stepnumber{StepNumber} returns null value. Exit Method.", LogMsgType.Error); return(false); } aStepsPrinter.PrintValue(aUnit.Value, aUnit.UnitColor); return(true); }
public List <QuestionForms> GetVBRStartAddressandSizeQuestions(Mbr anMbr) { var questionList = new List <QuestionForms> { }; var vbrsList = VbrHelpers.GetVBRListFromMBR(anMbr, ref aLogger); Random rnd = new Random(); var number = 1; foreach (var v in vbrsList) { if (v.IsEmptyPartition()) { continue; } List <string> options = new List <string>(); for (int i = 0; i < 5; i++) { var rndNum = rnd.Next(v.BootSectorStartLocationByte() / 2, v.BootSectorStartLocationByte() * 3); if ((rndNum & 0xFF00) == v.BootSectorStartLocationByte()) { i--; continue; } //to avoid equal to the correct answer options.Add((rndNum & 0xFF00).ToString("X8")); } options.Add(v.BootSectorStartLocationByte().ToString("X8")); //Start Address Question questionList.Add( new QuestionForms(new Question($"Start Address of Volume {number}", GetMBRString(ref anMbr), v.BootSectorStartLocationByte().ToString("X8"), "Convert LBA Address (see VBR Structure) From Little Endian, Then Multiply by boot sector size", options, 3, QuizHelper.QuestionDifficulty.Hard), QuizHelper.InputValueType.HexVlaue)); List <string> sizeoptions = new List <string>(); for (int i = 0; i < 5; i++) { var rndNum = rnd.Next(v.Size / 2, v.Size * 3); if ((rndNum & 0xFF00) == v.Size) { i--; continue; } //to avoid equal to the correct answer sizeoptions.Add((rndNum & 0xFF00).ToString("X8")); } sizeoptions.Add(v.Size.ToString("X8")); //Size Question questionList.Add( new QuestionForms(new Question($"Size of Volume {number}", GetMBRString(ref anMbr), v.Size.ToString("X8"), "Convert Size (see VBR Structure) From Little Endian, Then Multiply by boot sector size", sizeoptions, 3, QuizHelper.QuestionDifficulty.Hard), QuizHelper.InputValueType.HexVlaue)); } return(questionList); }
public static void constructor_ranges() { var mbr = new Mbr(new Range(1, 3), new Range(4, 2)); Assert.Equal(1, mbr.XMin); Assert.Equal(2, mbr.YMin); Assert.Equal(3, mbr.XMax); Assert.Equal(4, mbr.YMax); }
public static void range_x() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(4, 3, 2, 1); a.X.Low.Should().Be(1); a.X.High.Should().Be(3); b.X.Low.Should().Be(2); b.X.High.Should().Be(4); }
static int Main() { // warning CS0197 is expected several times UnlockedCbo uc = new UnlockedCbo(); Interlocked.Increment(ref uc.Counter); uc.Inc(); LockedCbo lc = new LockedCbo(); try { Interlocked.Increment(ref lc.Counter); return(1); } catch (InvalidOperationException) { } lc.Inc(); if (lc.Counter != 1) { return(2); } Mbr m = new Mbr(); Interlocked.Increment(ref m.Counter); m.Inc(); if (m.Counter != 2) { return(3); } Mbr rm = (Mbr)CreateRemote(typeof(Mbr)); try { Interlocked.Increment(ref rm.Counter); return(4); } catch (InvalidOperationException) { } rm.Inc(); if (rm.Counter != 1) { return(5); } return(0); }
public static void constructor_points() { var mbr = new Mbr(new Point2(1, 2), new Point2(3, 4)); Assert.Equal(1, mbr.XMin); Assert.Equal(2, mbr.YMin); Assert.Equal(3, mbr.XMax); Assert.Equal(4, mbr.YMax); }
public static void constructor_values() { var mbr = new Mbr(1, 2, 3, 4); Assert.Equal(1, mbr.XMin); Assert.Equal(2, mbr.YMin); Assert.Equal(3, mbr.XMax); Assert.Equal(4, mbr.YMax); }
public static void intersects_mbr_test() { var a = new Mbr(1, 1, 5, 6); var b = new Mbr(0, 0, 3, 2); var c = new Mbr(2, 3, 4, 5); Assert.True(a.Intersects(b)); Assert.True(a.Intersects(c)); Assert.False(b.Intersects(c)); }
public static void disjoint_point() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 2, 3); var c = new Mbr(5, 6, 7, 8); var p = new Point2(2, 3); Assert.False(a.Disjoint(p)); Assert.False(b.Disjoint(p)); Assert.True(c.Disjoint(p)); }
public static void spatially_equal_point() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 2, 3); var c = new Mbr(5, 6, 7, 8); var p = new Point2(2, 3); Assert.False(a.SpatiallyEqual(p)); Assert.True(b.SpatiallyEqual(p)); Assert.False(c.SpatiallyEqual(p)); }
public static void within_point() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 2, 3); var c = new Mbr(3, 3, 3, 3); var p = new Point2(2, 3); Assert.False(a.Within(p)); Assert.True(b.Within(p)); Assert.False(c.Within(p)); }
public static void overlaps_point() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 2, 3); var c = new Mbr(5, 6, 7, 8); var p = new Point2(2, 3); Assert.False(((IRelatableOverlaps <Point2>)a).Overlaps(p)); Assert.False(((IRelatableOverlaps <Point2>)b).Overlaps(p)); Assert.False(((IRelatableOverlaps <Point2>)c).Overlaps(p)); }
public static void crosses_point() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 2, 3); var c = new Mbr(5, 6, 7, 8); var p = new Point2(2, 3); Assert.False(((IRelatableCrosses <Point2>)a).Crosses(p)); Assert.False(((IRelatableCrosses <Point2>)b).Crosses(p)); Assert.False(((IRelatableCrosses <Point2>)c).Crosses(p)); }
public static void contains_point() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 2, 3); var c = new Mbr(5, 6, 7, 8); var p = new Point2(2, 3); Assert.True(a.Contains(p)); Assert.True(b.Contains(p)); Assert.False(c.Contains(p)); }
private void PrintColoredMBR(ref Mbr anMbr) { var aPrinter = new HexPrinter(ref richTextBox1, 32, anMbr.StartAddress, ref aLogger); aPrinter.Initialize(); foreach (var unit in anMbr.Structure) { aPrinter.PrintValue(unit.Value, unit.UnitColor); } richTextBox1.AppendText(Environment.NewLine); }
/// <summary> /// Returns true if Profitability instances are equal /// </summary> /// <param name="other">Instance of Profitability to be compared</param> /// <returns>Boolean</returns> public bool Equals(Profitability other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Roe == other.Roe || Roe != null && Roe.Equals(other.Roe) ) && ( Npm == other.Npm || Npm != null && Npm.Equals(other.Npm) ) && ( Gpm == other.Gpm || Gpm != null && Gpm.Equals(other.Gpm) ) && ( Np == other.Np || Np != null && Np.Equals(other.Np) ) && ( Eps == other.Eps || Eps != null && Eps.Equals(other.Eps) ) && ( Mbr == other.Mbr || Mbr != null && Mbr.Equals(other.Mbr) ) && ( Ts == other.Ts || Ts != null && Ts.Equals(other.Ts) ) && ( Cs == other.Cs || Cs != null && Cs.Equals(other.Cs) )); }
public static void equals_type() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 4, 5); var c = new Mbr(b.X, b.Y); Assert.False(a.Equals(b)); Assert.False(a.Equals(c)); Assert.False(b.Equals(a)); Assert.True(b.Equals(c)); Assert.False(c.Equals(a)); Assert.True(c.Equals(b)); }
public static void spatially_equal() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 4, 5); var c = new Mbr(b.X, b.Y); Assert.False(((ISpatiallyEquatable <Mbr>)a).SpatiallyEqual(b)); Assert.False(((ISpatiallyEquatable <Mbr>)a).SpatiallyEqual(c)); Assert.False(((ISpatiallyEquatable <Mbr>)b).SpatiallyEqual(a)); Assert.True(((ISpatiallyEquatable <Mbr>)b).SpatiallyEqual(c)); Assert.False(((ISpatiallyEquatable <Mbr>)c).SpatiallyEqual(a)); Assert.True(((ISpatiallyEquatable <Mbr>)c).SpatiallyEqual(b)); }
public static void inequal_op() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 4, 5); var c = new Mbr(b.X, b.Y); Assert.True(a != b); Assert.True(a != c); Assert.True(b != a); Assert.False(b != c); Assert.True(c != a); Assert.False(c != b); }
public static void equals_op() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 4, 5); var c = new Mbr(b.X, b.Y); Assert.False(a == b); Assert.False(a == c); Assert.False(b == a); Assert.True(b == c); Assert.False(c == a); Assert.True(c == b); }
public static void equals_object() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 4, 5); var c = new Mbr(b.X, b.Y); Assert.False(a.Equals((object)b)); Assert.False(a.Equals((object)c)); Assert.False(b.Equals((object)a)); Assert.True(b.Equals((object)c)); Assert.False(c.Equals((object)a)); Assert.True(c.Equals((object)b)); }
public static void touches_point() { var a = new Mbr(1, 2, 3, 4); Assert.False(a.Touches(new Point2(2, 3))); Assert.False(a.Touches(Point2.Zero)); Assert.False(a.Touches(Point2.Invalid)); Assert.True(a.Touches(new Point2(1, 2))); Assert.True(a.Touches(new Point2(3, 4))); Assert.True(a.Touches(new Point2(1, 4))); Assert.True(a.Touches(new Point2(3, 2))); Assert.True(a.Touches(new Point2(2, 4))); Assert.True(a.Touches(new Point2(3, 3))); }
public static void touches_mbr() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 4, 4); var c = new Mbr(3, 4, 5, 6); var d = new Mbr(3, 0, 5, 6); var e = new Mbr(0, 4, 4, 6); Assert.False(a.Touches(a)); Assert.False(a.Touches(b)); Assert.True(a.Touches(c)); Assert.True(a.Touches(d)); Assert.True(a.Touches(e)); }
private bool ReadImage(string fileName) { aLogger.LogMessage($" Opening file [{fileName}]", LogMsgType.Verbose); //anMbr = Mbr.ParseMbr(fileName, ref aLogger); anMbr = Common.Common.GetUnit <Mbr>(fileName, ref aLogger, 0, "MBR", null); if (anMbr == null) { aLogger.LogMessage($"Unable to read MBR from file [{fileName}], Operation Terminated!", LogMsgType.Error); return(false); } aLogger.LogMessage($"Image [{fileName}], Loaded Successfully.", LogMsgType.Verbose); return(true); }
private string GetMBRString(ref Mbr anMbr) { var aPrinter = new StringHexPrinter(32, anMbr.StartAddress, ref aLogger); aPrinter.Initialize(); foreach (var unit in anMbr.Structure) { aPrinter.PrintValue(unit.Value, unit.UnitColor); } string mbrString = aPrinter.rtb; mbrString = mbrString + (Environment.NewLine); return(mbrString); }
static int Main () { // warning CS0197 is expected several times UnlockedCbo uc = new UnlockedCbo (); Interlocked.Increment (ref uc.Counter); uc.Inc (); LockedCbo lc = new LockedCbo (); try { Interlocked.Increment (ref lc.Counter); return 1; } catch (InvalidOperationException) { } lc.Inc (); if (lc.Counter != 1) return 2; Mbr m = new Mbr (); Interlocked.Increment (ref m.Counter); m.Inc (); if (m.Counter != 2) return 3; Mbr rm = (Mbr) CreateRemote (typeof (Mbr)); try { Interlocked.Increment (ref rm.Counter); return 4; } catch (InvalidOperationException) { } rm.Inc (); if (rm.Counter != 1) return 5; return 0; }
public static void intersects_point_test() { var mbr = new Mbr(new Point2(1, 2), new Point2(3, 4)); Assert.False(mbr.Intersects(new Point2(0, 0))); Assert.False(mbr.Intersects(new Point2(2, 1))); Assert.False(mbr.Intersects(new Point2(0, 3))); Assert.False(mbr.Intersects(new Point2(-1, -1))); Assert.False(mbr.Intersects(new Point2(10, 10))); Assert.True(mbr.Intersects(new Point2(1, 2))); Assert.True(mbr.Intersects(new Point2(3, 4))); Assert.True(mbr.Intersects(new Point2(3, 2))); Assert.True(mbr.Intersects(new Point2(1, 4))); Assert.True(mbr.Intersects(new Point2(2, 3))); }
public static void disjoint_mbr() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 4, 5); var c = new Mbr(3, 2, 5, 4); var d = new Mbr(3, 4, 5, 6); var e = new Mbr(5, 6, 7, 8); Assert.False(a.Disjoint(a)); Assert.False(a.Disjoint(b)); Assert.False(b.Disjoint(a)); Assert.False(a.Disjoint(c)); Assert.False(c.Disjoint(a)); Assert.False(a.Disjoint(d)); Assert.False(d.Disjoint(a)); Assert.True(a.Disjoint(e)); Assert.True(e.Disjoint(a)); }
public static void distange_squared_mbr() { var a = new Mbr(0, 0, 2, 2); var b = new Mbr(1, 1, 3, 3); var c = new Mbr(3, 4, 5, 5); var d = new Mbr(8, 8, 10, 10); Assert.Equal(0, a.DistanceSquared(b)); Assert.Equal((1 + 4), a.DistanceSquared(c)); Assert.Equal((36 + 36), a.DistanceSquared(d)); Assert.Equal(1, b.Distance(c)); Assert.Equal((25 + 25), b.DistanceSquared(d)); Assert.Equal((9 + 9), c.DistanceSquared(d)); }
public static void distance_squared_point() { var mbr = new Mbr(new Point2(1, 2), new Point2(3, 4)); Assert.Equal((1 + 4), mbr.DistanceSquared(new Point2(0, 0))); Assert.Equal(1, mbr.DistanceSquared(new Point2(2, 1))); Assert.Equal(1, mbr.DistanceSquared(new Point2(0, 3))); Assert.Equal((4 + 9), mbr.DistanceSquared(new Point2(-1, -1))); Assert.Equal((36 + (7 * 7)), mbr.DistanceSquared(new Point2(10, 10))); Assert.Equal(0, mbr.DistanceSquared(new Point2(1, 2))); Assert.Equal(0, mbr.DistanceSquared(new Point2(3, 4))); Assert.Equal(0, mbr.DistanceSquared(new Point2(3, 2))); Assert.Equal(0, mbr.DistanceSquared(new Point2(1, 4))); Assert.Equal(0, mbr.DistanceSquared(new Point2(2, 3))); }
public static void crosses_point() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 2, 3); var c = new Mbr(5, 6, 7, 8); var p = new Point2(2, 3); Assert.False(((IRelatableCrosses<Point2>)a).Crosses(p)); Assert.False(((IRelatableCrosses<Point2>)b).Crosses(p)); Assert.False(((IRelatableCrosses<Point2>)c).Crosses(p)); }
public static void distance_point() { var mbr = new Mbr(new Point2(1, 2), new Point2(3, 4)); Assert.Equal(System.Math.Sqrt(1 + 4), mbr.Distance(new Point2(0, 0))); Assert.Equal(1, mbr.Distance(new Point2(2, 1))); Assert.Equal(1, mbr.Distance(new Point2(0, 3))); Assert.Equal(System.Math.Sqrt(4 + 9), mbr.Distance(new Point2(-1, -1))); Assert.Equal(System.Math.Sqrt(36 + (7 * 7)), mbr.Distance(new Point2(10, 10))); Assert.Equal(0, mbr.Distance(new Point2(1, 2))); Assert.Equal(0, mbr.Distance(new Point2(3, 4))); Assert.Equal(0, mbr.Distance(new Point2(3, 2))); Assert.Equal(0, mbr.Distance(new Point2(1, 4))); Assert.Equal(0, mbr.Distance(new Point2(2, 3))); }
public static void crosses_mbr() { var a = new Mbr(1, 2, 3, 4); // 2x2 var b = new Mbr(2, 3, 2, 5); // 0x2 var c = new Mbr(2, 3, 4, 3); // 2x0 var d = new Mbr(2, 3, 2, 3); // 0x0 Assert.False(a.Crosses(a)); Assert.True(a.Crosses(b)); Assert.True(a.Crosses(c)); Assert.True(b.Crosses(a)); Assert.False(b.Crosses(b)); Assert.False(b.Crosses(c)); Assert.True(c.Crosses(a)); Assert.False(c.Crosses(b)); Assert.False(c.Crosses(c)); Assert.False(d.Crosses(a)); Assert.False(d.Crosses(b)); Assert.False(d.Crosses(c)); Assert.False(d.Crosses(d)); }
public static void within_mbr() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 4, 5); var c = new Mbr(1.5, 2.5, 2.5, 3.5); var d = new Mbr(1.5, 2, 2.5, 4); Assert.True(a.Within(a)); Assert.False(a.Within(b)); Assert.False(a.Within(c)); Assert.False(a.Within(d)); Assert.False(b.Within(a)); Assert.True(b.Within(b)); Assert.False(b.Within(c)); Assert.False(b.Within(d)); Assert.True(c.Within(a)); Assert.False(c.Within(b)); Assert.True(c.Within(c)); Assert.True(c.Within(d)); Assert.True(d.Within(a)); Assert.False(d.Within(b)); Assert.False(d.Within(c)); Assert.True(d.Within(d)); }
public static void spatially_equal() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 4, 5); var c = new Mbr(b.X, b.Y); Assert.False(((ISpatiallyEquatable<Mbr>)a).SpatiallyEqual(b)); Assert.False(((ISpatiallyEquatable<Mbr>)a).SpatiallyEqual(c)); Assert.False(((ISpatiallyEquatable<Mbr>)b).SpatiallyEqual(a)); Assert.True(((ISpatiallyEquatable<Mbr>)b).SpatiallyEqual(c)); Assert.False(((ISpatiallyEquatable<Mbr>)c).SpatiallyEqual(a)); Assert.True(((ISpatiallyEquatable<Mbr>)c).SpatiallyEqual(b)); }
public static void centroid() { var mbr = new Mbr(1, 2, 3, 4); Assert.Equal(new Point2(2, 3), mbr.GetCentroid()); }
public static void overlaps_point() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 2, 3); var c = new Mbr(5, 6, 7, 8); var p = new Point2(2, 3); Assert.False(((IRelatableOverlaps<Point2>)a).Overlaps(p)); Assert.False(((IRelatableOverlaps<Point2>)b).Overlaps(p)); Assert.False(((IRelatableOverlaps<Point2>)c).Overlaps(p)); }
public HttpResponseMessage Draw(double? minLon, double? maxLon, double? minLat, double? maxLat, int? maxImgWidth, int? maxImgHeight) { var shapefilePath = HostingEnvironment.MapPath("~/App_Data/builtupp_usa/builtupp_usa.shp"); ITransformation<GeographicCoordinate, Point2> transformation = null; var targetCrs = EpsgMicroDatabase.Default.GetCrs(3005); LongitudeDegreeRange dataLongitudeRange; Range dataLatitudeRange; using (var shapeFile = Shapefile.Open(shapefilePath)) { dataLongitudeRange = new LongitudeDegreeRange(shapeFile.Extent.MinX, shapeFile.Extent.MaxX); dataLatitudeRange = new Range(shapeFile.Extent.MinY, shapeFile.Extent.MaxY); var dataCrs = EpsgMicroDatabase.Default.GetCrs(4326); var pathGenerator = new EpsgCrsCoordinateOperationPathGenerator(); var paths = pathGenerator.Generate(dataCrs, targetCrs); var compiler = new StaticCoordinateOperationCompiler(); var firstTransfom = paths.Select(p => { return compiler.Compile(p); }).First(x => x != null); transformation = firstTransfom as ITransformation<GeographicCoordinate, Point2>; if (transformation == null && firstTransfom is IEnumerable<ITransformation>) transformation = new CompiledConcatenatedTransformation<GeographicCoordinate, Point2>((IEnumerable<ITransformation>)firstTransfom); } var geoMbrMin = new GeographicCoordinate(minLat ?? dataLatitudeRange.Low, minLon ?? dataLongitudeRange.Start); var geoMbrMax = new GeographicCoordinate(maxLat ?? dataLatitudeRange.High, maxLon ?? dataLongitudeRange.End); var geoMbrTL = new GeographicCoordinate(geoMbrMax.Latitude, geoMbrMin.Longitude); var geoMbrTR = new GeographicCoordinate(geoMbrMin.Latitude, geoMbrMax.Longitude); var projectedMbrPoints = new[] { geoMbrMin, geoMbrMax, geoMbrTL, geoMbrTR, new GeographicCoordinate(geoMbrMin.Latitude, Math.Abs(geoMbrMin.Longitude + geoMbrMax.Longitude) / 2.0) } .Select(transformation.TransformValue) .ToArray(); var projectedExtent = new Mbr( new Point2(projectedMbrPoints.Min(x => x.X), projectedMbrPoints.Min(x => x.Y)), new Point2(projectedMbrPoints.Max(x => x.X), projectedMbrPoints.Max(x => x.Y)) ); var geogMapOrigin = new GeographicCoordinate(dataLatitudeRange.Mid, dataLongitudeRange.Mid); var mapOrigin = transformation.TransformValue(geogMapOrigin); var mapOffset = new Vector2(0/*-(mapOrigin.X - projectedExtent.X.Mid)*/, projectedExtent.Height / 2.0); var imageSizeLimits = new Vector2(maxImgWidth ?? 300, maxImgHeight ?? 300); if (imageSizeLimits.X > 4096 || imageSizeLimits.Y > 4096) throw new ArgumentException("Image size too large"); var dataRatio = new Vector2(projectedExtent.Width / imageSizeLimits.X, projectedExtent.Height / imageSizeLimits.Y); var lowCorner = projectedExtent.Min; Vector2 desiredImageSize; double imageScaleFactor; if (dataRatio.Y < dataRatio.X) { imageScaleFactor = imageSizeLimits.X / projectedExtent.Width; desiredImageSize = new Vector2(imageSizeLimits.X, (int)(projectedExtent.Height * imageScaleFactor)); } else { imageScaleFactor = imageSizeLimits.Y / projectedExtent.Height; desiredImageSize = new Vector2((int)(projectedExtent.Width * imageScaleFactor), imageSizeLimits.Y); } using (var image = new System.Drawing.Bitmap((int)desiredImageSize.X, (int)desiredImageSize.Y)) using (var graphics = Graphics.FromImage(image)) { graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; var shapeSource = new PointShapefileShapeSource(shapefilePath); var shapeReader = new ShapeReader(shapeSource); using (var shapeEnumerator = shapeReader.GetEnumerator()) { var sourceCoordinates = ReadPagesToGeographicCoordinate(shapeEnumerator).SelectMany(x => x); var pointColor = Color.Black; var circleFillBrush = new SolidBrush(Color.FromArgb(64,16,64,128)); var featureRadius = 3.0; var featureDiameter = featureRadius * 2; var featureDiameterFloat = (float)featureDiameter; var topLeftOffset = new Vector2(-featureRadius,-featureRadius); foreach (var transformedPoint in transformation.TransformValues(sourceCoordinates)) { var offsetPoint = transformedPoint.Difference(lowCorner).Add(mapOffset); var scaledPoint = offsetPoint.GetScaled(imageScaleFactor); var screenPoint = new Point2(scaledPoint.X, image.Height - scaledPoint.Y); var drawTopLeft = screenPoint.Add(topLeftOffset); graphics.FillEllipse(circleFillBrush, (float)drawTopLeft.X, (float)drawTopLeft.Y, featureDiameterFloat, featureDiameterFloat); } } var result = new HttpResponseMessage(HttpStatusCode.OK); byte[] imageBytes; using (var memoryStream = new MemoryStream()) { image.Save(memoryStream, ImageFormat.Png); imageBytes = memoryStream.ToArray(); } result.Content = new ByteArrayContent(imageBytes); result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/png"); return result; } }
public static void distance_mbr() { var a = new Mbr(0, 0, 2, 2); var b = new Mbr(1, 1, 3, 3); var c = new Mbr(3, 4, 5, 5); var d = new Mbr(8, 8, 10, 10); Assert.Equal(0, a.Distance(b)); Assert.Equal(System.Math.Sqrt(1 + 4), a.Distance(c)); Assert.Equal(System.Math.Sqrt(36 + 36), a.Distance(d)); Assert.Equal(1, b.Distance(c)); Assert.Equal(System.Math.Sqrt(25 + 25), b.Distance(d)); Assert.Equal(System.Math.Sqrt(9 + 9), c.Distance(d)); }
public static void contains_mbr() { var a = new Mbr(1, 2, 3, 4); var b = new Mbr(2, 3, 4, 5); var c = new Mbr(1.5, 2.5, 2.5, 3.5); var d = new Mbr(1.5, 2, 2.5, 4); Assert.True(a.Contains(a)); Assert.False(b.Contains(a)); Assert.False(c.Contains(a)); Assert.False(d.Contains(a)); Assert.False(a.Contains(b)); Assert.True(b.Contains(b)); Assert.False(c.Contains(b)); Assert.False(d.Contains(b)); Assert.True(a.Contains(c)); Assert.False(b.Contains(c)); Assert.True(c.Contains(c)); Assert.True(d.Contains(c)); Assert.True(a.Contains(d)); Assert.False(b.Contains(d)); Assert.False(c.Contains(d)); Assert.True(d.Contains(d)); }