예제 #1
0
파일: Rect.cs 프로젝트: liwq-net/liwq
 public Rect Union(Rect rect)
 {
     float minx = Math.Min(MinX, rect.MinX);
     float miny = Math.Min(MinY, rect.MinY);
     float maxx = Math.Max(MaxX, rect.MaxX);
     float maxy = Math.Max(MaxY, rect.MaxY);
     return new Rect(minx, miny, maxx - minx, maxy - miny);
 }
예제 #2
0
파일: Rect.cs 프로젝트: liwq-net/liwq
 public static bool Equal(ref Rect rect1, ref Rect rect2)
 {
     return rect1.Origin.Equals(rect2.Origin) && rect1.Size.Equals(rect2.Size);
 }
예제 #3
0
파일: Rect.cs 프로젝트: liwq-net/liwq
        public Rect Intersection(Rect rect)
        {
            if (IntersectsRect(rect) == false)
                return Zero;

            /*       +-------------+
             *       |             |
             *       |         +---+-----+
             * +-----+---+     |   |     |
             * |     |   |     |   |     |
             * |     |   |     +---+-----+
             * |     |   |         |
             * |     |   |         |
             * +-----+---+         |
             *       |             |
             *       +-------------+
             */
            float minx = 0, miny = 0, maxx = 0, maxy = 0;
            // X
            if (rect.MinX < this.MinX) minx = this.MinX;
            else if (rect.MinX < this.MaxX) minx = rect.MinX;
            if (rect.MaxX < this.MaxX) maxx = rect.MaxX;
            else if (rect.MaxX > this.MaxX) maxx = this.MaxX;

            //  Y
            if (rect.MinY < this.MinY) miny = this.MinY;
            else if (rect.MinY < this.MaxY) miny = rect.MinY;
            if (rect.MaxY < this.MaxY) maxy = rect.MaxY;
            else if (rect.MaxY > this.MaxY) maxy = this.MaxY;
            return new Rect(minx, miny, maxx - minx, maxy - miny);
        }
예제 #4
0
파일: Rect.cs 프로젝트: liwq-net/liwq
 public bool IntersectsRect(Rect rect)
 {
     return !(this.MaxX < rect.MinX || rect.MaxX < this.MinX || this.MaxY < rect.MinY || rect.MaxY < this.MinY);
 }
예제 #5
0
파일: Rect.cs 프로젝트: liwq-net/liwq
 public bool Equals(Rect rect)
 {
     return Origin.Equals(rect.Origin) && Size.Equals(rect.Size);
 }
예제 #6
0
파일: Sprite.cs 프로젝트: liwq-net/liwq
 public Sprite(string assetName, Rect? rect = null, bool isRotated = false, Size? unCropSize = null, Point? cropPosition = null)
 {
     this.Texture2D = Application.SharedApplication.Game.Content.Load<Texture2D>(assetName);
     this.initDefaultProperty(rect, isRotated, unCropSize, cropPosition);
 }
예제 #7
0
파일: Sprite.cs 프로젝트: liwq-net/liwq
 public Sprite(byte[] data, int width, int height, Rect? rect = null, bool isRotated = false, Size? unCropSize = null, Point? cropPosition = null)
 {
     this.Texture2D = new Texture2D(Application.SharedApplication.GraphicsDevice, width, height, false, SurfaceFormat.Color);
     this.Texture2D.SetData<byte>(data);
     this.initDefaultProperty(rect, isRotated, unCropSize, cropPosition);
 }
예제 #8
0
파일: Sprite.cs 프로젝트: liwq-net/liwq
 public Sprite(Texture2D texture2d, Rect? rect = null, bool isRotated = false, Size? unCropSize = null, Point? cropPosition = null)
 {
     this.Texture2D = texture2d;
     this.initDefaultProperty(rect, isRotated, unCropSize, cropPosition);
 }
예제 #9
0
파일: Sprite.cs 프로젝트: liwq-net/liwq
        private void initDefaultProperty(Rect? rect = null, bool isRotated = false, Size? unCropSize = null, Point? cropPosition = null)
        {
            this.Opacity = 1.0f;
            this.Color = Color.White;

            if (rect == null)
                this.SourceRectangle = new Rect(0, 0, this.Texture2D.Width, this.Texture2D.Height);
            else
                this.SourceRectangle = rect.Value;
            this.IsRotate = isRotated;
            if (unCropSize != null)
                this.UnCropSize = unCropSize.Value;
            if (cropPosition != null)
                this.CropPosition = cropPosition.Value;
        }