001/* 002 * Copyright (C) Photon Vision. 003 * 004 * This program is free software: you can redistribute it and/or modify 005 * it under the terms of the GNU General Public License as published by 006 * the Free Software Foundation, either version 3 of the License, or 007 * (at your option) any later version. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program. If not, see <https://www.gnu.org/licenses/>. 016 */ 017 018package org.photonvision.targeting; 019 020import edu.wpi.first.util.protobuf.ProtobufSerializable; 021import java.util.Objects; 022import org.photonvision.common.dataflow.structures.PacketSerde; 023import org.photonvision.struct.TargetCornerSerde; 024import org.photonvision.targeting.proto.TargetCornerProto; 025import org.photonvision.targeting.serde.PhotonStructSerializable; 026 027/** 028 * Represents a point in an image at the corner of the minimum-area bounding rectangle, in pixels. 029 * Origin at the top left, plus-x to the right, plus-y down. 030 */ 031@SuppressWarnings("doclint") 032public class TargetCorner implements ProtobufSerializable, PhotonStructSerializable<TargetCorner> { 033 public double x; 034 public double y; 035 036 public TargetCorner(double cx, double cy) { 037 this.x = cx; 038 this.y = cy; 039 } 040 041 public TargetCorner() { 042 this(0, 0); 043 } 044 045 @Override 046 public boolean equals(Object o) { 047 if (this == o) return true; 048 if (o == null || getClass() != o.getClass()) return false; 049 TargetCorner that = (TargetCorner) o; 050 return Double.compare(that.x, x) == 0 && Double.compare(that.y, y) == 0; 051 } 052 053 @Override 054 public int hashCode() { 055 return Objects.hash(x, y); 056 } 057 058 @Override 059 public String toString() { 060 return "(" + x + "," + y + ')'; 061 } 062 063 /** TargetCorner protobuf for serialization. */ 064 public static final TargetCornerProto proto = new TargetCornerProto(); 065 066 /** TargetCorner PhotonStruct for serialization. */ 067 public static final TargetCornerSerde photonStruct = new TargetCornerSerde(); 068 069 @Override 070 public PacketSerde<TargetCorner> getSerde() { 071 return photonStruct; 072 } 073}