-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBBox.cs
68 lines (60 loc) · 1.6 KB
/
BBox.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace OpenSim.ApplicationPlugins.MapDataAdapter
{
public class BBox
{
public int MinX, MinY, MaxX, MaxY;
public BBox()
{
MinX = 0;
MinY = 0;
MaxX = 0;
MaxY = 0;
}
public BBox(int minX, int minY, int maxX, int maxY)
{
MinX = minX;
MinY = minY;
MaxX = maxX;
MaxY = maxY;
}
public BBox(string boxStr)
{
string[] boxParams = boxStr.Split(',');
MinX = (int)float.Parse(boxParams[0]);
MinY = (int)float.Parse(boxParams[1]);
MaxX = (int)float.Parse(boxParams[2]);
MaxY = (int)float.Parse(boxParams[3]);
}
public void Extends(int x, int y)
{
if (x < MinX) MinX = x;
if (x > MaxX) MaxX = x;
if (y < MinY) MinY = y;
if (y > MaxY) MaxY = y;
}
public void Extends(BBox bbox)
{
MinX = Math.Min(MinX, bbox.MinX);
MinY = Math.Min(MinY, bbox.MinY);
MaxX = Math.Max(MaxX, bbox.MaxX);
MaxY = Math.Max(MaxY, bbox.MaxY);
}
public int Width
{
get { return MaxX - MinX; }
}
public int Height
{
get { return MaxY - MinY; }
}
public Rectangle ToRectangle()
{
Rectangle rect = new Rectangle(MinX, MinY, Width - 1, Height - 1);
return rect;
}
}
}