Project

General

Profile

Download (4.79 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / type / Static2D.java @ bff329fb

1 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 d333eb6b Leszek Koltunski
//                                                                                               //
6 46b572b5 Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 d333eb6b Leszek Koltunski
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11 46b572b5 Leszek Koltunski
// Distorted is distributed in the hope that it will be useful,                                  //
12 d333eb6b Leszek Koltunski
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17 46b572b5 Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 a4835695 Leszek Koltunski
package org.distorted.library.type;
21 6a06a912 Leszek Koltunski
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23
/**
24
 * A 2-dimensional data structure containing two floats. The floats have no particular meaning; 
25 cacc63de Leszek Koltunski
 * when this data structure is used in Dynamics, we can think of it as a 2-dimensional Point
26 568b29d8 Leszek Koltunski
 * a few of which the Dynamic interpolates between.
27 6a06a912 Leszek Koltunski
 */
28
29 a20f274f Leszek Koltunski
public class Static2D extends Static implements Data2D
30 6a06a912 Leszek Koltunski
  {
31 a20f274f Leszek Koltunski
  float x,y;
32 6a06a912 Leszek Koltunski
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
/**
35
 * Constructor that initialises the value of the two floats to (ox,oy).   
36
 *   
37
 * @param ox value of the first float.
38
 * @param oy value of the second float.
39
 */    
40 568b29d8 Leszek Koltunski
  public Static2D(float ox, float oy)
41 6a06a912 Leszek Koltunski
    {
42 a20f274f Leszek Koltunski
    super(2);
43
    x = ox;
44 6a06a912 Leszek Koltunski
    y = oy;
45
    }
46 a20f274f Leszek Koltunski
47 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
48 bff329fb Leszek Koltunski
/**
49
 * Copy constructor.
50
 */
51
  public Static2D(Static2D sta)
52
    {
53
    super(2);
54
    x = sta.x;
55
    y = sta.y;
56
    }
57
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59 6a06a912 Leszek Koltunski
/**
60
 * Reset the value of the floats to (ox,oy).
61
 * 
62
 * @param ox new value of the first float
63 a20f274f Leszek Koltunski
 * @param oy new value of the seond float
64 6a06a912 Leszek Koltunski
 */
65 a20f274f Leszek Koltunski
  public void set(float ox, float oy)
66 6a06a912 Leszek Koltunski
    {
67
    x = ox;
68
    y = oy;
69
    }
70
71 f211a191 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
72
/**
73
 * Copy a Static2D.
74
 */
75
  public void set(Static2D s)
76
    {
77
    x = s.x;
78
    y = s.y;
79
    }
80
81 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
82
/**
83 a20f274f Leszek Koltunski
 * Resets the value of the first float.
84
 *
85
 * @param ox new value of the first float.
86 6a06a912 Leszek Koltunski
 */
87 ece89b28 Leszek Koltunski
  public void set0(float ox)
88 6a06a912 Leszek Koltunski
    {
89
    x = ox;
90
    }
91
92 8df64ab9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
93
/**
94
 * Resets the value of the second float.
95
 *
96
 * @param oy new value of the second float.
97
 */
98 ece89b28 Leszek Koltunski
  public void set1(float oy)
99 8df64ab9 Leszek Koltunski
    {
100
    y = oy;
101
    }
102
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104
/**
105 a20f274f Leszek Koltunski
 * Return the value of the first float contained.
106 8df64ab9 Leszek Koltunski
 *
107 a20f274f Leszek Koltunski
 * @return The first float.
108 8df64ab9 Leszek Koltunski
 */
109 ece89b28 Leszek Koltunski
  public float get0()
110 8df64ab9 Leszek Koltunski
    {
111 a20f274f Leszek Koltunski
    return x;
112 8df64ab9 Leszek Koltunski
    }
113
114 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
115
/**
116
 * Return the value of the second float contained.
117
 * 
118
 * @return The second float.
119
 */
120 ece89b28 Leszek Koltunski
  public float get1()
121 6a06a912 Leszek Koltunski
    {
122
    return y;  
123
    }
124
125 a1d92a36 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
126
/**
127
 * 'Interpolation' between the single Point (i.e. always this very value) returned to the buffer.
128
 *
129
 * @param buffer Float buffer we will write the results to.
130
 * @param offset Offset in the buffer where to write the result.
131
 * @param time not used
132
 * @param step not used
133
 * @return <code>false</code>
134
 */
135
  public boolean get(float[] buffer, int offset, long time, long step)
136
    {
137
    buffer[offset  ] = x;
138
    buffer[offset+1] = y;
139
    return false;
140
    }
141 6a06a912 Leszek Koltunski
  }