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.geometry.mappings.linear; 011 012import imagingbook.common.math.Arithmetic; 013 014/** 015 * <p> 016 * This class represents a 2D scaling transformation (as a special case of affine transformation). See Secs. 21.1.3 and 017 * 21.3.1 of [1] for details. 018 * </p> 019 * <p> 020 * [1] W. Burger, M.J. Burge, <em>Digital Image Processing – An Algorithmic Introduction</em>, 3rd ed, Springer 021 * (2022). 022 * </p> 023 * 024 * @author WB 025 */ 026public class Scaling2D extends AffineMapping2D { 027 028 public Scaling2D(Scaling2D sc) { 029 super(sc); 030 } 031 032 /** 033 * Constructor. Creates a mapping that scales along the x- and y-axis by the associated factors. 034 * 035 * @param sx the scale factor in x-direction 036 * @param sy the scale factor in y-direction 037 */ 038 public Scaling2D(double sx, double sy) { 039 super( 040 checkZero(sx), 0, 0, 041 0, checkZero(sy), 0); 042 } 043 044 private static double checkZero(double s) { 045 if (Arithmetic.isZero(s)) { 046 throw new IllegalArgumentException("zero scale parameter " + s); 047 } 048 return s; 049 } 050 051 /** 052 * Constructor. Creates a uniform scaling in x and y. 053 * @param s the common scale factor 054 */ 055 public Scaling2D(double s) { 056 this(s, s); 057 } 058 059 /** 060 * {@inheritDoc} 061 * @return a new scaling transformation 062 */ 063 @Override 064 public Scaling2D getInverse() { 065 return new Scaling2D(1/a00, 1/a11); 066 } 067 068 /** 069 * {@inheritDoc} 070 * @return a new scaling transformation 071 */ 072 @Override 073 public Scaling2D duplicate() { 074 return new Scaling2D(this); 075 } 076} 077 078