RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
VectorStruct.java
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5package org.wpilib.math.linalg.struct;
6
7import java.nio.ByteBuffer;
8import org.ejml.simple.SimpleMatrix;
9import org.wpilib.math.linalg.Vector;
10import org.wpilib.math.util.Nat;
11import org.wpilib.math.util.Num;
12import org.wpilib.util.struct.Struct;
13
14public final class VectorStruct<R extends Num> implements Struct<Vector<R>> {
15 private final int m_rows;
16
22 public VectorStruct(Nat<R> rows) {
23 m_rows = rows.getNum();
24 }
25
26 @Override
27 public Class<Vector<R>> getTypeClass() {
28 @SuppressWarnings("unchecked")
29 var clazz = (Class<Vector<R>>) (Class<?>) Vector.class;
30 return clazz;
31 }
32
33 @Override
34 public String getTypeName() {
35 return "Vector__" + m_rows;
36 }
37
38 @Override
39 public int getSize() {
40 return DOUBLE_SIZE * m_rows;
41 }
42
43 @Override
44 public String getSchema() {
45 return "double data[" + m_rows + "]";
46 }
47
48 @Override
49 public Vector<R> unpack(ByteBuffer bb) {
50 var storage = new SimpleMatrix(Struct.unpackDoubleArray(bb, m_rows));
51 return new Vector<R>(storage);
52 }
53
54 @Override
55 public void pack(ByteBuffer bb, Vector<R> value) {
56 Struct.packArray(bb, value.getData());
57 }
58}
static< T > void packArray(ByteBuffer bb, T[] arr, Struct< T > struct)
Definition Struct.java:175
static double[] unpackDoubleArray(ByteBuffer bb, int size)
Definition Struct.java:157