Skip to content

Instantly share code, notes, and snippets.

@yohm
Created April 27, 2015 05:22
Show Gist options
  • Save yohm/5dd4c79d7b7868539c28 to your computer and use it in GitHub Desktop.
Save yohm/5dd4c79d7b7868539c28 to your computer and use it in GitHub Desktop.
A sample of Region of x10
import x10.regionarray.Region;
class Region01 {
private static def p( o: Any ) {
Console.OUT.println( o );
}
public static def main( args: Rail[String] ) {
val r1 = Region.make( 1..10 );
p( r1 );
val r2 = Region.make( 1, 10 );
p( r2 );
val r3 = Region.make( [1..5, 2..10] );
p( r3 );
val r4 = Region.make( [1..5, 2..10, 3..4, 4..8] );
p( r4 );
val empty = Region.makeEmpty( 3 );
p( empty ); // empty(3) : 3d empty region
val full = Region.makeFull( 2 );
p( full ); // full(2) : 2d full region
val unit = Region.makeUnit();
p( unit ); // full(0)
val rect = Region.makeRectangular( 1..2, 3..4 );
p( rect ); // equivalent to Region.make( [1..2, 3..4] )
val rectpoly = Region.makeRectangularPoly( [1,2], [3,4] );
p( rectpoly ); // (1,2), (3,4) を頂点とする四角形の領域
val diag = Region.makeBanded( 10 );
p( diag ); // [0,0], [1,1], ... [9,9]
val banded = Region.makeBanded( 5, 2, 3 );
p( banded ); // (x0>=0 && x0-x1>=-1 && x1>=0 && x1<=4 && x0-x1<=2 && x0<=4)
val tri = Region.makeUpperTriangular( 5 );
p( tri ); // (x0>=0 && x1<=4 && x0-x1<=0) 2次元の上三角領域
val bbox = Region.makeBanded( 10 ).boundingBox(); // [0..9, 0..9]
p( Region.make( 1..10 ).contains( 11 ) ); // false
p( Region.make( [1..5, 2..8] ).contains( Point.make( 3,5 ) ) ); // true
p( Region.make( [1..5, 2..8] ).contains( Region.make( [1..5,3..4] ) ) ); // true
p( Region.make( [1..5, 2..8] ).contains( Region.make( [-1..2,0..3] ) ) ); // false
p( Region.make( [1..5, 2..8] ).disjoint( Region.make( [6..7,-1..1] ) ) ); // true
p( Region.make( [1..5, 2..8] ).disjoint( Region.make( [-1..2,0..3] ) ) ); // false
p( Region.make( [1..3, 2..4, 3..5] ).eliminate( 0 ) ); // [2..4,3..5] 最初の次元を除いた領域(y-z平面へのprojection)を返す
p( Region.make( [1..3, 2..4, 3..5] ).projection( 0 ) ); // [1..3] x軸へのprojectionを返す
// indexOf
p( Region.makeRectangular( 0..2, 0..2).indexOf( Point.make(1,0) ) ); // 3 [0,0],[0,1],[0,2],[1,0],[1,1]...という順番でiterateされるときのインデックス
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment