root/as3/FLARToolKit/trunk/src/org/libspark/flartoolkit/core/types/FLARIntSize.as

リビジョン 4718, 4.9 kB (コミッタ: rokubou, コミット時期: 4 日 前)

FLARToolKit v4 core

Line 
1 /*
2  * PROJECT: FLARToolKit
3  * --------------------------------------------------------------------------------
4  * This work is based on the FLARToolKit developed by
5  *   R.Iizuka (nyatla)
6  * http://nyatla.jp/nyatoolkit/
7  *
8  * The FLARToolKit is ActionScript 3.0 version ARToolkit class library.
9  * Copyright (C)2008 Saqoosha
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  *
24  * For further information please contact.
25  *      http://www.libspark.org/wiki/saqoosha/FLARToolKit
26  *      <saq(at)saqoosha.net>
27  *
28  */
29 package org.libspark.flartoolkit.core.types
30 {
31         import org.libspark.flartoolkit.core.*;
32         public class FLARIntSize
33         {
34                 public var h:int;
35                 public var w:int;
36                 /*      public function FLARIntSize()
37                  *      public function FLARIntSize(i_width:int,i_height:int)
38                  *      public function FLARIntSize(i_ref_object:FLARIntSize)
39                 */
40                 public function FLARIntSize(...args:Array)
41                 {
42                         switch(args.length) {
43                         case 0:
44                                 {//public function FLARIntSize()
45                                         this.w = 0;
46                                         this.h = 0;
47                                         return;
48                                 }
49                         case 1:
50                                 if(args[0] is FLARIntSize)
51                                 {
52                                        
53                                         {       //public function FLARIntSize(i_width:int,i_height:int)
54                                                 this.w=args[0].w;
55                                                 this.h = args[0].h;
56                                                 return;
57                                         }
58                                 }
59                                 break;
60                         case 2:
61                                 {       //public function FLARIntSize(i_ref_object:FLARIntSize)
62                                         this.w=int(args[0]);
63                                         this.h=int(args[1]);
64                                         return;
65                                 }
66                                 break;
67                         default:
68                                 break;
69                         }
70                         throw new FLARException();
71                 }
72                 public function setValue(i_w:int,i_h:int):void
73                 {
74                         this.w=i_w;
75                         this.h=i_h;
76                         return;
77                 }
78                 /**
79                  * サイズが同一であるかを確認する。
80                  *
81                  * @param i_width
82                  * @param i_height
83                  * @return
84                  * @throws FLARException
85                  */
86                 public function isEqualSize(i_width:int,i_height:int):Boolean
87                 {
88                         if (i_width == this.w && i_height == this.h) {
89                                 return true;
90                         }
91                         return false;
92                 }
93
94                 /**
95                  * サイズが同一であるかを確認する。
96                  *
97                  * @param i_width
98                  * @param i_height
99                  * @return
100                  * @throws FLARException
101                  */
102                 public function isEqualSize_2(i_size:FLARIntSize):Boolean
103                 {
104                         if (i_size.w == this.w && i_size.h == this.h) {
105                                 return true;
106                         }
107                         return false;
108                 }
109                 public function isInnerSize( i_x:int , i_y:int ):Boolean
110                 {
111                         return ( i_x <= this.w && i_y <= this.h ) ;
112                 }
113                
114                 public function isInnerSize_2( i_size:FLARIntSize ):Boolean
115                 {
116                         return ( i_size.w <= this.w && i_size.h <= this.h ) ;
117                 }
118                
119                 public function isInnerSize_3( i_point:FLARDoublePoint2d ):Boolean
120                 {
121                         return ( i_point.x < this.w && i_point.y < this.h && 0 <= i_point.x && 0 <= i_point.y ) ;
122                 }
123                
124                 public function isInnerPoint( i_x:int , i_y:int ):Boolean
125                 {
126                         return ( i_x < this.w && i_y < this.h && 0 <= i_x && 0 <= i_y ) ;
127                 }
128                
129                 public function isInnerPoint_2( i_pos:FLARDoublePoint2d ):Boolean
130                 {
131                         return ( i_pos.x < this.w && i_pos.y < this.h && 0 <= i_pos.x && 0 <= i_pos.y ) ;
132                 }
133                
134                 public function isInnerPoint_3( i_pos:FLARIntPoint2d ):Boolean
135                 {
136                         return ( i_pos.x < this.w && i_pos.y < this.h && 0 <= i_pos.x && 0 <= i_pos.y ) ;
137                 }
138                
139                 public function setAreaRect( i_vertex:Vector.<FLARDoublePoint2d>, i_num_of_vertex:int ):void
140                 {
141                         var xmax:int , xmin:int , ymax:int , ymin:int ;
142                         xmin = xmax = int(i_vertex[i_num_of_vertex - 1].x) ;
143                         ymin = ymax = int(i_vertex[i_num_of_vertex - 1].y) ;
144                         for ( var i:int = i_num_of_vertex - 2 ; i >= 0 ; i-- )
145                         {
146                                 if( i_vertex[i].x < xmin ) {
147                                         xmin = int(i_vertex[i].x) ;
148                                 }
149                                 else if( i_vertex[i].x > xmax ) {
150                                         xmax = int(i_vertex[i].x) ;
151                                 }
152                                
153                                 if( i_vertex[i].y < ymin ) {
154                                         ymin = int(i_vertex[i].y) ;
155                                 }
156                                 else if( i_vertex[i].y > ymax ) {
157                                         ymax = int(i_vertex[i].y) ;
158                                 }
159                                
160                         }
161                         this.h = ymax - ymin + 1 ;
162                         this.w = xmax - xmin + 1 ;
163                 }
164                
165                 public function setAreaRect_2( i_vertex:Vector.<FLARIntPoint2d>, i_num_of_vertex:int ):void
166                 {
167                         var xmax:int , xmin:int , ymax:int , ymin:int ;
168                         xmin = xmax = int(i_vertex[i_num_of_vertex - 1].x) ;
169                         ymin = ymax = int(i_vertex[i_num_of_vertex - 1].y) ;
170                         for( var i:int = i_num_of_vertex - 2 ; i >= 0 ; i-- ) {
171                                 if( i_vertex[i].x < xmin ) {
172                                         xmin = int(i_vertex[i].x) ;
173                                 }
174                                 else if( i_vertex[i].x > xmax ) {
175                                         xmax = int(i_vertex[i].x) ;
176                                 }
177                                
178                                 if( i_vertex[i].y < ymin ) {
179                                         ymin = int(i_vertex[i].y) ;
180                                 }
181                                 else if( i_vertex[i].y > ymax ) {
182                                         ymax = int(i_vertex[i].y) ;
183                                 }
184                                
185                         }
186                         this.h = ymax - ymin + 1 ;
187                         this.w = xmax - xmin + 1 ;
188                 }
189         }
190 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。