[Struct] Size
using System;
public struct Size {
public static readonly Size Empty = new Size();
private int width;
private int height;
public Size (Point pt) {
width = pt.X;
height = pt.Y;
}
public Size (int width, int height) {
this.width = width;
this.height = height;
}
public static implicit operator Size (Point p) {
return new Size(p.X, p.Y);
}
public static explicit operator Point (Size s) {
return new Point (s.Width, s.Height);
}
public static Size operator + (Size sz1, Size sz2) {
return Add(sz1, sz2);
}
public static Size operator - (Size sz1, Size sz2) {
return Subtract(sz1, sz2);
}
public static bool operator == (Size sz1, Size sz2) {
return sz1.Width == sz2.Width && sz1.Height == sz2.Height;
}
public static bool operator != (Size sz1, Size sz2) {
return !(sz1 == sz2);
}
public bool IsEmpty { get { return width == 0 && height == 0; } }
public int Width {
get { return width; }
set { width = value; }
}
public int Height {
get { return height; }
set { height = value; }
}
public static Size Add (Size sz1, Size sz2) {
return new Size(sz1.Width + sz2.Width, sz1.Height + sz2.Height);
}
public static Size Ceiling (Size value) {
return new Size((int)Math.Ceiling((double)value.Width), (int)Math.Ceiling((double)value.Height));
}
public static Size Subtract (Size sz1, Size sz2) {
return new Size(sz1.Width - sz2.Width, sz1.Height - sz2.Height);
}
public static Size Truncate (Size value) {
return new Size((int)value.Width, (int)value.Height);
}
public static Size Round (Size value) {
return new Size((int)Math.Round((double)value.Width), (int)Math.Round((double)value.Height));
}
public override bool Equals (object obj) {
if (!(obj is Size)) return false;
Size comp = (Size)obj;
return (comp.width == this.width) && (comp.height == this.height);
}
public override int GetHashCode () {
return width ^ height;
}
public override string ToString () {
return "{Width=" + width.ToString() + ", Height=" + height.ToString() + "}";
}
}
'Unity' 카테고리의 다른 글
[UnityUI] Text LetterSpacing (0) | 2016.08.08 |
---|---|
[UnityUI] Text Gradient (0) | 2016.08.08 |
그라데이션 배경 (Gradient Shader 활용) (0) | 2015.11.19 |
[Shader] 그라데이션 (Gradient) (0) | 2015.11.19 |
[Struct] Point (0) | 2015.11.07 |
[Shader] 텍스처 회전 (Texture Rotation) (0) | 2015.09.08 |
C# 리스트(List)를 이용해 만든 우선순위큐(PriorityQueue) (0) | 2015.07.23 |
리플렉션 응용 (C# Reflection) (0) | 2015.07.01 |
MonoBehaviour Lifecycle (0) | 2014.06.30 |
Android Local Notification Plugin (0) | 2013.04.23 |