Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// 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
// Distorted is distributed in the hope that it will be useful,                                  //
12
// 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
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.library.type;
21

    
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23
/**
24
 * A 2-dimensional data structure containing two floats. The floats have no particular meaning; 
25
 * when this data structure is used in Dynamics, we can think of it as a 2-dimensional Point
26
 * a few of which the Dynamic interpolates between.
27
 */
28

    
29
public class Static2D extends Static implements Data2D
30
  {
31
  float x,y;
32

    
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
  public Static2D(float ox, float oy)
41
    {
42
    super(2);
43
    x = ox;
44
    y = oy;
45
    }
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
/**
49
 * Reset the value of the floats to (ox,oy).
50
 * 
51
 * @param ox new value of the first float
52
 * @param oy new value of the seond float
53
 */
54
  public void set(float ox, float oy)
55
    {
56
    x = ox;
57
    y = oy;
58
    }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
/**
62
 * Copy a Static2D.
63
 */
64
  public void set(Static2D s)
65
    {
66
    x = s.x;
67
    y = s.y;
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
/**
72
 * Resets the value of the first float.
73
 *
74
 * @param ox new value of the first float.
75
 */
76
  public void set0(float ox)
77
    {
78
    x = ox;
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
/**
83
 * Resets the value of the second float.
84
 *
85
 * @param oy new value of the second float.
86
 */
87
  public void set1(float oy)
88
    {
89
    y = oy;
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93
/**
94
 * Return the value of the first float contained.
95
 *
96
 * @return The first float.
97
 */
98
  public float get0()
99
    {
100
    return x;
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104
/**
105
 * Return the value of the second float contained.
106
 * 
107
 * @return The second float.
108
 */
109
  public float get1()
110
    {
111
    return y;  
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115
/**
116
 * 'Interpolation' between the single Point (i.e. always this very value) returned to the buffer.
117
 *
118
 * @param buffer Float buffer we will write the results to.
119
 * @param offset Offset in the buffer where to write the result.
120
 * @param time not used
121
 * @param step not used
122
 * @return <code>false</code>
123
 */
124
  public boolean get(float[] buffer, int offset, long time, long step)
125
    {
126
    buffer[offset  ] = x;
127
    buffer[offset+1] = y;
128
    return false;
129
    }
130
  }
(15-15/18)