コード例 #1
0
ファイル: PixelMapTests.cs プロジェクト: sahwar/DjvuNet
        public static IPixelMap CreateInitVerifyPixelMap(int width, int height, IPixel color)
        {
            IPixelMap map = CreateVerifyPixelMap();

            map.Init(height, width, color);
            Assert.Equal(width, map.Width);
            Assert.Equal(height, map.Height);
            Assert.Equal <IPixel>(color, map.CreateGPixelReference(width / 2).ToPixel());

            var pix = map.CreateGPixelReference(width / 2);

            Assert.True(color.Equals(pix.ToPixel()));
            return(map);
        }
コード例 #2
0
ファイル: Circle.cs プロジェクト: lanicon/Styx
        /// <summary>
        /// Checks if the given first pixel is within the circle
        /// defined by the remaining three edge pixels.
        /// </summary>
        /// <param name="Pixel">The pixel to be checked.</param>
        /// <param name="EdgePixel1">The first edge pixel defining a circle.</param>
        /// <param name="EdgePixel2">The second edge pixel defining a circle.</param>
        /// <param name="EdgePixel3">The third edge pixel defining a circle.</param>
        public static Boolean IsInCircle(IPixel <T> Pixel, IPixel <T> EdgePixel1, IPixel <T> EdgePixel2, IPixel <T> EdgePixel3)
        {
            #region Initial Checks

            if (Pixel == null)
            {
                throw new ArgumentNullException("The given first pixel must not be null!");
            }

            if (EdgePixel1 == null)
            {
                throw new ArgumentNullException("The given first edgepixel must not be null!");
            }

            if (EdgePixel2 == null)
            {
                throw new ArgumentNullException("The given second edgepixel must not be null!");
            }

            if (EdgePixel3 == null)
            {
                throw new ArgumentNullException("The given third edgepixel must not be null!");
            }

            #endregion

            var Math = MathsFactory <T> .Instance;

            #region Math Checks

            if (EdgePixel1.Equals(EdgePixel2) ||
                EdgePixel1.Equals(EdgePixel3) ||
                EdgePixel2.Equals(EdgePixel3))
            {
                throw new ArgumentException("All distances between the pixels must be larger than zero!");
            }

            if (EdgePixel1.X.Equals(EdgePixel2.X) &&
                EdgePixel2.X.Equals(EdgePixel3.X))
            {
                throw new ArgumentException("All three pixels must not be on a single line!");
            }

            if (EdgePixel1.Y.Equals(EdgePixel2.Y) &&
                EdgePixel2.Y.Equals(EdgePixel3.Y))
            {
                throw new ArgumentException("All three pixels must not be on a single line!");
            }

            #endregion

            var _Line12 = new Line2D <T>(EdgePixel1, EdgePixel2);
            var _Line23 = new Line2D <T>(EdgePixel2, EdgePixel3);

            var _Normale12 = _Line12.Normale;
            var _Normale23 = _Line23.Normale;

            var Center = new Line2D <T>(_Line12.Center, _Normale12.X, _Normale12.Y).
                         Intersection(
                new Line2D <T>(_Line23.Center, _Normale23.X, _Normale23.Y));

            return(Center.DistanceTo(Pixel).
                   IsLessThanOrEquals(
                       Center.DistanceTo(EdgePixel1)));
        }
コード例 #3
0
ファイル: Circle.cs プロジェクト: lanicon/Styx
        /// <summary>
        /// Creates a circumcircle of type T based on three pixels.
        /// </summary>
        /// <param name="Pixel1">The first pixel of the triangle.</param>
        /// <param name="Pixel2">The second pixel of the triangle.</param>
        /// <param name="Pixel3">The third pixel of the triangle.</param>
        public Circle(IPixel <T> Pixel1, IPixel <T> Pixel2, IPixel <T> Pixel3)
        {
            #region Initial Checks

            if (Pixel1 == null)
            {
                throw new ArgumentNullException("The given first pixel must not be null!");
            }

            if (Pixel2 == null)
            {
                throw new ArgumentNullException("The given second pixel must not be null!");
            }

            if (Pixel3 == null)
            {
                throw new ArgumentNullException("The given third pixel must not be null!");
            }

            #endregion

            this.Math = MathsFactory <T> .Instance;

            #region Math Checks

            if (Pixel1.Equals(Pixel2) ||
                Pixel1.Equals(Pixel3) ||
                Pixel2.Equals(Pixel3))
            {
                throw new ArgumentException("All distances between the pixels must be larger than zero!");
            }

            //if (Pixel1.X.Equals(Pixel2.X) &&
            //    Pixel2.X.Equals(Pixel3.X))
            //    throw new ArgumentException("All three pixels must not be on a single line!");

            //if (Pixel1.Y.Equals(Pixel2.Y) &&
            //    Pixel2.Y.Equals(Pixel3.Y))
            //    throw new ArgumentException("All three pixels must not be on a single line!");

            #endregion

            var _Line12 = new Line2D <T>(Pixel1, Pixel2);
            var _Line23 = new Line2D <T>(Pixel2, Pixel3);

            var _Normale12 = _Line12.Normale;
            var _Normale23 = _Line23.Normale;

            Center = new Line2D <T>(_Line12.Center, _Normale12.X, _Normale12.Y).
                     Intersection(
                new Line2D <T>(_Line23.Center, _Normale23.X, _Normale23.Y));

            if (Center != null)
            {
                X      = Center.X;
                Y      = Center.Y;
                Radius = Pixel1.DistanceTo(X, Y);
            }
            else
            {
                X      = default(T);
                Y      = default(T);
                Radius = default(T);
            }
        }
コード例 #4
0
        /// <summary>
        /// Create a triangle of type T.
        /// </summary>
        /// <param name="Pixel1">The first pixel of the triangle.</param>
        /// <param name="Pixel2">The second pixel of the triangle.</param>
        /// <param name="Pixel3">The third pixel of the triangle.</param>
        public Triangle(IPixel <T> Pixel1, IPixel <T> Pixel2, IPixel <T> Pixel3)
        {
            #region Initial Checks

            if (Pixel1 == null)
            {
                throw new ArgumentNullException("The given first pixel must not be null!");
            }

            if (Pixel2 == null)
            {
                throw new ArgumentNullException("The given second pixel must not be null!");
            }

            if (Pixel3 == null)
            {
                throw new ArgumentNullException("The given third pixel must not be null!");
            }

            #endregion

            this.Math = MathsFactory <T> .Instance;

            #region Math Checks

            if (Pixel1.Equals(Pixel2) ||
                Pixel1.Equals(Pixel3) ||
                Pixel2.Equals(Pixel3))
            {
                throw new ArgumentException("All distances between the pixels must be larger than zero!");
            }

            if (Pixel1.X.Equals(Pixel2.X) &&
                Pixel2.X.Equals(Pixel3.X))
            {
                throw new ArgumentException("All three pixels must not be on a single line!");
            }

            if (Pixel1.Y.Equals(Pixel2.Y) &&
                Pixel2.Y.Equals(Pixel3.Y))
            {
                throw new ArgumentException("All three pixels must not be on a single line!");
            }

            #endregion

            #region Sort Pixels

            // Sort by x-coordinate.
            while (true)
            {
                if (Pixel1.X.IsLargerThan(Pixel2.X))
                {
                    Pixel <T> .Swap(ref Pixel1, ref Pixel2);

                    continue;
                }

                if (Pixel1.X.IsLargerThan(Pixel3.X))
                {
                    Pixel <T> .Swap(ref Pixel1, ref Pixel3);

                    continue;
                }

                if (Pixel2.X.IsLargerThan(Pixel3.X))
                {
                    Pixel <T> .Swap(ref Pixel2, ref Pixel3);

                    continue;
                }

                break;
            }

            // Sort by y-coordinate if x-coordinates are the same
            if (Pixel1.X.Equals(Pixel2.X))
            {
                if (Pixel1.Y.IsLargerThan(Pixel2.Y))
                {
                    Pixel <T> .Swap(ref Pixel1, ref Pixel2);
                }
            }

            if (Pixel2.X.Equals(Pixel3.X))
            {
                if (Pixel2.Y.IsLargerThan(Pixel3.Y))
                {
                    Pixel <T> .Swap(ref Pixel1, ref Pixel2);
                }
            }

            #endregion

            this.P1 = Pixel1;
            this.P2 = Pixel2;
            this.P3 = Pixel3;
        }