nodebox.graphics
Class Geometry

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

public class Geometry
extends AbstractGeometry
implements Colorizable


Field Summary
 
Fields inherited from interface nodebox.graphics.IGeometry
DEFAULT_POINT_AMOUNT
 
Constructor Summary
Geometry()
           
Geometry(Geometry other)
           
 
Method Summary
 void add(Geometry geometry)
          Convenience function that extends the current geometry with the given geometry.
 void add(Path path)
          Add geometry to the group.
 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.
 void clear()
           
 Geometry clone()
          Clone the geometry, returning a new copy that is totally independent from the original.
 boolean contains(double x, double y)
           
 boolean contains(Point pt)
           
 boolean contains(Rect r)
           
 void draw(Graphics2D g)
           
 void extend(Geometry g)
          Create copies of all paths in the given group and append them to myself.
 void flatten()
          Flatten the geometry.
 IGeometry flattened()
          Make a flattened copy of the geometry.
 Rect getBounds()
          Returns the bounding box of all elements in the group.
 double getLength()
          Calculate the length of the path.
 List<Path> getPaths()
          Get the subshapes of a geometry object.
 int getPointCount()
           
 List<Point> getPoints()
          Get the points for this geometry.
 boolean intersects(Geometry g2)
           
 boolean intersects(Path p)
           
 void invalidate()
          Invalidates the cache.
 boolean isClosed()
          Check if the last path in this group is closed.
 boolean isEmpty()
          Check if the group contains any paths.
 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 pointAt(double t)
          Returns coordinates for point at t on the group.
 Geometry resampleByAmount(int amount, boolean perContour)
          Generate new geometry with the given amount of points along the shape of the original geometry.
 Geometry resampleByLength(double segmentLength)
          Generate new geometry with points along the shape of the original geometry, spaced at the given length.
 void setFill(Color c)
           
 void setFillColor(Color fillColor)
           
 void setStroke(Color c)
           
 void setStrokeColor(Color strokeColor)
           
 void setStrokeWidth(double strokeWidth)
           
 int size()
           
 String toString()
           
 void transform(Transform t)
           
 
Methods inherited from class nodebox.graphics.AbstractGeometry
extend, extend, makePoints, 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, wait, wait, wait
 
Methods inherited from interface nodebox.graphics.Grob
getTransformDelegate, rotate, rotateRadians, scale, scale, setTransformDelegate, skew, skew, translate
 

Constructor Detail

Geometry

public Geometry()

Geometry

public Geometry(Geometry other)
Method Detail

getPaths

public List<Path> getPaths()
Get the subshapes of a geometry object.

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

Returns:
a list of primitives

add

public void add(Path path)
Add geometry to the group.

Added geometry is not cloned.

Parameters:
path - the geometry to add.

add

public void add(Geometry geometry)
Convenience function that extends the current geometry with the given geometry.

Alias for extend().

Parameters:
geometry - the geometry to add.
See Also:
extend(Geometry)

size

public int size()

isEmpty

public boolean isEmpty()
Check if the group contains any paths. This method does not check if the paths themselves are empty.

Specified by:
isEmpty in interface Grob
Returns:
true if the group contains no paths.

clear

public void clear()

extend

public void extend(Geometry g)
Create copies of all paths in the given group and append them to myself.

Parameters:
g - the group whose paths are appended.

isClosed

public boolean isClosed()
Check if the last path in this group is closed.

A group (or path) can't technically be called "closed", only specific contours in the path can. This method provides a reasonable heuristic for a "closed" group by checking the closed state of the last contour on the last path. It returns false if this path contains no contours.

Returns:
true if the last contour on the last path is closed.

setFillColor

public void setFillColor(Color fillColor)
Specified by:
setFillColor in interface Colorizable

setFill

public void setFill(Color c)
Specified by:
setFill in interface Colorizable

setStrokeColor

public void setStrokeColor(Color strokeColor)
Specified by:
setStrokeColor in interface Colorizable

setStroke

public void setStroke(Color c)
Specified by:
setStroke in interface Colorizable

setStrokeWidth

public void setStrokeWidth(double strokeWidth)
Specified by:
setStrokeWidth in interface Colorizable

getPointCount

public int getPointCount()
Specified by:
getPointCount in interface IGeometry

getPoints

public List<Point> getPoints()
Get the points for this geometry.

This returns a live reference to the points of the geometry. Changing the points will change the geometry.

Specified by:
getPoints in interface IGeometry
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.

Specified by:
addPoint in interface IGeometry
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.

Specified by:
addPoint in interface IGeometry
Parameters:
x - the X coordinate.
y - the Y coordinate.

invalidate

public void invalidate()
Invalidates the cache. Querying the path length or asking for getGeneralPath will return an up-to-date result.

This operation recursively invalidates all underlying geometry.

Cache invalidation happens automatically when using the Path methods, such as rect/ellipse, or container operations such as add/extend/clear. You should invalidate the cache when manually changing the point positions or adding points to the underlying contours.

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


getBounds

public Rect getBounds()
Returns the bounding box of all elements in the group.

Specified by:
getBounds in interface Grob
Returns:
a bounding box that contains all elements in the group.

getLength

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

Returns:
the length of the path.

pointAt

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

Gets the length of the group, based on the length of each path in the group. Determines in what path t falls. Gets the point on that path.

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.

contains

public boolean contains(Point pt)

contains

public boolean contains(double x,
                        double y)

contains

public boolean contains(Rect r)

intersects

public boolean intersects(Geometry g2)

intersects

public boolean intersects(Path p)

makePoints

public Point[] makePoints(int amount,
                          boolean perContour)
Description copied from interface: IGeometry
Make new points along the contours of the existing path.

Points are evenly distributed according to the length of each geometric object.

Specified by:
makePoints in interface IGeometry
Parameters:
amount - the amount of points to distribute.
perContour - if true, the points are distributed per contour. The amount of points returned will then be number of contours * amount.
Returns:
a list of Points.

resampleByAmount

public Geometry resampleByAmount(int amount,
                                 boolean perContour)
Description copied from interface: IGeometry
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.

Specified by:
resampleByAmount in interface IGeometry
Parameters:
amount - the number of points to generate.
perContour - whether the given points are per contour, or for the entire geometry.
Returns:
a new geometry object. This method will return whatever comes out of it, so calling resample on a Contour will return a new Contour object.

resampleByLength

public Geometry resampleByLength(double segmentLength)
Description copied from interface: IGeometry
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.

Specified by:
resampleByLength in interface IGeometry
Parameters:
segmentLength - the maximum length of each resampled segment.
Returns:
a new geometry object. This object will be of the same type as the callee, so calling resample on a Contour will return a new Contour object.

transform

public void transform(Transform t)
Specified by:
transform in interface Grob

draw

public void draw(Graphics2D g)
Specified by:
draw in interface Drawable

flatten

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

Specified by:
flatten in interface IGeometry

flattened

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

Specified by:
flattened in interface IGeometry
Returns:
a flattened copy.

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 Geometry 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 Colorizable
Specified by:
clone in interface Grob
Specified by:
clone in interface IGeometry
Specified by:
clone in class AbstractGeometry
Returns:
the new geometry object.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013. All Rights Reserved.