Class PolygonScaling
- java.lang.Object
-
- ch.sahits.game.graphic.image.impl.PolygonScaling
-
- All Implemented Interfaces:
IPolygonScaling
@Service public class PolygonScaling extends java.lang.Object implements IPolygonScaling
Implementation class for recalculating poligons of a scaled, bordered and cropped image and on the absolute positioning of that image on the screen.- Author:
- Andi Hotz, (c) Sahits GmbH, 2012 Created on Jul 1, 2012
-
-
Constructor Summary
Constructors Constructor Description PolygonScaling()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private ImageData
createNewCopy(ImageData imgData)
Create a clone of the image data and handle the CloneNotSupportedException(package private) ImageData
recalculatePolygonCrop(ImageData imgData, ImageScaleState state)
Compute the polygon affected by the cropping of the image as stated in stateImageData
recalculatePolygons(ImageData imgData, ImageScaleState state)
Compute the location and dimensions of the NamedPolygons that are contained inimgData
based on the scaling state.(package private) ImageData
recalculatePolygonScale(ImageData imgData, ImageScaleState state)
Compute the polygon affected by the scaling of the image as stated in stateImageData
recalculatePolygonsOffset(ImageData imgData, javafx.geometry.Point2D offset)
Recalculate the positions of the polygons to reflect their absolute on screen locations.(package private) void
updateCoordinate(NamedPolygon poly, double factor)
Update the x and y coordinate of each point within the polygon by factor(package private) void
updateCoordinates(NamedPolygon poly, double diffX, double diffY)
Update the coordinates of the polygon by the specified values in x and y direction(package private) void
updateXCoordinate(NamedPolygon poly, int amount)
Update the x coordinate of each point within the polygon by amount(package private) void
updateYCoordinate(NamedPolygon poly, int amount)
Update the y coordinate of each point within the polygon by amount
-
-
-
Method Detail
-
recalculatePolygons
public ImageData recalculatePolygons(ImageData imgData, ImageScaleState state)
Description copied from interface:IPolygonScaling
Compute the location and dimensions of the NamedPolygons that are contained inimgData
based on the scaling state. If the image was cropped or bordered this may result in a translocation of the defined polygon. If the image was scaled this will result in a translocation to or from the origin (top left corner) by the factor of the scaling. A new instance of image Data with the new polygon definition will be returned.- Specified by:
recalculatePolygons
in interfaceIPolygonScaling
- Parameters:
imgData
- Input data of the image containing a list of NamedPolygons that are to be recalculatedstate
- of the scaled image- Returns:
- new instance of ImageData containing the recalculated polygons
-
recalculatePolygonsOffset
public ImageData recalculatePolygonsOffset(ImageData imgData, javafx.geometry.Point2D offset)
Description copied from interface:IPolygonScaling
Recalculate the positions of the polygons to reflect their absolute on screen locations.- Specified by:
recalculatePolygonsOffset
in interfaceIPolygonScaling
- Parameters:
imgData
- Input data of the image containing a list of NamedPolygons that are to be recalculatedoffset
- Point indicating the absolute position on screen of the origin (top left corner) of the image- Returns:
- new instance of ImageData containing the recalculated polygons
-
recalculatePolygonCrop
final ImageData recalculatePolygonCrop(ImageData imgData, ImageScaleState state)
Compute the polygon affected by the cropping of the image as stated in state- Parameters:
imgData
- Input data of the image containing a list ofNamedPolygon
s that are to be recalculatedstate
- of the scaled image- Returns:
- new instance of ImageData containing the recalculated polygons
-
createNewCopy
private ImageData createNewCopy(ImageData imgData)
Create a clone of the image data and handle the CloneNotSupportedException- Parameters:
imgData
- image data- Returns:
- copy of the image data
-
recalculatePolygonScale
final ImageData recalculatePolygonScale(ImageData imgData, ImageScaleState state)
Compute the polygon affected by the scaling of the image as stated in state- Parameters:
imgData
- Input data of the image containing a list ofNamedPolygon
s that are to be recalculatedstate
- of the scaled image- Returns:
- new instance of ImageData containing the recalculated polygons
-
updateCoordinates
void updateCoordinates(NamedPolygon poly, double diffX, double diffY)
Update the coordinates of the polygon by the specified values in x and y direction- Parameters:
poly
- polygon to be updateddiffX
- difference in x directiondiffY
- difference in y direction
-
updateXCoordinate
void updateXCoordinate(NamedPolygon poly, int amount)
Update the x coordinate of each point within the polygon by amount- Parameters:
poly
- polygon to be updatedamount
- the X-coordinate is to be translated
-
updateYCoordinate
void updateYCoordinate(NamedPolygon poly, int amount)
Update the y coordinate of each point within the polygon by amount- Parameters:
poly
- polygon to be updatedamount
- the Y-coordinate is to be translated
-
updateCoordinate
void updateCoordinate(NamedPolygon poly, double factor)
Update the x and y coordinate of each point within the polygon by factor- Parameters:
poly
- polygon to be updatedfactor
- that is to be multiplied with each coordinate
-
-