javamorph
Class CTriangle

java.lang.Object
  extended by javamorph.CTriangle
All Implemented Interfaces:
Comparator<Point>

public class CTriangle
extends Object
implements Comparator<Point>

Version:
1.1
Author:
claus.erhard.wimmer@googlemail.com
Program: JavaMorph V 1.1.
Class: CTriangle.
License: GPLv2.
Description: Data structure for triangulation of the mesh.
Hint: Relating to picture pixel units.

Field Summary
private  Point[] c
          All three corners of the triangle.
private  Point[] p
          All three corners of the triangle.
private  Point[] withins
          All pixel points within the triangle.
private  int x_max
          Rectangular border of the triangle.
private  int x_min
          Rectangular border of the triangle.
private  int y_max
          Rectangular border of the triangle.
private  int y_min
          Rectangular border of the triangle.
 
Constructor Summary
CTriangle(Point _p0, Point _p1, Point _p2)
          Copy constructor.
 
Method Summary
private  void calculateXBounds(int y)
          Calculate left & right edge point of the scan line.
 int compare(Point o1, Point o2)
          Due to comparator API.
 void debug(BufferedImage image)
          Draw the triangle to an image.
private  void drawLine(BufferedImage image, Point p1, Point p2)
          Debug one line to an image.
 boolean equals(Object obj)
          Equal if the sorted points are equal.
 Point[] getPoints()
          Get function.
 Point[] getWithins()
          Get function.
private  int getXIntersection(int y, Point p1, Point p2)
          Test
 int hashCode()
          Hash code calculated by sorted points.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

p

private Point[] p
All three corners of the triangle. (not sorted)


c

private Point[] c
All three corners of the triangle. (sorted by comparator)


withins

private Point[] withins
All pixel points within the triangle.


y_min

private int y_min
Rectangular border of the triangle.


y_max

private int y_max
Rectangular border of the triangle.


x_min

private int x_min
Rectangular border of the triangle.


x_max

private int x_max
Rectangular border of the triangle.

Constructor Detail

CTriangle

public CTriangle(Point _p0,
                 Point _p1,
                 Point _p2)
Copy constructor.

Parameters:
_p0 - First of the three points.
_p1 - Second of the three points.
_p2 - Third of the three points
Method Detail

getWithins

public Point[] getWithins()
Get function.

Returns:
All points within the triangle.

getPoints

public Point[] getPoints()
Get function.

Returns:
All three corner points.

debug

public void debug(BufferedImage image)
Draw the triangle to an image.

Parameters:
image - Image to draw the lines to.

hashCode

public int hashCode()
Hash code calculated by sorted points. See hash contract.

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Equal if the sorted points are equal. See has contract.

Specified by:
equals in interface Comparator<Point>
Overrides:
equals in class Object

compare

public int compare(Point o1,
                   Point o2)
Due to comparator API. Used as sort order for the points.

Specified by:
compare in interface Comparator<Point>

drawLine

private void drawLine(BufferedImage image,
                      Point p1,
                      Point p2)
Debug one line to an image.

Parameters:
image - Image to draw to.
p1 - First point.
p2 - Second point.

calculateXBounds

private void calculateXBounds(int y)
Calculate left & right edge point of the scan line. The scan line must cross two of the three edges. Seldom the scan line crosses one edge + two end points of the other both edges.

Parameters:
y - Vertical position of the scan line.

getXIntersection

private int getXIntersection(int y,
                             Point p1,
                             Point p2)
Test

Parameters:
y - Vertical position of the scan line.
p1 - First point of the edge line.
p2 - Second point of the edge line.
Returns:
X coordinate of the intersection point between edge & scan line.