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
33 import jp.nyatla.nyartoolkit.NyARException;
\r
36 * このクラスは、整数型の距離値を格納します。
\r
39 public class NyARIntSize
\r
47 * 初期値を格納したインスタンスを生成します。
\r
49 public NyARIntSize()
\r
57 * @param i_ref_object
\r
58 * 引数値で初期化したインスタンスを生成します。
\r
60 public NyARIntSize(NyARIntSize i_ref_object)
\r
62 this.w=i_ref_object.w;
\r
63 this.h=i_ref_object.h;
\r
73 public NyARIntSize(int i_width,int i_height)
\r
80 * この関数は、引数値をインスタンスにセットします。
\r
86 public final void setValue(int i_w,int i_h)
\r
93 * この関数は、サイズが引数値と同一であるかを確認します。
\r
99 * サイズが引数値と同じなら、trueを返します。
\r
100 * @throws NyARException
\r
102 public final boolean isEqualSize(int i_width, int i_height)
\r
104 if (i_width == this.w && i_height == this.h) {
\r
111 * この関数は、サイズが引数値と同一であるかを確認します。
\r
115 * サイズが引数値と同じなら、trueを返します。
\r
116 * @throws NyARException
\r
118 public final boolean isEqualSize(NyARIntSize i_size)
\r
120 if (i_size.w == this.w && i_size.h == this.h) {
\r
126 * この関数は、引数値がインスタンスのサイズよりも小さいかを返します。
\r
132 * 引数値がインスタンスのサイズよりも小さければ、trueを返します。
\r
133 * @throws NyARException
\r
135 public final boolean isInnerSize(int i_x,int i_y)
\r
137 return (i_x<=this.w && i_y<=this.h);
\r
140 * この関数は、引数値がインスタンスのサイズよりも小さいかを返します。
\r
144 * 引数値がインスタンスのサイズよりも小さければ、trueを返します。
\r
145 * @throws NyARException
\r
147 public final boolean isInnerSize(NyARIntSize i_size)
\r
149 return (i_size.w<=this.w && i_size.h<=this.h);
\r
152 * この関数は、座標がサイズの範囲内(0,0基点)よりも小さいかを返します。
\r
156 * 引数値が範囲内ならば、trueを返します。
\r
157 * @throws NyARException
\r
159 public final boolean isInnerSize(NyARDoublePoint2d i_point)
\r
161 return (i_point.x<this.w && i_point.y<this.h && 0<=i_point.x && 0<=i_point.y);
\r
164 * この関数は、座標がサイズの範囲内(0,0-w,hの矩形)にあるかを返します。
\r
170 * 引数値が範囲内ならば、trueを返します。
\r
171 * @throws NyARException
\r
173 public final boolean isInnerPoint(int i_x,int i_y)
\r
175 return (i_x<this.w && i_y<this.h && 0<=i_x && 0<=i_y);
\r
178 * この関数は、座標がサイズの範囲内(0,0-w,hの矩形)にあるかを返します。
\r
182 * 引数値が範囲内ならば、trueを返します。
\r
183 * @throws NyARException
\r
185 public final boolean isInnerPoint(NyARDoublePoint2d i_pos)
\r
187 return (i_pos.x<this.w && i_pos.y<this.h && 0<=i_pos.x && 0<=i_pos.y);
\r
190 * この関数は、座標がサイズの範囲内(0,0-w,hの矩形)にあるかを返します。
\r
194 * 引数値が範囲内ならば、trueを返します。
\r
195 * @throws NyARException
\r
197 public final boolean isInnerPoint(NyARIntPoint2d i_pos)
\r
199 return (i_pos.x<this.w && i_pos.y<this.h && 0<=i_pos.x && 0<=i_pos.y);
\r
202 * この関数は、頂点集合を包括する矩形のサイズ値(幅、高さ)を計算して、インスタンスにセットします。
\r
205 * @param i_num_of_vertex
\r
208 public final void setAreaRect(NyARDoublePoint2d[] i_vertex,int i_num_of_vertex)
\r
211 int xmax,xmin,ymax,ymin;
\r
212 xmin=xmax=(int)i_vertex[i_num_of_vertex-1].x;
\r
213 ymin=ymax=(int)i_vertex[i_num_of_vertex-1].y;
\r
214 for(int i=i_num_of_vertex-2;i>=0;i--){
\r
215 if(i_vertex[i].x<xmin){
\r
216 xmin=(int)i_vertex[i].x;
\r
217 }else if(i_vertex[i].x>xmax){
\r
218 xmax=(int)i_vertex[i].x;
\r
220 if(i_vertex[i].y<ymin){
\r
221 ymin=(int)i_vertex[i].y;
\r
222 }else if(i_vertex[i].y>ymax){
\r
223 ymax=(int)i_vertex[i].y;
\r
226 this.h=ymax-ymin+1;
\r
227 this.w=xmax-xmin+1;
\r
230 * この関数は、頂点集合を包括する矩形のサイズ値(幅、高さ)を計算して、インスタンスにセットします。
\r
233 * @param i_num_of_vertex
\r
236 public final void setAreaRect(NyARIntPoint2d[] i_vertex,int i_num_of_vertex)
\r
239 int xmax,xmin,ymax,ymin;
\r
240 xmin=xmax=(int)i_vertex[i_num_of_vertex-1].x;
\r
241 ymin=ymax=(int)i_vertex[i_num_of_vertex-1].y;
\r
242 for(int i=i_num_of_vertex-2;i>=0;i--){
\r
243 if(i_vertex[i].x<xmin){
\r
244 xmin=(int)i_vertex[i].x;
\r
245 }else if(i_vertex[i].x>xmax){
\r
246 xmax=(int)i_vertex[i].x;
\r
248 if(i_vertex[i].y<ymin){
\r
249 ymin=(int)i_vertex[i].y;
\r
250 }else if(i_vertex[i].y>ymax){
\r
251 ymax=(int)i_vertex[i].y;
\r
254 this.h=ymax-ymin+1;
\r
255 this.w=xmax-xmin+1;
\r