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.shape;
031
032import org.openimaj.math.geometry.GeometricObject2d;
033import org.openimaj.math.geometry.point.Point2d;
034
035import Jama.Matrix;
036
037/**
038 * Interface for classes that represent a shape.
039 *
040 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
041 */
042public interface Shape extends GeometricObject2d, Cloneable {
043        /**
044         * Test whether the point p is inside the shape.
045         *
046         * @param point
047         *            the point
048         * @return true if the point is inside; false otherwise
049         */
050        public boolean isInside(Point2d point);
051
052        /**
053         * Calculate the area of the shape
054         *
055         * @return the area of the shape
056         */
057        public double calculateArea();
058
059        /**
060         * Calculate the perimeter of the shape
061         *
062         * @return the perimeter of the shape
063         */
064        public double calculatePerimeter();
065
066        /**
067         * Convert the shape to a polygon representation
068         *
069         * @return a polygon representation of the shape
070         */
071        public Polygon asPolygon();
072
073        /**
074         * Calls {@link Polygon#intersectionArea(Shape, int)} with 1 step per pixel
075         * dimension. Subsequently this function returns the shared whole pixels of
076         * this polygon and that.
077         *
078         * @param that
079         * @return intersection area
080         */
081        public double intersectionArea(Shape that);
082
083        /**
084         * Return an estimate for the area of the intersection of this polygon and
085         * another polygon. For each pixel step 1 is added if the point is inside
086         * both polygons. The length of a step in each direction is calculated as
087         * follows:
088         *
089         * max(intersectionWidth,intersectionHeight)/ (nStepsPerDimention)
090         *
091         * The total number of points inside the intersection of the shames is
092         * divided by the number of points read and multiplied by the total area of
093         * the intersection.
094         *
095         * @param that
096         * @param nStepsPerDimension
097         * @return normalised intersection area
098         */
099        public double intersectionArea(Shape that, int nStepsPerDimension);
100
101        /**
102         * @return a copy of the shape
103         */
104        public Shape clone();
105
106        /**
107         * Compute the minimum size rotated bounding rectangle that contains this
108         * shape.
109         *
110         * @return the minimum bounding box
111         */
112        public RotatedRectangle minimumBoundingRectangle();
113
114        /**
115         * Test if the shape is convex.
116         *
117         * @return true if the shape is convex; false if non-convex
118         */
119        public boolean isConvex();
120
121        /*
122         * (non-Javadoc)
123         * 
124         * @see org.openimaj.math.geometry.GeometricObject2d#transform(Jama.Matrix)
125         */
126        @Override
127        public Shape transform(Matrix transform);
128}