001/******************************************************************************* 002 * This software is provided as a supplement to the authors' textbooks on digital 003 * image processing published by Springer-Verlag in various languages and editions. 004 * Permission to use and distribute this software is granted under the BSD 2-Clause 005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause). 006 * Copyright (c) 2006-2023 Wilhelm Burger, Mark J. Burge. All rights reserved. 007 * Visit https://imagingbook.com for additional details. 008 ******************************************************************************/ 009 010package imagingbook.common.corners; 011 012import imagingbook.common.geometry.basic.Pnt2d; 013 014import java.awt.Shape; 015import java.awt.geom.Path2D; 016import java.util.Locale; 017 018 019/** 020 * This class represents a 2D corner. A corner is essentially a {@link Pnt2d} plus a scalar quantity {@code q} for the 021 * corner strength. 022 * 023 * @version 2022/09/05 024 */ 025public class Corner implements Pnt2d, Comparable<Corner> { 026 027 private final float x, y; 028 private final float q; 029 030 /** 031 * Constructor. 032 * @param x horizontal position 033 * @param y vertical position 034 * @param q corner score value 035 */ 036 public Corner(float x, float y, float q) { 037 this.x = x; 038 this.y = y; 039 this.q = q; 040 } 041 042 @Override 043 public double getX() { 044 return x; 045 } 046 047 @Override 048 public double getY() { 049 return y; 050 } 051 052 /** 053 * Returns this corner's score value. 054 * @return score value 055 */ 056 public double getQ() { 057 return q; 058 } 059 060 // used for sorting corners by corner strength q (strong corners first) 061 @Override 062 public int compareTo(Corner other) { 063 return Float.compare(other.q, this.q); 064 } 065 066 // ---------------------------------------------------------------- 067 068 @Override 069 public String toString() { 070 return String.format(Locale.US, "Corner <%.3f, %.3f, %.3f>", x, y, q); 071 } 072 073 @Override 074 public Shape getShape(double size) { 075 Path2D path = new Path2D.Double(); 076 path.moveTo(x - size, y); 077 path.lineTo(x + size, y); 078 path.moveTo(x, y - size); 079 path.lineTo(x, y + size); 080 return path; 081 } 082 083} 084