001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.math.geometry.struct; 006 007import edu.wpi.first.math.geometry.Pose2d; 008import edu.wpi.first.math.geometry.Rectangle2d; 009import edu.wpi.first.util.struct.Struct; 010import java.nio.ByteBuffer; 011 012public class Rectangle2dStruct implements Struct<Rectangle2d> { 013 @Override 014 public Class<Rectangle2d> getTypeClass() { 015 return Rectangle2d.class; 016 } 017 018 @Override 019 public String getTypeName() { 020 return "Rectangle2d"; 021 } 022 023 @Override 024 public int getSize() { 025 return Pose2d.struct.getSize() + kSizeDouble + kSizeDouble; 026 } 027 028 @Override 029 public String getSchema() { 030 return "Pose2d center;double xWidth; double yWidth"; 031 } 032 033 @Override 034 public Struct<?>[] getNested() { 035 return new Struct<?>[] {Pose2d.struct}; 036 } 037 038 @Override 039 public Rectangle2d unpack(ByteBuffer bb) { 040 Pose2d center = Pose2d.struct.unpack(bb); 041 double width = bb.getDouble(); 042 double height = bb.getDouble(); 043 return new Rectangle2d(center, width, height); 044 } 045 046 @Override 047 public void pack(ByteBuffer bb, Rectangle2d value) { 048 Pose2d.struct.pack(bb, value.getCenter()); 049 bb.putDouble(value.getXWidth()); 050 bb.putDouble(value.getYWidth()); 051 } 052}