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.proto; 006 007import edu.wpi.first.math.geometry.Pose2d; 008import edu.wpi.first.math.geometry.Rectangle2d; 009import edu.wpi.first.math.proto.Geometry2D.ProtobufRectangle2d; 010import edu.wpi.first.util.protobuf.Protobuf; 011import us.hebi.quickbuf.Descriptors.Descriptor; 012 013public class Rectangle2dProto implements Protobuf<Rectangle2d, ProtobufRectangle2d> { 014 @Override 015 public Class<Rectangle2d> getTypeClass() { 016 return Rectangle2d.class; 017 } 018 019 @Override 020 public Descriptor getDescriptor() { 021 return ProtobufRectangle2d.getDescriptor(); 022 } 023 024 @Override 025 public ProtobufRectangle2d createMessage() { 026 return ProtobufRectangle2d.newInstance(); 027 } 028 029 @Override 030 public Rectangle2d unpack(ProtobufRectangle2d msg) { 031 return new Rectangle2d(Pose2d.proto.unpack(msg.getCenter()), msg.getXWidth(), msg.getYWidth()); 032 } 033 034 @Override 035 public void pack(ProtobufRectangle2d msg, Rectangle2d value) { 036 Pose2d.proto.pack(msg.getMutableCenter(), value.getCenter()); 037 msg.setXWidth(value.getXWidth()); 038 msg.setYWidth(value.getYWidth()); 039 } 040}