Skip to content

Commit

Permalink
Extract 2D shapes interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ppouchin committed Nov 30, 2024
1 parent 9d04c69 commit 534e2c0
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 420 deletions.
117 changes: 1 addition & 116 deletions src/main/java/fr/igred/omero/roi/Mask.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Interface to handle Mask shapes on OMERO.
*/
public interface Mask extends Shape {
public interface Mask extends Shape, Rectangular {

/**
* Returns an {@link MaskData} corresponding to the handled object.
Expand All @@ -48,69 +48,6 @@ default java.awt.Shape toAWTShape() {
return new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight());
}

/**
* Returns the x-coordinate of the top-left corner of the mask.
*
* @return See above.
*/
double getX();


/**
* Sets the x-coordinate top-left corner of an untransformed mask.
*
* @param x The value to set.
*/
void setX(double x);


/**
* Returns the y-coordinate of the top-left corner of the mask.
*
* @return See above.
*/
double getY();


/**
* Sets the y-coordinate top-left corner of an untransformed mask.
*
* @param y See above.
*/
void setY(double y);


/**
* Returns the width of the mask.
*
* @return See above.
*/
double getWidth();


/**
* Sets the width of an untransformed mask.
*
* @param width See above.
*/
void setWidth(double width);


/**
* Returns the height of the mask.
*
* @return See above.
*/
double getHeight();


/**
* Sets the height of an untransformed mask.
*
* @param height See above.
*/
void setHeight(double height);


/**
* Returns the mask image.
Expand Down Expand Up @@ -159,56 +96,4 @@ default java.awt.Shape toAWTShape() {
*/
void setMask(boolean[][] mask);


/**
* Sets the coordinates of the MaskData shape.
*
* @param x The x-coordinate of the top-left corner.
* @param y The y-coordinate of the top-left corner.
* @param width The width of the rectangle.
* @param height The height of the rectangle.
*/
default void setCoordinates(double x, double y, double width, double height) {
setX(x);
setY(y);
setWidth(width);
setHeight(height);
}


/**
* Gets the coordinates of the MaskData shape.
*
* @return Array of coordinates containing {X,Y,Width,Height}.
*/
default double[] getCoordinates() {
double[] coordinates = new double[4];
coordinates[0] = getX();
coordinates[1] = getY();
coordinates[2] = getWidth();
coordinates[3] = getHeight();
return coordinates;
}


/**
* Sets the coordinates of the MaskData shape.
*
* @param coordinates Array of coordinates containing {X,Y,Width,Height}.
*/
default void setCoordinates(double[] coordinates) {
if (coordinates == null) {
String msg = "MaskData cannot set null coordinates.";
throw new IllegalArgumentException(msg);
} else if (coordinates.length == 4) {
setX(coordinates[0]);
setY(coordinates[1]);
setWidth(coordinates[2]);
setHeight(coordinates[3]);
} else {
String msg = "4 coordinates required for MaskData.";
throw new IllegalArgumentException(msg);
}
}

}
2 changes: 1 addition & 1 deletion src/main/java/fr/igred/omero/roi/MaskWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public double getX() {
/**
* Sets the x-coordinate top-left corner of an untransformed mask.
*
* @param x The value to set.
* @param x See above.
*/
@Override
public void setX(double x) {
Expand Down
77 changes: 1 addition & 76 deletions src/main/java/fr/igred/omero/roi/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* Interface to handle Point shapes on OMERO.
*/
public interface Point extends Shape {
public interface Point extends Shape, Punctual {

/**
* Returns an {@link PointData} corresponding to the handled object.
Expand All @@ -50,79 +50,4 @@ default java.awt.Shape toAWTShape() {
}


/**
* Returns the x-coordinate of the shape.
*
* @return See above.
*/
double getX();


/**
* Sets the x-coordinate of the shape.
*
* @param x See above.
*/
void setX(double x);


/**
* Returns the y coordinate of the shape.
*
* @return See above.
*/
double getY();


/**
* Sets the y-coordinate of the shape.
*
* @param y See above.
*/
void setY(double y);


/**
* Sets the coordinates the PointData shape.
*
* @param x x-coordinate of the PointData shape.
* @param y y-coordinate of the PointData shape.
*/
default void setCoordinates(double x, double y) {
setX(x);
setY(y);
}


/**
* Gets the coordinates of the PointData shape.
*
* @return Array of coordinates containing {X,Y}.
*/
default double[] getCoordinates() {
double[] coordinates = new double[2];
coordinates[0] = getX();
coordinates[1] = getY();
return coordinates;
}


/**
* Sets the coordinates of the PointData shape.
*
* @param coordinates Array of coordinates containing {X,Y}.
*/
default void setCoordinates(double[] coordinates) {
if (coordinates == null) {
String msg = "PointData cannot set null coordinates.";
throw new IllegalArgumentException(msg);
} else if (coordinates.length == 2) {
setX(coordinates[0]);
setY(coordinates[1]);
} else {
String msg = "2 coordinates required for PointData.";
throw new IllegalArgumentException(msg);
}
}

}
18 changes: 1 addition & 17 deletions src/main/java/fr/igred/omero/roi/Polygon.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* Interface to handle Polygon shapes on OMERO.
*/
public interface Polygon extends Shape {
public interface Polygon extends Shape, Polylineal {

/**
* Returns an {@link PolygonData} corresponding to the handled object.
Expand Down Expand Up @@ -60,22 +60,6 @@ default java.awt.Shape toAWTShape() {
}


/**
* Returns the points in the Polygon.
*
* @return See above.
*/
List<Point2D.Double> getPoints();


/**
* Sets the points in the polyline.
*
* @param points The points to set.
*/
void setPoints(List<Point2D.Double> points);


/**
* Returns the points in the polygon.
*
Expand Down
18 changes: 1 addition & 17 deletions src/main/java/fr/igred/omero/roi/Polyline.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* Interface to handle Polyline shapes on OMERO.
*/
public interface Polyline extends Shape {
public interface Polyline extends Shape, Polylineal {

/**
* Returns an {@link PolylineData} corresponding to the handled object.
Expand Down Expand Up @@ -58,20 +58,4 @@ default java.awt.Shape toAWTShape() {
return polyline;
}


/**
* Returns the points in the Polyline.
*
* @return See above.
*/
List<Point2D.Double> getPoints();


/**
* Sets the points in the polyline.
*
* @param points The points to set.
*/
void setPoints(List<Point2D.Double> points);

}
45 changes: 45 additions & 0 deletions src/main/java/fr/igred/omero/roi/Polylineal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2020-2024 GReD
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
* Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package fr.igred.omero.roi;


import java.awt.geom.Point2D;
import java.util.List;


/**
* Interface for polygonal shapes.
*/
public interface Polylineal {

/**
* Returns the points in the polygonal shape.
*
* @return See above.
*/
List<Point2D.Double> getPoints();


/**
* Sets the points in the polygonal shape.
*
* @param points The points to set.
*/
void setPoints(List<Point2D.Double> points);

}
Loading

0 comments on commit 534e2c0

Please sign in to comment.