Example #1
0
        public void Equals_Should_Return_True_For_Same_PointS()
        {
            var point1 = new PointS(1, 2);
            var point2 = new PointS(1, 2);

            Equals(point1, point2).Should().BeTrue();
        }
Example #2
0
        static void Main()
        {
            CircleS[] circArr = new CircleS[] { new CircleS(1, 1, 3), new CircleS(2, 3, 4),
                                                new CircleS(-1, -2, 3), new CircleS(4, 3, 1) };

            Console.WriteLine("Ключи и круги до сортировки:");
            // Массив ключей для сортировки по уменьшению удаленности
            // кругов от начала координат:
            PointS[] keys = new PointS[circArr.Length];
            PointS   p0   = new PointS(0, 0);

            for (int i = 0; i < circArr.Length; i++)
            {
                keys[i] = circArr[i].Center;
                Console.Write("distance[{0}]={1:g3}\t", i, keys[i].distance(p0));
                Console.WriteLine(circArr[i].ToString());
            }
            Array.Sort(keys, circArr);
            Console.WriteLine("Массив кругов после сортировки: ");
            foreach (CircleS cs in circArr)
            {
                Console.WriteLine(cs.ToString());
            }
            Console.WriteLine("Для выхода из программы нажмите ENTER.");
            Console.ReadLine();
        }
Example #3
0
        public void Equality_Operator_Should_Return_False_For_Different_PointS()
        {
            var point1 = new PointS(1, 2);
            var point2 = new PointS(3, 4);

            (point1 == point2).Should().BeFalse();
        }
Example #4
0
        public void Equals_Should_Return_False_For_Different_PointS_As_Object()
        {
            var point1 = new PointS(1, 2);
            var point2 = new PointS(2, 3);

            point1.Equals((object)point2).Should().BeFalse();
        }
Example #5
0
        public void Equality_Operator_Should_Return_True_For_Same_PointS()
        {
            var point1 = new PointS(1, 2);
            var point2 = new PointS(1, 2);

            (point1 == point2).Should().BeTrue();
        }
Example #6
0
        public void Add(Equation[] limits, Equation limit, PointS point, bool valid, List <int> path, Equation func)
        {
            Leaf temp = _root;

            foreach (var t in path)
            {
                if (t == 1)
                {
                    if (temp.Left == null)
                    {
                        temp.Left = new Leaf();
                    }
                    temp = temp.Left;
                }
                else
                {
                    if (temp.Right == null)
                    {
                        temp.Right = new Leaf();
                    }
                    temp = temp.Right;
                }
            }
            temp.Limits = limits;
            temp.New    = limit;
            temp.Point  = point;
            temp.Valid  = valid;
            temp.Path   = path;
            temp.Func   = func;
        }
Example #7
0
        protected void extendRoad(RoadBud bud, PointS p, int length, Direction dir)
        {
            if (length < 0 || !world.isInWorld(p.x, p.y))
            {
                return;
            }
            switch (dir)
            {
            case Direction.EAST:
                buildRoadE(bud.level, p.x, p.y, (short)length, bud);
                break;

            case Direction.WEST:
                buildRoadW(bud.level, p.x, p.y, (short)length, bud);
                break;

            case Direction.NORTH:
                buildRoadN(bud.level, p.x, p.y, (short)length, bud);
                break;

            case Direction.SOUTH:
                buildRoadS(bud.level, p.x, p.y, (short)length, bud);
                break;

            default:
                Debug.Assert(false);
                break;
            }
        }
Example #8
0
        static void Main()
        {
            MassPoint[] elements;
            int         N; // количество точек на плоскости
            Random      gen = new Random(0);

            do
            {
                Console.Write("Введите количество точек на плоскости: ");
            }while (!int.TryParse(Console.ReadLine(), out N) || N < 1);
            elements = new MassPoint[N];
            for (int i = 0; i < elements.Length; i++)
            {
                PointS ps = new PointS(gen.Next(-10, 11), gen.Next(-10, 11));
                elements[i] = new MassPoint(ps, gen.Next(1, 6));
                Console.WriteLine(elements[i].ToString());
            }
            SetOfMassPoint real;

            do
            {
                double R = 0;
                do
                {
                    Console.Write("Введите радиус множества: ");
                }while (!double.TryParse(Console.ReadLine(), out R) || R <= 1);
                real = new SetOfMassPoint(elements, new PointS(0, 0), R);
                Console.WriteLine(real.ToString());
                Console.WriteLine(real.MassCenter.ToString());
                Console.WriteLine("Для завершения работы нажмите Escape ");
            } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
        }
Example #9
0
        internal bool addBud(short x, short y, int level, Direction dir, int sleep)
        {
            // ignore if the road is already exist.
            PointS at = PointS.pointFrom(x, y, dir, 1);

            if (!world.isInWorld(at.x, at.y))
            {
                return(false);
            }
            Voxel toward = world[at.x, at.y];

            if (toward.road != null && toward.road.getLevel(dir) <= level)
            {
                return(false);
            }
            vector key = new vector(x, y, dir);

            if (buds.ContainsKey(key))
            {
                return(false);
            }
            RoadBud bud = new RoadBud(level, sleep);

            buds.Add(key, bud);
            Debug.WriteLine("new bud at:(" + x + "," + y + ") to " + dir);
            return(true);
        }
Example #10
0
        /// <summary>
        /// Writes a <see cref="PointS"/>.
        /// </summary>
        /// <param name="builder">The <see cref="IPacketBuilder">packet builder</see> to use.</param>
        /// <param name="vector">The <see cref="PointS"/> to write.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="builder"/> is <see langword="null"/>.</exception>
        /// <inheritdoc cref="PacketBuilder.WriteInt16(short)" select="exception[@cref='ObjectDisposedException']" />
        public static void WriteVector(this IPacketBuilder builder, PointS vector)
        {
            Guard.NotNull(() => builder, builder);

            builder.WriteInt16(vector.X);
            builder.WriteInt16(vector.Y);
        }
Example #11
0
 public Glyph(PointS[] points, GlyphFlag[] flags, byte[] instructions, ushort[] endPtsOfContours, BoundsS bounds)
 {
     Points = points;
     Flags = flags;
     Instructions = instructions;
     EndPtsOfContours = endPtsOfContours;
     Bounds = bounds;
 }
Example #12
0
        public void Binary_Plus_Operator_Should_Return_Correct_PointS()
        {
            var a = new PointS(-20, 20);
            var b = new PointS(20, -20);

            var c = a + b;

            c.Should().HaveComponents(0, 0);
        }
Example #13
0
        static void Main()
        {
            //string s1 = "Hello";
            //string s2 = "Hello";

            //Console.WriteLine(s1 == s2);

            PointR r1 = new PointR {
                X = 1, Y = 2, Z = 3
            };
            PointR r2 = new PointR {
                X = 1, Y = 2, Z = 3
            };

            PointS s1 = new PointS {
                X = 1, Y = 2, Z = 3
            };
            PointS s2 = new PointS {
                X = 1, Y = 2, Z = 3
            };

            PointC c1 = new PointC {
                X = 1, Y = 2, Z = 3
            };
            PointC c2 = new PointC {
                X = 1, Y = 2, Z = 3
            };

            //IEquatable<PointR> eq = r1;

            Console.WriteLine(r1 != r2);
            //Console.WriteLine(c1 == c2);
            //Console.WriteLine(s1 == s2);

            PointR r3 = r1 with {
                X = 27, Z = 200
            };

            Console.WriteLine(object.ReferenceEquals(r3, r1));

            Console.WriteLine(r1);
            Console.WriteLine(r3);

            PointR p4 = new Point4D {
                X = 1, Y = 2, Z = 3, CT = 4
            };

            Console.WriteLine(p4);

            // Decomposition only provided automatically for positional record
            //var (x, y, _) = r3;

            //Console.WriteLine(x);
            //Console.WriteLine(y);
        }
    }
Example #14
0
        public static IEnumerable <PointS> GetPointSs(MetafileReader reader, uint count)
        {
            var points = new PointS[count];

            for (uint i = 0; i < count; i++)
            {
                points[i] = new PointS(reader);
            }
            return(points);
        }
Example #15
0
        protected PointS adjustPoint2(PointS src, int level, Direction dir, ref int[] right, ref int[] left)
        {
            PointS p = src;

            // overlap to nearest lower level road (if exist)
            if (level < Configure.RoadLevelMax)
            {
                int start;
                if (dir == Direction.SOUTH || dir == Direction.NORTH)
                {
                    start = p.y;
                }
                else
                {
                    start = p.x;
                }
                int l  = min_length[Configure.RoadLevelMax];
                int dR = right[Configure.RoadLevelMax];
                int dL = left[Configure.RoadLevelMax];
                int sR = Math.Abs(dR - start);
                int sL = Math.Abs(dL - start);
                if (dR >= 0)
                {
                    if (dL >= 0)
                    {
                        if (sL < sR)
                        {
                            if (sL < l)
                            {
                                p = PointS.pointFrom(p, DirConvertor.rotL(dir), (short)(l - sL));
                            }
                        }
                        else
                        {
                            if (sR < l)
                            {
                                p = PointS.pointFrom(p, DirConvertor.rotR(dir), (short)(l - sR));
                            }
                        }
                    }
                    else if (sR < l)
                    {
                        p = PointS.pointFrom(p, DirConvertor.rotR(dir), (short)(l - sR));
                    }
                }
                else if (dL >= 0)
                {
                    if (sL < l)
                    {
                        p = PointS.pointFrom(p, DirConvertor.rotL(dir), (short)(l - sL));
                    }
                }
            }
            return(p);
        }
Example #16
0
 public Minutia(TemplateBuilder.Minutia builderMinutia)
 {
     Position  = new PointS(builderMinutia.Position);
     Direction = builderMinutia.Direction;
     if (builderMinutia.Type == TemplateBuilder.MinutiaType.Extremidade)
     {
         Type = MinutiaType.Ending;
     }
     else
     {
         Type = MinutiaType.Bifurcation;
     }
 }
Example #17
0
        public Chunk GetChunk(short x, short z)
        {
            PointS p = new PointS(x, z);

            if (!_chunks.ContainsKey(p))
            {
                return(null);
            }
            else
            {
                return(_chunks[p]);
            }
        }
Example #18
0
            public Minutia(TemplateBuilder.Minutia builderMinutia)
            {
                Position  = new PointS(builderMinutia.Position);
                Direction = builderMinutia.Direction;
                switch (builderMinutia.Type)
                {
                case TemplateBuilder.MinutiaType.Ending: Type = MinutiaType.Ending; break;

                case TemplateBuilder.MinutiaType.Bifurcation: Type = MinutiaType.Bifurcation; break;

                case TemplateBuilder.MinutiaType.Other: Type = MinutiaType.Other; break;

                default: throw new ApplicationException();
                }
            }
        /// <summary>
        /// Get points.
        /// </summary>
        /// <param name="amount"> Amount of points </param>
        /// <returns> List of points </returns>
        private static List <MassPoint> GetPoints(int amount)
        {
            Console.WriteLine();

            var massPoints = new List <MassPoint>(amount);

            for (var i = 0; i < amount; i++)
            {
                var point = new PointS(Rnd.Next(-10, 11), Rnd.Next(-10, 11));
                massPoints.Add(new MassPoint(point, Rnd.Next(1, 6)));
                PrintMessage(massPoints[i] + Environment.NewLine, ConsoleColor.Yellow);
            }

            return(massPoints);
        }
Example #20
0
File: Program.cs Project: aodlf/CS
        static void Main(string[] args)
        {
            PointS p1 = new PointS(1, 2);
            PointC p2 = new PointC(1, 2);
            PointS p3 = p1; // 값에 의한 복사
            PointC p4 = p2; // 참조에 의한 복사

            //Console.WriteLine("{0} {1}", p1.x, p1.y);
            //Console.WriteLine("{0} {1}", p2.x, p2.y);

            p3.x = 11;
            p4.x = 11;

            Console.WriteLine("{0} {1}", p1.x, p3.x);
            Console.WriteLine("{0} {1}", p2.x, p4.x);
        }
Example #21
0
    static void Main()
    {
        Point p = null;

        Console.WriteLine(p == null);   // true

        // But you cannot do this:
        // (runtime error)
        Console.WriteLine(p.X);

        // A value type cannot have a null value,
        // unless it's a nullable type.
        // These will fail:

        PointS p2 = null;
        int    x  = null;
    }
Example #22
0
        // retruns true if no road is extended.
        protected bool extend(vector key)
        {
            RoadBud bud = (RoadBud)buds[key];

            if (bud == null)
            {
                return(false);
            }
            // remove if the road is already exist.
            PointS at     = PointS.pointFrom(key.x, key.y, key.dir, 1);
            Voxel  toward = world[at.x, at.y];

            if (toward.road != null && toward.road.getLevel(key.dir) <= bud.level)
            {
                removeBud(key);
                return(true);
            }
            // sleep check
            bool f = bud.sleeping;

            if (f)
            {
                Debug.Write(".");
                bud.stepSleep();
            }
            else
            {
                removeBud(key);
                int    length = min_length[bud.level];
                PointS p      = adjustPoint(bud.level, key.x, key.y, length, key.dir);
                if (p == null || p.IsEmpty)
                {
                    return(true);
                }
                extendRoad(bud, p, length, key.dir);
                if (bud.level < Configure.noTrunkLevel)
                {
                    makeBranch(bud, p, length, key.dir);
                }
                Debug.WriteLine("extends from (" + p.x + "," + p.y + ") to " + key.dir + " by " + length + " voxels.");
            }
            return(f);
        }
        /// <summary>
        /// Get list of mass points.
        /// </summary>
        /// <param name="amount"> Amount of mass points </param>
        /// <returns> List of mass points </returns>
        private static List <MassPoint> GetMassPoints(int amount)
        {
            Console.WriteLine();

            var massPoints = new List <MassPoint>(amount);

            // Fill list.
            for (var i = 0; i < amount; i++)
            {
                var x     = GetDoubleFromInterval();
                var y     = GetDoubleFromInterval();
                var point = new PointS(x, y);
                var mass  = Rnd.Next(1, 6) * Rnd.NextDouble();

                massPoints.Add(new MassPoint(point, mass));
                PrintMessage(massPoints[i].ToString(), ConsoleColor.Magenta);
            }

            return(massPoints);
        }
Example #24
0
        public void Arrays_Struct_Test()
        {
            //Arrays
            var vowels = new char[5];

            vowels[0] = 'a';
            vowels[1] = 'e';
            vowels[2] = 'i';
            vowels[3] = 'o';
            vowels[4] = 'u';
            Check.That(vowels).HasSize(5).And.ContainsExactly('a', 'e', 'i', 'o', 'u');
            //Default values, values vs references
            var ps = new PointS[100];

            Check.That(ps[0].x).IsEqualTo(0);
            var pc = new PointC[100];

            Check.ThatCode(() =>
            {
                var a1 = pc[0].x;
            }).Throws <NullReferenceException>();
        }
Example #25
0
        internal bool addBud(RoadBud bud, short x, short y, Direction dir)
        {
            PointS at = PointS.pointFrom(x, y, dir, 1);

            if (!world.isInWorld(at.x, at.y))
            {
                return(false);
            }
            Voxel toward = world[at.x, at.y];

            if (toward.road != null && toward.road.getLevel(dir) <= bud.level)
            {
                return(false);
            }
            vector key = new vector(x, y, dir);

            if (buds.ContainsKey(key))
            {
                buds.Remove(key);
            }
            buds.Add(key, bud);
            Debug.WriteLine("new bud at:(" + x + "," + y + ") to " + dir);
            return(true);
        }
Example #26
0
        protected int[] getLastBranches(RoadBud bud, PointS p, Direction dir)
        {
            if (!bud.sprouted || bud.lastBranch == null)
            {
                short     w  = min_length[0];
                int       n  = w * 2;
                Direction r  = DirConvertor.reverse(dir);
                int[]     b0 = getNearestBranches(p, r, n);
                int[]     bR = getNearestBranches(PointS.pointFrom(p, DirConvertor.rotR(dir), w), r, n);
                int[]     bL = getNearestBranches(PointS.pointFrom(p, DirConvertor.rotL(dir), w), r, n);
                if (dir == Direction.WEST || dir == Direction.NORTH)
                {
                    for (int i = 0; i < b0.Length; i++)
                    {
                        if (bR[i] > b0[i])
                        {
                            b0[i] = bR[i];
                        }
                        if (bL[i] > b0[i])
                        {
                            b0[i] = bL[i];
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < b0.Length; i++)
                    {
                        if (bR[i] > 0 && bR[i] < b0[i])
                        {
                            b0[i] = bR[i];
                        }
                        if (bL[i] > 0 && bL[i] < b0[i])
                        {
                            b0[i] = bL[i];
                        }
                    }
                }
                bud.lastBranch = b0;
                bud.sprouted   = true;
            }
            // high level branch is substitutable for lower one
            int v;

            if (dir == Direction.WEST || dir == Direction.NORTH)
            {
                v = -1;
            }
            else
            {
                v = 1;
            }
            for (int i = 1; i <= Configure.RoadLevelMax; i++)
            {
                if (bud.lastBranch[i - 1] != -1)
                {
                    if (bud.lastBranch[i] == -1)
                    {
                        bud.lastBranch[i] = bud.lastBranch[i - 1];
                    }
                    else
                    if ((bud.lastBranch[i - 1] - bud.lastBranch[i]) * v > 0)
                    {
                        bud.lastBranch[i] = bud.lastBranch[i - 1];
                    }
                }
            }
            return(bud.lastBranch);
        }
Example #27
0
        protected void makeBranch(RoadBud bud, PointS p, int length, Direction dir)
        {
            int[] b     = getLastBranches(bud, p, dir);
            int   d_min = min_length[Configure.RoadLevelMax];

            // prepare arguments
            int start;

            if (dir == Direction.SOUTH || dir == Direction.NORTH)
            {
                start = p.y;
            }
            else
            {
                start = p.x;
            }
            int last = Math.Abs(b[Configure.RoadLevelMax] - start);

            int n = length / d_min + 1;

            // points proposed for branch
            short[] grid = new short[n];
            // set first point
            grid[0] = (short)world.randEx(0, 2);
            if (last < d_min)
            {
                grid[0] += (short)d_min;
            }
            // set followed points
            for (int i = 1; i < n; i++)
            {
                grid[i] = (short)(grid[i - 1] + d_min + world.randEx(0, 2));
            }

            // sleep count of the bud
            int[] counter = new int[n];

            for (int lv = bud.level; lv <= Configure.RoadLevelMax; lv++)
            {
                for (int i = 0; i < n; i++)
                {
                    counter[i] = -1;
                }
                last = Math.Abs(b[lv] - start);
                makeBranch2(lv, length, last, ref grid, ref counter);
                for (int i = 0; i < n; i++)
                {
                    if (counter[i] > -1)
                    {
                        PointS p2 = PointS.pointFrom(p, dir, grid[i]);
                        addBud(p2.x, p2.y, lv, DirConvertor.rotL(dir), counter[i]);
                        addBud(p2.x, p2.y, lv, DirConvertor.rotR(dir), counter[i]);
                        if (dir == Direction.EAST || dir == Direction.WEST)
                        {
                            bud.lastBranch[lv] = p2.x;
                        }
                        else
                        {
                            bud.lastBranch[lv] = p2.y;
                        }
                    }
                }
            }
        }
Example #28
0
        protected PointS adjustPoint(int level, short x, short y, int length, Direction dir)
        {
            PointS p = new PointS(x, y);
            short  start;

            if (dir == Direction.SOUTH || dir == Direction.NORTH)
            {
                start = y;
            }
            else
            {
                start = x;
            }

            int       l    = min_length[level];
            Direction dirR = DirConvertor.rotR(dir);
            Direction dirL = DirConvertor.rotL(dir);

            int[] bR = getNearestBranches(PointS.pointFrom(p, dirR, 1), dirR, l * 4 / 3);
            int[] bL = getNearestBranches(PointS.pointFrom(p, dirL, 1), dirL, l * 4 / 3);
            int   dR = bR[level];
            int   dL = bL[level];
            int   sR = Math.Abs(dR - start);
            int   sL = Math.Abs(dL - start);
            int   s  = Math.Abs(dR - dL);

            if (dR >= 0)
            {
                // too close branch on ether side
                if (dL >= 0 && s < l)
                {
                    Debug.WriteLine("bud canceled 0");
                    return(null);
                }
                // close branch on right side
                if (sR < l)
                {
                    // can shift left side?
                    if (sL - l > l - sR)
                    {
                        p = PointS.pointFrom(p, DirConvertor.rotL(dir), (short)(l - sR));
                        bR[Configure.RoadLevelMax] = -1;
                        return(adjustPoint2(p, level, dir, ref bR, ref bL));
                    }
                    else
                    {
                        Debug.WriteLine("bud canceled R");
                        return(null);
                    }
                }
            }
            if (dL >= 0)
            {
                // close branch on left side
                if (sL < l)
                {
                    // can shift right side?
                    if (sR - l > l - sL)
                    {
                        p = PointS.pointFrom(p, DirConvertor.rotL(dir), (short)(l - sL));
                        bL[Configure.RoadLevelMax] = -1;
                        return(adjustPoint2(p, level, dir, ref bR, ref bL));
                    }
                    else
                    {
                        Debug.WriteLine("bud canceled L");
                        return(null);
                    }
                }
            }
            return(adjustPoint2(p, level, dir, ref bR, ref bL));
        }
 // Constructor.
 public MassPoint(PointS coordinates, double mass) =>
 (Coordinates, Mass) = (coordinates, mass);
Example #30
0
        public void MinComponents_Should_Return_Correct_PointS()
        {
            var a = new PointS(-20, 30);
            var b = new PointS(20, -40);

            var c = PointS.MinComponents(a, b);

            c.Should().HaveComponents(-20, -40);
        }
Example #31
0
        public void Inequality_Operator_Should_Return_False_For_Same_PointS()
        {
            var point1 = new PointS(1, 2);
            var point2 = new PointS(1, 2);

            (point1 != point2).Should().BeFalse();
        }
Example #32
0
 public void GetHashCode_Should_Return_Same_Hash_For_Same_PointS()
 {
     var hash1 = new PointS(1, 2).GetHashCode();
     var hash2 = new PointS(1, 2).GetHashCode();
     hash1.Should().Be(hash2);
 }
Example #33
0
        public void Inequality_Operator_Should_Return_True_For_Different_PointS()
        {
            var point1 = new PointS(1, 2);
            var point2 = new PointS(2, 1);

            (point1 != point2).Should().BeTrue();
        }
Example #34
0
        protected int[] getNearestBranches(PointS p, Direction dir, int length)
        {
            int[] ret = new int[Configure.RoadLevelMax + 1];
            for (int i = 0; i < ret.Length; i++)
            {
                ret[i] = -1;
            }

            if (p.x < 0 || p.x >= world.xWidth)
            {
                return(ret);
            }
            if (p.y < 0 || p.y >= world.yWidth)
            {
                return(ret);
            }

            short vx = 0;
            short vy = 0;

            switch (dir)
            {
            case Direction.EAST:
                vx = +1;
                break;

            case Direction.WEST:
                vx = -1;
                break;

            case Direction.NORTH:
                vy = -1;
                break;

            case Direction.SOUTH:
                vy = +1;
                break;

            default:
                Debug.Assert(false);
                break;
            }
            // find flag: if all level branch found, becomes zero.
            int f = (1 << Configure.RoadLevelMax) - 1;
            // scanning range max.
            int       x    = p.x;
            int       y    = p.y;
            Direction dirL = DirConvertor.rotL(dir);
            Direction dirR = DirConvertor.rotR(dir);

            for (int i = 0; i < length; i++)
            {
                Road r = world[x, y].road;
                if (r != null)
                {
                    int lv = Math.Min(r.getLevel(dirR), r.getLevel(dirL));
                    if (lv <= Configure.RoadLevelMax && ret[lv] == -1)
                    {
                        // store x if dir is E or W otherwise store y.
                        ret[lv] = Math.Abs(x * vx + y * vy);
                        // reset flag
                        f ^= (1 << lv);
                        // all nearest branch found
                        if (f == 0)
                        {
                            break;
                        }
                    }
                }
                x += vx;
                y += vy;
                if (!world.isInWorld(x, y))
                {
                    break;
                }
            }
            return(ret);
        }
Example #35
0
 public PointS(PointS src)
 {
     this.x = src.x;
     this.y = src.y;
 }
Example #36
0
        static void Main(string[] args)
        {
            int n = 10;

            CircleS[] circleS = new CircleS[n];

            for (int i = 0; i < circleS.Length; i++)
            {
                circleS[i] = new CircleS(random.NextDouble() + random.Next(-10, 10),
                                         random.NextDouble() + random.Next(-10, 10),
                                         random.NextDouble() + random.Next(0, 10));
                Console.WriteLine(circleS[i].ToString());
            }
            Console.WriteLine();

            Array.Sort(circleS);

            foreach (CircleS a in circleS)
            {
                Console.WriteLine(a.ToString());
            }
            PointS center = new PointS(0, 0);

            Console.WriteLine();
            Array.Sort(circleS, (CircleS a, CircleS b) =>
            {
                if (a.Center.distance(center) > b.Center.distance(center))
                {
                    return(1);
                }
                if (a.Center.distance(center) < b.Center.distance(center))
                {
                    return(-1);
                }
                return(0);
            }
                       );

            foreach (CircleS a in circleS)
            {
                Console.WriteLine(a.ToString());
            }

            Array.Sort(circleS);
            Console.WriteLine();

            double[] keys = new double[n];

            for (int i = 0; i < keys.Length; i++)
            {
                keys[i] = circleS[i].Center.distance(center);
            }

            Array.Sort(keys, circleS);

            foreach (CircleS a in circleS)
            {
                Console.WriteLine(a.ToString() + " " + a.Center.distance(center));
            }

            Console.ReadKey();
        }
Example #37
0
        public void Unary_Minus_Operator_Should_Return_Correct_PointS()
        {
            var a = new PointS(20, -20);

            var b = -a;

            b.Should().HaveComponents(-20, 20);
        }
Example #38
0
        private Glyph ReadSimpleGlyph(BinaryReader reader, int numberOfContours, short xMin, short yMin, short xMax, short yMax)
        {
            var endPtsOfContours = new ushort[numberOfContours];
            for(int i = 0; i < numberOfContours; i++)
            {
                endPtsOfContours[i] = reader.ReadUInt16();
            }

            var instructionLength = reader.ReadUInt16();
            var instructions = reader.ReadBytes(instructionLength);

            var numberOfPoints = endPtsOfContours.Last() + 1;

            var flags = ReadGlyphFlags(reader, numberOfPoints);

            var xCoordinates = ReadGlyphCoordinates(reader, numberOfPoints, flags, GlyphFlag.XByte, GlyphFlag.XSignOrSame);
            var yCoordinates = ReadGlyphCoordinates(reader, numberOfPoints, flags, GlyphFlag.YByte, GlyphFlag.YSignOrSame);

            var points = new PointS[numberOfPoints];
            for(int i = 0; i < numberOfPoints; i++)
            {
                points[i] = new PointS(xCoordinates[i], yCoordinates[i]);
            }

            var bounds = new BoundsS(xMin, xMax, yMin, yMax);

            return new Glyph(points, flags, instructions, endPtsOfContours, bounds);
        }
Example #39
0
        public void Equals_Should_Return_False_For_Null_Object()
        {
            var point1 = new PointS(1, 2);

            point1.Equals(null).Should().BeFalse();
        }
Example #40
0
 public static PointS pointFrom(PointS p, Direction dir, short length)
 {
     return(pointFrom(p.x, p.y, dir, length));
 }
Example #41
0
        public void Unary_Minus_Operator_Should_Throw_On_MinValue()
        {
            var point = new PointS(short.MinValue, short.MinValue);

            point
                .Invoking(a => (-a).Whatever())
                .ShouldThrow<ArgumentException>();
        }
Example #42
0
        public void Equals_Should_Return_True_For_Same_PointS_As_Object()
        {
            var point1 = new PointS(1, 2);
            var point2 = new PointS(1, 2);

            point1.Equals((object)point2).Should().BeTrue();
        }
Example #43
0
 // Constructor.
 public MassPoint(PointS point, double mass)
 {
     Center = point;
     Mass   = mass;
 }
Example #44
0
 public static double Distance(PointS firstPoint, PointS secondPoint) =>
 Math.Sqrt(Math.Pow(firstPoint.X - secondPoint.X, 2) + Math.Pow(firstPoint.Y - secondPoint.Y, 2));
Example #45
0
 public static PointSAssertions Should(this PointS subject)
 {
     return(new PointSAssertions(subject));
 }