JavaCAD
XModifier.java
Go to the documentation of this file.
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 package eu.mihosoft.vrl.v3d;
7 
8 // TODO: Auto-generated Javadoc
14 public class XModifier implements WeightFunction {
15 
17  private Bounds bounds;
18 
20  private double min = 0;
21 
23  private double max = 1.0;
24 
26  private double sPerUnit;
27 
29  private boolean centered;
30 
31 
35  public XModifier() {
36  }
37 
43  public XModifier(boolean centered) {
44  this.centered = centered;
45  }
46 
47  /* (non-Javadoc)
48  * @see eu.mihosoft.vrl.v3d.WeightFunction#eval(eu.mihosoft.vrl.v3d.Vector3d, eu.mihosoft.vrl.v3d.CSG)
49  */
50  @Override
51  public double eval(Vector3d pos, CSG csg) {
52 
53  if (bounds == null) {
54  this.bounds = csg.getBounds();
55  sPerUnit = (max - min) / (bounds.getMax().x - bounds.getMin().x);
56  }
57 
58  double s = sPerUnit * (pos.x - bounds.getMin().x);
59 
60  if (centered) {
61  s = s - (max - min)/2.0;
62 
63  s = Math.abs(s)*2;
64  }
65 
66  return s;
67  }
68 
69 }
static Vector3d x(double x)
Definition: Vector3d.java:474
double eval(Vector3d pos, CSG csg)
Definition: XModifier.java:51
XModifier(boolean centered)
Definition: XModifier.java:43