]> gerrit.simantics Code Review - simantics/3d.git/blob - org.jcae.opencascade/src-java-test/org/jcae/opencascade/jni/Dimensions.java
Include old 64-bit versions of org.jcae.opencascade and vtk bundles
[simantics/3d.git] / org.jcae.opencascade / src-java-test / org / jcae / opencascade / jni / Dimensions.java
1 package org.jcae.opencascade.jni;
2
3 import static org.junit.Assert.*;
4 import org.junit.Test;
5
6 /**
7  * Example of BRepGProp and BRepBndLib
8  * @author Jerome Robert
9  */
10 public class Dimensions
11 {
12         @Test public void torus()
13         {
14                 // Create a shape for the example (a torus)
15                 double[] axis=new double[]{
16                         0,0,0,  // position
17                         0,0,1}; // direction
18                 double R = 3.0;
19                 double r = 1.0;
20                 TopoDS_Shape torus=new BRepPrimAPI_MakeTorus(axis, R, r).shape();
21
22                 // Compute the bounding box of the shape
23                 Bnd_Box bbox = new Bnd_Box();                   
24                 BRepBndLib.add(torus, bbox);                    
25                 double[] bboxValues = bbox.get();
26                 
27                 // Display the bounding box
28                 System.out.println("Xmin="+bboxValues[0]);
29                 System.out.println("Ymin="+bboxValues[1]);
30                 System.out.println("Zmin="+bboxValues[2]);
31                 System.out.println("Xmax="+bboxValues[3]);
32                 System.out.println("Ymax="+bboxValues[4]);
33                 System.out.println("Zmax="+bboxValues[5]);
34
35                 // Display various other properties
36                 GProp_GProps property=new GProp_GProps();
37                 BRepGProp.linearProperties(torus, property);
38                 System.out.println("length="+property.mass());
39                 assertEquals(property.mass(), 4.0*Math.PI*(R+2.0*r), 1.e-6);
40
41                 // If Eps is argument is absent, precision is quite poor
42                 BRepGProp.surfaceProperties(torus, property, 1.e-2);
43                 System.out.println("surface="+property.mass());
44                 assertEquals(property.mass(), 4.0*Math.PI*Math.PI*R*r, 1.e-6);
45
46                 BRepGProp.volumeProperties(torus, property);
47                 System.out.println("volume="+property.mass());
48                 assertEquals(property.mass(), 2.0*Math.PI*Math.PI*R*r*r, 1.e-6);
49
50         }
51 }