Package com.geniusscansdk.core
Class Quadrangle
- java.lang.Object
-
- com.geniusscansdk.core.Quadrangle
-
- All Implemented Interfaces:
android.os.Parcelable
public class Quadrangle extends java.lang.Object implements android.os.ParcelableThe quadrangle used to represent document borders. It consists of four points in a specific order: Top Left, Top Right, Bottom Left, Bottom Right. If no document is present, the quadrangle matches the full image.
-
-
Field Summary
Fields Modifier and Type Field Description static android.os.Parcelable.Creator<Quadrangle>CREATOR
-
Constructor Summary
Constructors Constructor Description Quadrangle()Create an empty quadrangle, meaning document detection has not been run, or it has detected no document in the image.Quadrangle(float[] points)Create a quadrangle from an array of coordinates.Quadrangle(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)Create a quadrangle from the coordinates of the corners.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static QuadranglecreateFullQuadrangle()Create a quadrangle that matches the full image, meaning a document has been detected but it fills the entire image and thus no crop should be performed.intdescribeContents()intgetClosestCorner(float x, float y)float[]getPoints()booleanisEmpty()booleanisFullImage()voidmove(int cornerIndex, float dx, float dy)Move a specific corner by a fixed distance.voidorder()Reorder the corners of the Quadrangle in the standard order.Quadranglerotate(RotationAngle angle)Rotate a quadrangle by a specific anglevoidsetToFullImage()Set the corners of the quadrangle to match the corners of the image.java.lang.StringtoString()voidwriteToParcel(android.os.Parcel dest, int flags)
-
-
-
Field Detail
-
CREATOR
public static final android.os.Parcelable.Creator<Quadrangle> CREATOR
-
-
Constructor Detail
-
Quadrangle
public Quadrangle()
Create an empty quadrangle, meaning document detection has not been run, or it has detected no document in the image.
-
Quadrangle
public Quadrangle(float[] points)
Create a quadrangle from an array of coordinates. The order of the corners must be: TopLeft (x, y), TopRight (x, y), BottomLeft (x, y), BottomRight (x, y). Each coordinate must be between 0 and 1. x values are relative to the width of the image, y values are relative to the height of the image.- Parameters:
-
points- The relative coordinates of the four corners of the quadrangle. This array must have a length of 8.
-
Quadrangle
public Quadrangle(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)Create a quadrangle from the coordinates of the corners. SeeQuadrangle(float[])for more details.
-
-
Method Detail
-
createFullQuadrangle
public static Quadrangle createFullQuadrangle()
Create a quadrangle that matches the full image, meaning a document has been detected but it fills the entire image and thus no crop should be performed.- Returns:
- a full quadrangle
-
getPoints
public float[] getPoints()
- Returns:
-
the coordinates of the corners of the Quadrangle. See
Quadrangle(float[])for the order of the coordinates.
-
move
public void move(int cornerIndex, float dx, float dy)Move a specific corner by a fixed distance.- Parameters:
cornerIndex- The index of the corner to move. Must be between 0 and 3.-
dx- Horizontal shift of the corner. Must be between 0 and 1 and relative to the width of the image. -
dy- Vertical shift of the corner. Must be between 0 and 1 and relative to the height of the image.
-
getClosestCorner
public int getClosestCorner(float x, float y)- Parameters:
x- The horizontal coordinate of a point, relative to the width of an image.y- The vertical coordinate of a point, relative to the height of an image.- Returns:
- The index of the closest corner to the given point
-
order
public void order()
Reorder the corners of the Quadrangle in the standard order.
-
setToFullImage
public void setToFullImage()
Set the corners of the quadrangle to match the corners of the image.
-
isFullImage
public boolean isFullImage()
- Returns:
- true if the corners of the quadrangle matches the corners of the image, meaning no document has been detected in the image.
-
isEmpty
public boolean isEmpty()
- Returns:
- true if all coordinates equal to 0, meaning no document detection has been run yet.
-
rotate
public Quadrangle rotate(RotationAngle angle)
Rotate a quadrangle by a specific angle- Parameters:
angle- The angle used to rotate the quadrangle- Returns:
- the rotated quadrangle
-
toString
@NonNull public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
describeContents
public int describeContents()
- Specified by:
describeContentsin interfaceandroid.os.Parcelable
-
writeToParcel
public void writeToParcel(android.os.Parcel dest, int flags)- Specified by:
writeToParcelin interfaceandroid.os.Parcelable
-
-