2 * PROJECT: NyARToolkit
\r
3 * --------------------------------------------------------------------------------
\r
4 * This work is based on the original ARToolKit developed by
\r
7 * HITLab, University of Washington, Seattle
\r
8 * http://www.hitl.washington.edu/artoolkit/
\r
10 * The NyARToolkit is Java edition ARToolKit class library.
\r
11 * Copyright (C)2008-2009 Ryo Iizuka
\r
13 * This program is free software: you can redistribute it and/or modify
\r
14 * it under the terms of the GNU General Public License as published by
\r
15 * the Free Software Foundation, either version 3 of the License, or
\r
16 * (at your option) any later version.
\r
18 * This program is distributed in the hope that it will be useful,
\r
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 * GNU General Public License for more details.
\r
23 * You should have received a copy of the GNU General Public License
\r
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
26 * For further information please contact.
\r
27 * http://nyatla.jp/nyatoolkit/
\r
28 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
31 package jp.nyatla.nyartoolkit.core.types;
\r
34 * このクラスは、基点x,yと、幅、高さで矩形を定義します。
\r
36 public class NyARIntRect
\r
47 * この関数は、頂点集合を包括する矩形を計算して、インスタンスにセットします。
\r
50 * @param i_num_of_vertex
\r
53 public final void setAreaRect(NyARDoublePoint2d[] i_vertex,int i_num_of_vertex)
\r
56 int xmax,xmin,ymax,ymin;
\r
57 xmin=xmax=(int)i_vertex[i_num_of_vertex-1].x;
\r
58 ymin=ymax=(int)i_vertex[i_num_of_vertex-1].y;
\r
59 for(int i=i_num_of_vertex-2;i>=0;i--){
\r
60 if(i_vertex[i].x<xmin){
\r
61 xmin=(int)i_vertex[i].x;
\r
62 }else if(i_vertex[i].x>xmax){
\r
63 xmax=(int)i_vertex[i].x;
\r
65 if(i_vertex[i].y<ymin){
\r
66 ymin=(int)i_vertex[i].y;
\r
67 }else if(i_vertex[i].y>ymax){
\r
68 ymax=(int)i_vertex[i].y;
\r
77 * この関数は、頂点集合を包括する矩形を計算して、インスタンスにセットします。
\r
80 * @param i_num_of_vertex
\r
83 public final void setAreaRect(NyARIntPoint2d[] i_vertex,int i_num_of_vertex)
\r
86 int xmax,xmin,ymax,ymin;
\r
87 xmin=xmax=(int)i_vertex[i_num_of_vertex-1].x;
\r
88 ymin=ymax=(int)i_vertex[i_num_of_vertex-1].y;
\r
89 for(int i=i_num_of_vertex-2;i>=0;i--){
\r
90 if(i_vertex[i].x<xmin){
\r
91 xmin=(int)i_vertex[i].x;
\r
92 }else if(i_vertex[i].x>xmax){
\r
93 xmax=(int)i_vertex[i].x;
\r
95 if(i_vertex[i].y<ymin){
\r
96 ymin=(int)i_vertex[i].y;
\r
97 }else if(i_vertex[i].y>ymax){
\r
98 ymax=(int)i_vertex[i].y;
\r
101 this.h=ymax-ymin+1;
\r
103 this.w=xmax-xmin+1;
\r
108 * この関数は、矩形を領域内にクリップします。
\r
118 public final void clip(int i_left,int i_top,int i_right,int i_bottom)
\r
126 }else if(x>i_right){
\r
131 }else if(y>i_bottom){
\r
135 l=(r>i_right)?i_right-x:r-x;
\r
141 l=(b>i_bottom)?i_bottom-y:b-y;
\r
153 * この関数は、点が矩形の範囲内にあるか判定します。
\r
159 * 点が矩形の中にあれば、trueを返します。
\r
161 public final boolean isInnerPoint(int i_x,int i_y)
\r
166 return (0<=x && x<this.w && 0<=y && y<this.h);
\r
169 * この関数は、点が矩形の範囲内にあるか判定します。
\r
173 * 点が矩形の中にあれば、trueを返します。
\r
175 public final boolean isInnerPoint(NyARDoublePoint2d i_pos)
\r
177 int x=(int)i_pos.x-this.x;
\r
178 int y=(int)i_pos.y-this.y;
\r
179 return (0<=x && x<this.w && 0<=y && y<this.h);
\r
182 * この関数は、点が矩形の範囲内にあるか判定します。
\r
186 * 点が矩形の中にあれば、trueを返します。
\r
188 public final boolean isInnerPoint(NyARIntPoint2d i_pos)
\r
190 int x=i_pos.x-this.x;
\r
191 int y=i_pos.y-this.y;
\r
192 return (0<=x && x<this.w && 0<=y && y<this.h);
\r
195 * この関数は、引数の矩形が、この矩形内にあるか判定します。
\r
199 * 矩形が内側にあれば、trueを返します。
\r
201 public final boolean isInnerRect(NyARIntRect i_rect)
\r
203 assert(i_rect.w>=0 && i_rect.h>=0);
\r
204 int lx=i_rect.x-this.x;
\r
205 int ly=i_rect.y-this.y;
\r
206 int lw=lx+i_rect.w;
\r
207 int lh=ly+i_rect.h;
\r
208 return (0<=lx && lx<this.w && 0<=ly && ly<this.h && lw<=this.w && lh<=this.h);
\r
211 * この関数は、引数で定義される矩形が、この矩形内にあるか判定します。
\r
213 * 内側にあるか調べる矩形の左上座標(X)
\r
215 * 内側にあるか調べる矩形の左上座標(Y)
\r
221 * 矩形が内側にあれば、trueを返します。
\r
223 public final boolean isInnerRect(int i_x,int i_y,int i_w,int i_h)
\r
225 assert(i_w>=0 && i_h>=0);
\r
230 return (0<=lx && lx<this.w && 0<=ly && ly<this.h && lw<=this.w && lh<=this.h);
\r
233 * この関数は、2つの矩形の対角点同士の距離の二乗値を計算します。
\r
239 public final int sqDiagonalPointDiff(NyARIntRect i_rect2)
\r
243 w1=this.x-i_rect2.x;
\r
244 w2=this.y-i_rect2.y;
\r
246 w1+=this.w-i_rect2.w;
\r
247 w2+=this.h-i_rect2.h;
\r
252 * この関数は、矩形の対角距離の二乗距離を返します。
\r
256 public final int getDiagonalSqDist()
\r
260 return lh*lh+lw*lw;
\r
264 * この関数は、オブジェクトの値をインスタンスにセットします。
\r
266 * セットする値を格納したオブジェクト。
\r
268 public final void setValue(NyARIntRect i_source)
\r