nodebox.graphics
Class Contour

java.lang.Object
  extended by nodebox.graphics.AbstractTransformable
      extended by nodebox.graphics.AbstractGeometry
          extended by nodebox.graphics.Contour
All Implemented Interfaces:
Cloneable, Drawable, Grob, IGeometry

public class Contour
extends AbstractGeometry


Field Summary
 
Fields inherited from interface nodebox.graphics.IGeometry
DEFAULT_POINT_AMOUNT
 
Constructor Summary
Contour()
           
Contour(Contour other)
           
Contour(Iterable<Point> points, boolean closed)
           
 
Method Summary
 void addPoint(double x, double y)
          Add a new point to the geometry specified by its x and y coordinates.
 void addPoint(Point pt)
          Add the given point to the geometry.
 Contour clone()
          Clone the geometry, returning a new copy that is totally independent from the original.
 void close()
           
 void draw(Graphics2D g)
           
 void flatten()
          Flatten the geometry.
 IGeometry flattened()
          Make a flattened copy of the geometry.
 Rect getBounds()
           
 double getLength()
          Calculate the length of the contour.
 int getPointCount()
           
 List<Point> getPoints()
          Get the points for this geometry.
 void invalidate()
          Invalidates the cache.
 boolean isClosed()
           
 boolean isEmpty()
           
 Point[] makePoints(int amount)
          Make new points along the contours of the existing path.
 Point[] makePoints(int amount, boolean perContour)
          Make new points along the contours of the existing path.
 AbstractGeometry mapPoints(com.google.common.base.Function<Point,Point> pointFunction)
          Change all points in the geometry and return a mutated copy.
 Point point(double t)
          Same as pointAt(t).
 Point pointAt(double t)
          Returns coordinates for point at t on the path.
 Contour resampleByAmount(int amount)
          Generate new geometry with the given amount of points along the shape of the original geometry.
 Contour resampleByAmount(int amount, boolean perContour)
          Generate new geometry with the given amount of points along the shape of the original geometry.
 Contour resampleByLength(double segmentLength)
          Generate new geometry with points along the shape of the original geometry, spaced at the given length.
 void setClosed(boolean closed)
           
 Path toPath()
           
 void transform(Transform t)
           
 double updateSegmentLengths()
           
 
Methods inherited from class nodebox.graphics.AbstractGeometry
extend, extend, makePoints, pointDelta
 
Methods inherited from class nodebox.graphics.AbstractTransformable
getTransformDelegate, rotate, rotateRadians, scale, scale, setTransformDelegate, skew, skew, translate
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface nodebox.graphics.Grob
getTransformDelegate, rotate, rotateRadians, scale, scale, setTransformDelegate, skew, skew, translate
 

Constructor Detail

Contour

public Contour()

Contour

public Contour(Contour other)

Contour

public Contour(Iterable<Point> points,
               boolean closed)
Method Detail

getPointCount

public int getPointCount()

getPoints

public List<Point> getPoints()
Description copied from interface: IGeometry
Get the points for this geometry.

This method returns live references to the points. Changing them will change the original geometry.

Returns:
a list of Points.

addPoint

public void addPoint(Point pt)
Description copied from interface: IGeometry
Add the given point to the geometry. The point is cloned.

Parameters:
pt - the point to add.

addPoint

public void addPoint(double x,
                     double y)
Description copied from interface: IGeometry
Add a new point to the geometry specified by its x and y coordinates.

Parameters:
x - the X coordinate.
y - the Y coordinate.

isClosed

public boolean isClosed()

setClosed

public void setClosed(boolean closed)

close

public void close()

isEmpty

public boolean isEmpty()

getBounds

public Rect getBounds()

invalidate

public void invalidate()
Invalidates the cache. Querying the contour length or calling makePoints/resample will an up-to-date result.

Cache invalidation happens automatically when using the Contour methods, such as addPoint/close. You should invalidate the cache only after manually changing the point positions.

Invalidating the cache is a lightweight operation; it doesn't recalculate anything. Only when querying the new length will the values be recalculated.


updateSegmentLengths

public double updateSegmentLengths()

getLength

public double getLength()
Calculate the length of the contour. This is not the number of segments, but rather the sum of all segment lengths.

Returns:
the length of the contour

pointAt

public Point pointAt(double t)
Returns coordinates for point at t on the path.

Gets the length of the path, based on the length of each curve and line in the path. Determines in what segment t falls. Gets the point on that segment.

Specified by:
pointAt in class AbstractGeometry
Parameters:
t - relative coordinate of the point (between 0.0 and 1.0) Results outside of this range are undefined.
Returns:
coordinates for point at t.

point

public Point point(double t)
Same as pointAt(t).

This method is here for compatibility with NodeBox 1.

Parameters:
t - relative coordinate of the point.
Returns:
coordinates for point at t.
See Also:
pointAt(double)

makePoints

public Point[] makePoints(int amount)
Make new points along the contours of the existing path.

Specified by:
makePoints in interface IGeometry
Overrides:
makePoints in class AbstractGeometry
Parameters:
amount - the number of points to create.
Returns:
a list with "amount" points or zero points if the contour is empty.

makePoints

public Point[] makePoints(int amount,
                          boolean perContour)
Make new points along the contours of the existing path.

Parameters:
amount - the amount of points to distribute.
perContour - this port was added to comply with the IGeometry interface, but is ignored since we're at the contour level.
Returns:
a list with "amount" points or zero points if the contour is empty.

resampleByAmount

public Contour resampleByAmount(int amount,
                                boolean perContour)
Generate new geometry with the given amount of points along the shape of the original geometry.

The length of each segment is not given and will be determined based on the required number of points.

Parameters:
amount - the number of points to generate.
perContour - this port is ignored since we're at the contour level.
Returns:
a new Contour with the given number of points.

resampleByAmount

public Contour resampleByAmount(int amount)
Generate new geometry with the given amount of points along the shape of the original geometry.

The length of each segment is not given and will be determined based on the required number of points.

Parameters:
amount - the number of points to generate.
Returns:
a new Contour with the given number of points.

resampleByLength

public Contour resampleByLength(double segmentLength)
Generate new geometry with points along the shape of the original geometry, spaced at the given length.

The number of points is not given and will be determined by the system based on the segment length. Note that the last segment may be shorter than the given segment length.

Parameters:
segmentLength - the maximum length of each resampled segment.
Returns:
a new Contour with segments of the given length.

flatten

public void flatten()
Description copied from interface: IGeometry
Flatten the geometry.


flattened

public IGeometry flattened()
Description copied from interface: IGeometry
Make a flattened copy of the geometry.

Returns:
a flattened copy.

draw

public void draw(Graphics2D g)

transform

public void transform(Transform t)

toPath

public Path toPath()

mapPoints

public AbstractGeometry mapPoints(com.google.common.base.Function<Point,Point> pointFunction)
Description copied from class: AbstractGeometry
Change all points in the geometry and return a mutated copy. The original geometry remains unchanged.

Specified by:
mapPoints in class AbstractGeometry
Parameters:
pointFunction - The function to apply to each point.
Returns:
The new geometry.

clone

public Contour clone()
Description copied from interface: IGeometry
Clone the geometry, returning a new copy that is totally independent from the original.

Specified by:
clone in interface Grob
Specified by:
clone in interface IGeometry
Specified by:
clone in class AbstractGeometry
Returns:
the new geometry object.


Copyright © 2013. All Rights Reserved.