コード例 #1
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #4
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #5
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #6
0
ファイル: mbrFrm.cs プロジェクト: SariSultan/SDES
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #9
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #10
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #11
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #12
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #13
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #14
0
    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);
    }
コード例 #15
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #16
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #17
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #18
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #19
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #20
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #21
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #22
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #23
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #24
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #25
0
ファイル: mbrFrm.cs プロジェクト: SariSultan/SDES
        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);
        }
コード例 #26
0
        /// <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)
                 ));
        }
コード例 #27
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #28
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #29
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #30
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #31
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #32
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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)));
        }
コード例 #33
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #34
0
        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);
        }
コード例 #35
0
        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);
        }
コード例 #36
0
ファイル: bug-415577.cs プロジェクト: Zman0169/mono
	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;
	}
コード例 #37
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #38
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #39
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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)));
        }
コード例 #40
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #41
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #42
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #43
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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)));
        }
コード例 #44
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #45
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #46
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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)));
        }
コード例 #47
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #48
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #49
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #50
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #51
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        public static void centroid() {
            var mbr = new Mbr(1, 2, 3, 4);

            Assert.Equal(new Point2(2, 3), mbr.GetCentroid());
        }
コード例 #52
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #53
0
        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;
            }
        }
コード例 #54
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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)));
        }
コード例 #55
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #56
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #57
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #58
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }
コード例 #59
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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);
        }
コード例 #60
0
ファイル: MbrFacts.cs プロジェクト: aarondandy/vertesaur
        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));
        }