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 */ 031public class TargetCorner implements ProtobufSerializable, PhotonStructSerializable<TargetCorner> { 032 public double x; 033 public double y; 034 035 public TargetCorner(double cx, double cy) { 036 this.x = cx; 037 this.y = cy; 038 } 039 040 public TargetCorner() { 041 this(0, 0); 042 } 043 044 @Override 045 public boolean equals(Object o) { 046 if (this == o) return true; 047 if (o == null || getClass() != o.getClass()) return false; 048 TargetCorner that = (TargetCorner) o; 049 return Double.compare(that.x, x) == 0 && Double.compare(that.y, y) == 0; 050 } 051 052 @Override 053 public int hashCode() { 054 return Objects.hash(x, y); 055 } 056 057 @Override 058 public String toString() { 059 return "(" + x + "," + y + ')'; 060 } 061 062 public static final TargetCornerProto proto = new TargetCornerProto(); 063 public static final TargetCornerSerde photonStruct = new TargetCornerSerde(); 064 065 @Override 066 public PacketSerde<TargetCorner> getSerde() { 067 return photonStruct; 068 } 069}