1 /*
2 * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package view.f32.pool;
26
27 import view.f32.F32x2;
28
29 public class F32x2Pool extends F32Pool<F32x2, F32x2Pool> implements F32x2.Factory {
30
31 public record PoolEntry(F32x2Pool pool, int idx) implements Pool.PoolEntry<F32x2, F32x2Pool>, F32x2 {
32 private static final int X = 0;
33 private static final int Y = 1;
34
35 private int xIdx() {
36 return pool.floatStride * idx + X;
37 }
38
39 @Override
40 public float x() {
41 return pool.floatEntries[xIdx()];
42 }
43
44 private int yIdx() {
45 return pool.floatStride * idx + Y;
46 }
47
48 @Override
49 public float y() {
50 return pool.floatEntries[yIdx()];
51 }
52
53 }
54
55 public F32x2Pool(int max) {
56 super(2, max);
57 }
58
59 @Override
60 public F32x2 entry(int idx) {
61 return new PoolEntry(this, idx);
62 }
63
64 @Override
65 public F32x2 of(Float x, Float y) {
66 PoolEntry i = (PoolEntry) entry(count++);
67 floatEntries[i.xIdx()] = x;
68 floatEntries[i.yIdx()] = y;
69 return i;
70 }
71 }