SizeInt.cs :  » Game » SokoSolve-Sokoban » SokoSolve » Common » Math » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » SokoSolve Sokoban 
SokoSolve Sokoban » SokoSolve » Common » Math » SizeInt.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;

namespace SokoSolve.Common.Math{
  public struct SizeInt
    {

        #region SizeInt
        
        public SizeInt(int x, int y)
        {
            this.x = x;
            this.y = y;
        }

        public SizeInt(VectorInt copy): this(copy.X, copy.Y )
        {
            
        }

        public SizeInt(SizeInt copy) : this(copy.X, copy.Y)
        {

        }

        public SizeInt(System.Drawing.Size FromDrawing) : this(FromDrawing.Width, FromDrawing.Height)
        {
        }

    public int Width
    {
      get { return x;  }
      set { x = value; }
    }

    public int Height
    {
      get { return y; }
      set { y = value; }
        }

      public VectorInt ToVectorInt
      {
          get { return new VectorInt(x, y);}
      }

        #endregion SizeInt

        #region Vector

        public  static readonly SizeInt Zero = new SizeInt(0, 0);
        public  static readonly SizeInt Null = new SizeInt(0, 0);
        private int x;
        private int y;

      

        public int X
        {
            get { return x; }
            set { x = value; }
        }

        public int Y
        {
            get { return y; }
            set { y = value; }
        }


        public static SizeInt MinValue
        {
            get { return new SizeInt(int.MinValue, int.MinValue); }
        }

        

        public VectorInt Add(VectorInt value)
        {
            return new VectorInt(x + value.X, y + value.Y);
        }

        public VectorInt Subtract(VectorInt value)
        {
            return new VectorInt(x - value.X, y - value.Y);
        }

        public VectorInt Multiply(VectorInt value)
        {
            return new VectorInt(x*value.X, y*value.Y);
        }

        public VectorInt Divide(VectorInt value)
        {
            return new VectorInt(x/value.X, y/value.Y);
        }

        public VectorInt Add(int aX, int aY)
        {
            return new VectorInt(x + aX, y + aY);
        }

        public VectorInt Subtract(int aX, int aY)
        {
            return new VectorInt(x - aX, y - aY);
        }

        public VectorInt Multiply(int aX, int aY)
        {
            return new VectorInt(x*aX, y*aY);
        }

        public VectorInt Divide(int aX, int aY)
        {
            return new VectorInt(x/aX, y/aY);
        }



        public override bool Equals(object obj)
        {
            if (object.ReferenceEquals(obj, null))
            {
                return IsNull;
            }

            if (obj is VectorInt)
            {
                VectorInt rhs = (VectorInt)obj;
                return x == rhs.X && y == rhs.Y;
            }

            if (obj is SizeInt)
            {
                SizeInt rhs = (SizeInt)obj;
                return x == rhs.X && y == rhs.Y;
            }
            return false;
        }

        public bool IsNull
        {
            get { return x == int.MinValue && y == int.MinValue; }
        }

        public static SizeInt Min(SizeInt A, SizeInt B)
        {
            return new SizeInt(System.Math.Min(A.X, B.X), System.Math.Min(A.Y, B.Y));
        }

        public static SizeInt Max(SizeInt A, SizeInt B)
        {
            return new SizeInt(System.Math.Max(A.X, B.X), System.Math.Max(A.Y, B.Y));
        }

        public override int GetHashCode()
        {
            return x.GetHashCode() ^ y.GetHashCode();
        }

        public override string ToString()
        {
            return string.Format("{0}x{1}", x, y);
        }

        public VectorDouble ToVectorDouble()
        {
            return new VectorDouble((double) X, (double) Y);
        }

        /// <summary>
        /// Convert to a Drawing position
        /// </summary>
        /// <returns></returns>
        public System.Drawing.Point ToPoint()
        {
            return new Point(x, y);
        }

        /// <summary>
        /// Convert to a Drawing position
        /// </summary>
        /// <returns></returns>
        public System.Drawing.PointF ToPointF()
        {
            return new PointF(x, y);
        }

        public VectorInt Offset(Direction dir)
        {
            switch (dir)
            {
                case (Direction.Up):
                    return this.Add(0, -1);
                case (Direction.Down):
                    return this.Add(0, 1);
                case (Direction.Left):
                    return this.Add(-1, 0);
                case (Direction.Right):
                    return this.Add(1, 0);
            }
            throw new InvalidOperationException();
        }


        /// <summary>
        /// Geint FOUR offsets (Up, Down, Left, Right) as an array
        /// </summary>
        /// <returns></returns>
        public VectorInt[] OffsetDirections()
        {
            return new VectorInt[]
                {
                    Offset(Direction.Up),
                    Offset(Direction.Down),
                    Offset(Direction.Left),
                    Offset(Direction.Right)
                };
        }

        #endregion Vector
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.