Project

General

Profile

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

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

1 2c8310b1 Leszek Koltunski
////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski  leszek@koltunski.pl                                          //
3 d333eb6b Leszek Koltunski
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 d333eb6b Leszek Koltunski
//                                                                                               //
6 2c8310b1 Leszek Koltunski
// 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 d333eb6b Leszek Koltunski
//                                                                                               //
11 2c8310b1 Leszek Koltunski
// This library 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 2c8310b1 Leszek Koltunski
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
14
// Lesser General Public License for more details.                                               //
15 d333eb6b Leszek Koltunski
//                                                                                               //
16 2c8310b1 Leszek Koltunski
// 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 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
20
21 a4835695 Leszek Koltunski
package org.distorted.library.type;
22 6a06a912 Leszek Koltunski
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24
/**
25
 * A 2-dimensional data structure containing two floats. The floats have no particular meaning; 
26 cacc63de Leszek Koltunski
 * when this data structure is used in Dynamics, we can think of it as a 2-dimensional Point
27 568b29d8 Leszek Koltunski
 * a few of which the Dynamic interpolates between.
28 6a06a912 Leszek Koltunski
 */
29
30 a20f274f Leszek Koltunski
public class Static2D extends Static implements Data2D
31 6a06a912 Leszek Koltunski
  {
32 a20f274f Leszek Koltunski
  float x,y;
33 6a06a912 Leszek Koltunski
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 568b29d8 Leszek Koltunski
  public Static2D(float ox, float oy)
42 6a06a912 Leszek Koltunski
    {
43 a20f274f Leszek Koltunski
    super(2);
44
    x = ox;
45 6a06a912 Leszek Koltunski
    y = oy;
46
    }
47 a20f274f Leszek Koltunski
48 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
49 bff329fb Leszek Koltunski
/**
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 6a06a912 Leszek Koltunski
/**
61
 * Reset the value of the floats to (ox,oy).
62
 * 
63
 * @param ox new value of the first float
64 a20f274f Leszek Koltunski
 * @param oy new value of the seond float
65 6a06a912 Leszek Koltunski
 */
66 a20f274f Leszek Koltunski
  public void set(float ox, float oy)
67 6a06a912 Leszek Koltunski
    {
68
    x = ox;
69
    y = oy;
70
    }
71
72 f211a191 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
73
/**
74
 * Copy a Static2D.
75
 */
76
  public void set(Static2D s)
77
    {
78
    x = s.x;
79
    y = s.y;
80
    }
81
82 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
83
/**
84 a20f274f Leszek Koltunski
 * Resets the value of the first float.
85
 *
86
 * @param ox new value of the first float.
87 6a06a912 Leszek Koltunski
 */
88 ece89b28 Leszek Koltunski
  public void set0(float ox)
89 6a06a912 Leszek Koltunski
    {
90
    x = ox;
91
    }
92
93 8df64ab9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
94
/**
95
 * Resets the value of the second float.
96
 *
97
 * @param oy new value of the second float.
98
 */
99 ece89b28 Leszek Koltunski
  public void set1(float oy)
100 8df64ab9 Leszek Koltunski
    {
101
    y = oy;
102
    }
103
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105
/**
106 a20f274f Leszek Koltunski
 * Return the value of the first float contained.
107 8df64ab9 Leszek Koltunski
 *
108 a20f274f Leszek Koltunski
 * @return The first float.
109 8df64ab9 Leszek Koltunski
 */
110 ece89b28 Leszek Koltunski
  public float get0()
111 8df64ab9 Leszek Koltunski
    {
112 a20f274f Leszek Koltunski
    return x;
113 8df64ab9 Leszek Koltunski
    }
114
115 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
116
/**
117
 * Return the value of the second float contained.
118
 * 
119
 * @return The second float.
120
 */
121 ece89b28 Leszek Koltunski
  public float get1()
122 6a06a912 Leszek Koltunski
    {
123
    return y;  
124
    }
125
126 a1d92a36 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
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 6a06a912 Leszek Koltunski
  }