001/**
002 * Copyright (c) 2011, The University of Southampton and the individual contributors.
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification,
006 * are permitted provided that the following conditions are met:
007 *
008 *   *  Redistributions of source code must retain the above copyright notice,
009 *      this list of conditions and the following disclaimer.
010 *
011 *   *  Redistributions in binary form must reproduce the above copyright notice,
012 *      this list of conditions and the following disclaimer in the documentation
013 *      and/or other materials provided with the distribution.
014 *
015 *   *  Neither the name of the University of Southampton nor the names of its
016 *      contributors may be used to endorse or promote products derived from this
017 *      software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030package org.openimaj.math.geometry;
031
032import org.openimaj.math.geometry.point.Point2d;
033import org.openimaj.math.geometry.shape.Rectangle;
034
035import Jama.Matrix;
036
037/**
038 * A generalised 2D geometric object that has a calculable centre of gravity and
039 * regular bounding box. The object can also be transformed in a variety of
040 * ways.
041 * 
042 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
043 */
044public interface GeometricObject2d {
045        /**
046         * Compute the regular (oriented to the axes) bounding box of the shape.
047         * 
048         * @return the regular bounding box as [x,y,width,height]
049         */
050        public Rectangle calculateRegularBoundingBox();
051
052        /**
053         * Translate the shapes position
054         * 
055         * @param x
056         *            x-translation
057         * @param y
058         *            y-translation
059         */
060        public void translate(float x, float y);
061
062        /**
063         * Scale the shape by the given amount about (0,0). Scalefactors between 0
064         * and 1 shrink the shape.
065         * 
066         * @param sc
067         *            the scale factor.
068         */
069        public void scale(float sc);
070
071        /**
072         * Scale the shape by the given amount about the given point. Scalefactors
073         * between 0 and 1 shrink the shape.
074         * 
075         * @param centre
076         *            the centre of the scaling operation
077         * @param sc
078         *            the scale factor
079         */
080        public void scale(Point2d centre, float sc);
081
082        /**
083         * Scale the shape about its centroid. Scalefactors between 0 and 1 shrink
084         * the shape.
085         * 
086         * @param sc
087         *            the scale factor
088         */
089        public void scaleCentroid(float sc);
090
091        /**
092         * Calculate the centroid of the shape
093         * 
094         * @return the centroid of the shape
095         */
096        public Point2d calculateCentroid();
097
098        /**
099         * @return the minimum x-ordinate
100         */
101        public double minX();
102
103        /**
104         * @return the minimum y-ordinate
105         */
106        public double minY();
107
108        /**
109         * @return the maximum x-ordinate
110         */
111        public double maxX();
112
113        /**
114         * @return the maximum y-ordinate
115         */
116        public double maxY();
117
118        /**
119         * @return the width of the regular bounding box
120         */
121        public double getWidth();
122
123        /**
124         * @return the height of the regular bounding box
125         */
126        public double getHeight();
127
128        /**
129         * Apply a 3x3 transform matrix to a copy of the {@link GeometricObject2d} and
130         * return it
131         * 
132         * @param transform
133         *            3x3 transform matrix
134         * @return the transformed shape
135         */
136        public GeometricObject2d transform(Matrix transform);
137}