public class UnsafeSegment2D
extends java.lang.Object
implements java.lang.Cloneable
"Unsafe" 2D segment
It is a version of Segment2D
segment, which can work incorrectly if arguments
of setFi(fi, nx, ny) or setAll(centerX, centerY, length, fi, nx, ny) method are illegal.
This class allows to avoid slow calculation of cosine and sine
while setting new direction. But getNormalClone() and copyNormalTo()
methods work slower than the same methods in Segment2D
class.
This class is immutable and threadsafe: there are no ways to modify settings of the created instance.
AlgART Laboratory 2007–2014
Modifier and Type  Method and Description 

void 
checkInvariants()
Generates IllegalStateException exception if the information stored in this object is invalid, setFi(fi, nx, ny) or setAll(centerX, centerY, length, fi, nx, ny) method
was called with illegal arguments.

java.lang.Object 
clone()
Creates an identical copy of this object.

void 
copyFrom(UnsafeSegment2D other)
Sets the current segment identical to other.

void 
copyNormalTo(Direction2D normal)
Copies the normal vector to this segment to the given argument
(normal.getAngle() will be equal to this.getFi() + π / 2).

boolean 
equals(java.lang.Object obj)
Indicates whether some other segment is equal to this one, with a precision set by the last
setEqualityPrecision(double) call (or with absolute precision if that method was never called). 
double 
getAngleBetweenDirections(UnsafeSegment2D other)
Returns the shortes angle (0..π, in radians)
between the directions of this and other segments, from 1st end to 2nd.

double 
getAngleBetweenStraights(UnsafeSegment2D other)
Returns the shortes angle (0..π/2, in radians)
between the straights containing this and other segments.

double 
getCenterX()
Returns the xcoordinate of the segment center.

double 
getCenterY()
Returns the ycoordinate of the segment center.

double 
getEqualityPrecision()
Returns the "equality prevision" for this segment: a precision of segments equality
considered by equals and hashCode methods.

double 
getFi()
Returns the direction (in radians) from the segment begin to the segment end:
an angle between 0x and a ray from 1st to 2nd segment end.

double 
getLength()
Returns the segment length.

Direction2D 
getNormalClone()
Returns the normal unit vector, with creating a clone.

double 
getNormalUnitVectorX()
Returns xprojection of the normal unit vector,
which direction is fi+π/2, where fi is set by setFi or setAll methods.

double 
getNormalUnitVectorY()
Returns yprojection of the normal unit vector,
which direction is fi+π/2, where fi is set by setFi or setAll methods.

double 
getUnitVectorX()
Returns xprojection of the unit vector directed from the segment begin to the segment end,
that is which direction is fi, where fi is set by setFi or setAll methods.

double 
getUnitVectorY()
Returns yprojection of the unit vector directed from the segment begin to the segment end,
that is which direction is fi, where fi is set by setFi or setAll methods.

static UnsafeSegment2D 
getUnsafeInstance()
Creates some "default" segment.

double 
getX1()
Returns xcoordinate of the segment begin.

double 
getX2()
Returns xcoordinate of the segment end.

double 
getY1()
Returns ycoordinate of the segment begin.

double 
getY2()
Returns ycoordinate of the segment end.

int 
hashCode()
Returns the hash code for this segment.

void 
inverse()
Rotates the segment around its center by π: new direction angle will be φ + π,
where φ is current direction angle.

void 
revive()
Revive direction vector by recalculation of the normal unit vector:
see
Direction2D.revive() . 
void 
rotate(Rotation2D rot)
Rotates the segment around its center: new direction angle will be φ + rot.getRotationAngle(),
where φ is current direction angle.

void 
rotateBack(Rotation2D rot)
Rotates the segment around its center: new direction angle will be φ  rot.getRotationAngle(),
where φ is current direction angle.

void 
setAll(double centerX,
double centerY,
double length,
Direction2D normal)
Sets all segment information (normal.getAngle() = this.getFi() + π / 2).

void 
setAll(double centerX,
double centerY,
double length,
double fi)
Sets all segment information.

void 
setAll(double centerX,
double centerY,
double length,
double fi,
double nx,
double ny)
Sets all segment information.

void 
setCenter(double centerX,
double centerY)
Sets the coordinates of the segment center.

void 
setCenterX(double value)
Sets the xcoordinate of the segment center.

void 
setCenterY(double value)
Sets the ycoordinate of the segment center.

void 
setEqualityPrecision(double value)
Sets the "equality prevision" for this segment: a precision of segments equality
considered by equals and hashCode methods.

void 
setFi(double value)
Sets the segment orientation (an angle between 0x and a ray from 1st to 2nd segment end).

void 
setFi(double fi,
double nx,
double ny)
Sets the segment direction.

void 
setLength(double value)
Sets the segment length.

void 
setNormal(Direction2D value)
Copies the agrument into the normal unit vector inside this object
(value.getAngle() = this.getFi() + π / 2)

java.lang.String 
toString()
Returns some string representation of this object.

public static UnsafeSegment2D getUnsafeInstance()
public double getCenterX()
public void setCenterX(double value)
public double getCenterY()
public void setCenterY(double value)
public double getLength()
public void setLength(double value)
public double getFi()
public void setFi(double value)
public double getX1()
public double getY1()
public double getX2()
public double getY2()
public void setCenter(double centerX, double centerY)
public void setAll(double centerX, double centerY, double length, double fi)
public void setAll(double centerX, double centerY, double length, Direction2D normal)
public void setNormal(Direction2D value)
public void setFi(double fi, double nx, double ny)
The following conditions must be true: nx = cos(fi+π/2), ny = sin(fi+π/2). If it is not so, then getNormalUnitVectorX(), getNormalUnitVectorY(), getX1(), getY1(), getX2(), getY2() methods will work incorrectly.
public void setAll(double centerX, double centerY, double length, double fi, double nx, double ny)
The following conditions must be true: length >= 0.0, nx = cos(fi+π/2), ny = sin(fi+π/2) If it is not so, then getNormalUnitVectorX(), getNormalUnitVectorY(), getX1(), getY1(), getX2(), getY2() methods will work incorrectly.
public Direction2D getNormalClone()
public void copyNormalTo(Direction2D normal)
public double getUnitVectorX()
public double getUnitVectorY()
public double getNormalUnitVectorX()
public double getNormalUnitVectorY()
public double getAngleBetweenStraights(UnsafeSegment2D other)
public double getAngleBetweenDirections(UnsafeSegment2D other)
public void revive()
Direction2D.revive()
.
This method should usually be called sometimes in any long sequence of rotate
or rotateBack methods.public void rotate(Rotation2D rot)
public void rotateBack(Rotation2D rot)
public void inverse()
public void copyFrom(UnsafeSegment2D other)
public void checkInvariants()
public double getEqualityPrecision()
equals(Object)
,
hashCode()
,
setEqualityPrecision(double)
public void setEqualityPrecision(double value)
equals(Object)
,
hashCode()
public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
setEqualityPrecision(double)
method, is nonzero,
this method uses it to correspond to behavior of equals(Object)
} method.hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
setEqualityPrecision(double)
call (or with absolute precision if that method was never called).
This method requires that the "equality precision", which can be set by
setEqualityPrecision(double)
method (and is 0.0 by default),
is the same for both segments. In other case, this method throws IllegalArgumentException.
This method returns true if:
UnsafeSegment2D
or Segment2D
).
getCenterX()
, getCenterY()
, getLength()
,
getFi()
) are equal for both segments. But some difference is still possible.
Namely, let ε is "equality precision" set by setEqualityPrecision(double)
method
(identical for both segments).
Two values A and B are considered "equal" here,
if A==B or if ε>0.0 and (int)(A/ε)==(int)(B/ε).
Of course, this algorithm works good only if all segment coordinatates,
divided by equality precision ε, are not too large (>>2^31) or too small (<<1.0).
Note: if the difference between directions is kπ or even 2kπ, the segments are not considered to be equal, though their ends are identical.
equals
in class java.lang.Object
java.lang.IllegalArgumentException
 if the passed argument is a segment,
but this and passed segments have different equality precisionpublic java.lang.Object clone()
clone
in class java.lang.Object
Www.alldisser.ru Стоимость защиты диссертации. Стоимость диссертации кандидатской www.alldisser.ru. www.alldisser.ru 