Project

General

Profile

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

library / src / main / java / org / distorted / library / type / Static2D.java @ 8c57d77b

1
////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski  leszek@koltunski.pl                                          //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// This library is free software; you can redistribute it and/or                                 //
7
// modify it under the terms of the GNU Lesser General Public                                    //
8
// License as published by the Free Software Foundation; either                                  //
9
// version 2.1 of the License, or (at your option) any later version.                            //
10
//                                                                                               //
11
// This library 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 GNU                             //
14
// Lesser General Public License for more details.                                               //
15
//                                                                                               //
16
// You should have received a copy of the GNU Lesser General Public                              //
17
// License along with this library; if not, write to the Free Software                           //
18
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20

    
21
package org.distorted.library.type;
22

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

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

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
/**
36
 * Constructor that initialises the value of the two floats to (ox,oy).   
37
 *   
38
 * @param ox value of the first float.
39
 * @param oy value of the second float.
40
 */    
41
  public Static2D(float ox, float oy)
42
    {
43
    super(2);
44
    x = ox;
45
    y = oy;
46
    }
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
/**
50
 * Copy constructor.
51
 */
52
  public Static2D(Static2D sta)
53
    {
54
    super(2);
55
    x = sta.x;
56
    y = sta.y;
57
    }
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
/**
61
 * Reset the value of the floats to (ox,oy).
62
 * 
63
 * @param ox new value of the first float
64
 * @param oy new value of the seond float
65
 */
66
  public void set(float ox, float oy)
67
    {
68
    x = ox;
69
    y = oy;
70
    }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73
/**
74
 * Copy a Static2D.
75
 */
76
  public void set(Static2D s)
77
    {
78
    x = s.x;
79
    y = s.y;
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83
/**
84
 * Resets the value of the first float.
85
 *
86
 * @param ox new value of the first float.
87
 */
88
  public void set0(float ox)
89
    {
90
    x = ox;
91
    }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94
/**
95
 * Resets the value of the second float.
96
 *
97
 * @param oy new value of the second float.
98
 */
99
  public void set1(float oy)
100
    {
101
    y = oy;
102
    }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105
/**
106
 * Return the value of the first float contained.
107
 *
108
 * @return The first float.
109
 */
110
  public float get0()
111
    {
112
    return x;
113
    }
114

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116
/**
117
 * Return the value of the second float contained.
118
 * 
119
 * @return The second float.
120
 */
121
  public float get1()
122
    {
123
    return y;  
124
    }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127
/**
128
 * 'Interpolation' between the single Point (i.e. always this very value) returned to the buffer.
129
 *
130
 * @param buffer Float buffer we will write the results to.
131
 * @param offset Offset in the buffer where to write the result.
132
 * @param time not used
133
 * @param step not used
134
 * @return <code>false</code>
135
 */
136
  public boolean get(float[] buffer, int offset, long time, long step)
137
    {
138
    buffer[offset  ] = x;
139
    buffer[offset+1] = y;
140
    return false;
141
    }
142
  }
(15-15/18)