org.shapelogic.polygon
Class Polygon

java.lang.Object
  extended by org.shapelogic.polygon.BaseAnnotatedShape
      extended by org.shapelogic.polygon.Polygon
All Implemented Interfaces:
java.lang.Cloneable, Calc0<Polygon>, CalcInvoke<Polygon>, CalcValue<Polygon>, LazyCalc<Polygon>, AnnotatedShape, GeometricShape2D, IPolygon2D, PointReplacable<Polygon>
Direct Known Subclasses:
MultiLinePolygon

public class Polygon
extends BaseAnnotatedShape
implements IPolygon2D, CalcInvoke<Polygon>, java.lang.Cloneable, PointReplacable<Polygon>

Polygon is the bottom class for polygon works for points on any kind Almost immutable: you can extend it by adding more but you cannot change the element, and the underlying points are mutable. So point should not be changed after they are added. Note that this and the sub class MultiLinePolygon has the exactly same interface

Author:
Sami Badawi

Field Summary
protected  AnnotatedShapeImplementation _annotatedShape
           
protected  double _aspectRatio
           
protected  BBox _bBox
           
protected  boolean _closed
           
protected  MultiLine _currentMultiLine
           
protected  boolean _dirty
           
protected  int _endPointCount
           
protected  java.util.List<java.util.Set<IPoint2D>> _endPointsClusters
           
protected  java.util.Set<CLine> _lines
           
protected  java.lang.Double _perimeter
           
protected  java.util.Set<IPoint2D> _points
           
protected  java.util.Map<IPoint2D,java.lang.Integer> _pointsCountMap
           
protected  java.util.Map<IPoint2D,java.util.Set<CLine>> _pointsToLineMap
           
protected  java.util.List<Improver<Polygon>> _polygonImprovers
           
protected  int _version
           
 
Constructor Summary
Polygon()
           
Polygon(AnnotatedShapeImplementation annotatedShape)
           
 
Method Summary
 void addAfterEnd(IPoint2D newPoint)
           
 void addBeforeStart(IPoint2D newPoint)
           
protected  CLine addIndependentLine(CLine line)
          Most of the time this should not be used use the version taking input points instead
 CLine addIndependentLine(IPoint2D point1, IPoint2D point2)
          To have the same interface as MultiLinePolygon
protected  CLine addLine(CLine line)
          Deprecated. 
 CLine addLine(IPoint2D point1, IPoint2D point2)
          this should not be used use addIndependentLine() instead
 void addMultiLine(MultiLine multiLine)
           
 Polygon cleanUp(boolean onlyInt, double procentage)
          Return a cleaned up polygon
 java.lang.Object clone()
           
 boolean containsLine(ILine2D line)
           
 boolean containsPoint(IPoint2D point)
           
 void endMultiLine()
          Add all the lines segments in the multi line to _lines
<Element> java.util.Collection<Element>
filter(IFilter<Polygon,Element> filterObject)
           
<Element> java.util.Collection<Element>
filter(java.lang.String inputExpression)
           
 int findPointCount()
           
 double getAspectRatio()
           
 BBox getBBox()
           
 IPoint2D getCenter()
           
 MultiLine getCurrentMultiLine()
           
 double getDiameter()
           
 int getEndPointCount()
           
 java.util.List<java.util.Set<IPoint2D>> getEndPointsClusters()
           
 java.util.List<java.util.Set<IPoint2D>> getEndPointsMultiClusters()
           
 int getHoleCount()
           
 java.util.List<CLine> getHorizontalLines()
           
 java.util.Set<CLine> getIndependentLines()
          To have the same interface as MultiLinePolygon
 java.util.Set<CLine> getLines()
           
 java.util.Collection<CLine> getLinesForPoint(IPoint2D point)
           
 java.util.List<MultiLine> getMultiLines()
          To have the same interface as MultiLinePolygon returns null since this and the independent lines are supposed to be all the lines
 java.lang.Double getPerimeter()
           
 java.util.Set<IPoint2D> getPoints()
           
 java.util.Map<IPoint2D,java.lang.Integer> getPointsCountMap()
          Find how many lines each point is part of by making a map
 java.util.Map<IPoint2D,java.util.Set<CLine>> getPointsToLineMap()
          Find how many lines each point is part of by making a map
 Polygon getValue()
          Starts a lazy calculation.
 int getVersion()
           
 java.util.List<CLine> getVerticalLines()
           
 Polygon improve()
          register a list of improvers and call them here
protected  void internalFactory()
          All the objects that needs special version should be created here.
 java.lang.String internalInfo(java.lang.StringBuffer sb)
           
 Polygon invoke()
           
 boolean isClosed()
           
 boolean isDirty()
          When dirty is false that means that the calculated value can be used
 java.lang.String printAnnotation(java.lang.StringBuffer result)
           
 Polygon replacePointsInMap(java.util.Map<IPoint2D,IPoint2D> pointReplacementMap, AnnotatedShapeImplementation annotatedShape)
          No filtering in first version
 void setPerimeter(java.lang.Double perimeter)
           
 void setPolygonImprovers(java.util.List<Improver<Polygon>> improvers)
           
 void setup()
          Currently not super well define used for 2 purposes: Reset: called from the outside if you want to reuse it init: Called from the inside when calculation start to have everything setup maybe the semantic could work for both? TODO: This should be separated better.
 void setVersion(int version)
           
 void startMultiLine()
           
 java.lang.String toString()
           
 
Methods inherited from class org.shapelogic.polygon.BaseAnnotatedShape
getAnnotatedShape, getAnnotationForShapes, getMap, getShapesForAnnotation, putAllAnnotation, putAnnotation
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_bBox

protected BBox _bBox

_lines

protected java.util.Set<CLine> _lines

_points

protected java.util.Set<IPoint2D> _points

_dirty

protected boolean _dirty

_aspectRatio

protected double _aspectRatio

_closed

protected boolean _closed

_endPointCount

protected int _endPointCount

_pointsCountMap

protected java.util.Map<IPoint2D,java.lang.Integer> _pointsCountMap

_pointsToLineMap

protected java.util.Map<IPoint2D,java.util.Set<CLine>> _pointsToLineMap

_version

protected int _version

_currentMultiLine

protected MultiLine _currentMultiLine

_endPointsClusters

protected java.util.List<java.util.Set<IPoint2D>> _endPointsClusters

_annotatedShape

protected AnnotatedShapeImplementation _annotatedShape

_polygonImprovers

protected java.util.List<Improver<Polygon>> _polygonImprovers

_perimeter

protected java.lang.Double _perimeter
Constructor Detail

Polygon

public Polygon()

Polygon

public Polygon(AnnotatedShapeImplementation annotatedShape)
Method Detail

internalFactory

protected void internalFactory()
All the objects that needs special version should be created here.


getBBox

public BBox getBBox()
Specified by:
getBBox in interface IPolygon2D

getLines

public java.util.Set<CLine> getLines()
Specified by:
getLines in interface IPolygon2D

getPoints

public java.util.Set<IPoint2D> getPoints()
Specified by:
getPoints in interface IPolygon2D

getAspectRatio

public double getAspectRatio()
Specified by:
getAspectRatio in interface IPolygon2D

isClosed

public boolean isClosed()
Specified by:
isClosed in interface IPolygon2D

isDirty

public boolean isDirty()
Description copied from interface: LazyCalc
When dirty is false that means that the calculated value can be used

Specified by:
isDirty in interface LazyCalc<Polygon>

setup

public void setup()
Description copied from interface: LazyCalc
Currently not super well define used for 2 purposes: Reset: called from the outside if you want to reuse it init: Called from the inside when calculation start to have everything setup maybe the semantic could work for both? TODO: This should be separated better.

Specified by:
setup in interface LazyCalc<Polygon>
Specified by:
setup in interface AnnotatedShape
Overrides:
setup in class BaseAnnotatedShape

containsPoint

public boolean containsPoint(IPoint2D point)

containsLine

public boolean containsLine(ILine2D line)

addLine

public CLine addLine(IPoint2D point1,
                     IPoint2D point2)
this should not be used use addIndependentLine() instead


addLine

@Deprecated
protected CLine addLine(CLine line)
Deprecated. 

this should not be used use addIndependentLine() instead


invoke

public Polygon invoke()
Specified by:
invoke in interface Calc0<Polygon>

cleanUp

public Polygon cleanUp(boolean onlyInt,
                       double procentage)
Return a cleaned up polygon

Parameters:
onlyInt - Change all coordinates to integers
procentage - of diagonal of b box that should be considered as same point

improve

public Polygon improve()
register a list of improvers and call them here


getValue

public Polygon getValue()
Description copied from interface: CalcValue
Starts a lazy calculation. If dirty do calc() else return cached value. This should maybe be moved up in the hierarchy

Specified by:
getValue in interface CalcValue<Polygon>

getVerticalLines

public java.util.List<CLine> getVerticalLines()

getHorizontalLines

public java.util.List<CLine> getHorizontalLines()

getPointsCountMap

public java.util.Map<IPoint2D,java.lang.Integer> getPointsCountMap()
Find how many lines each point is part of by making a map


getPointsToLineMap

public java.util.Map<IPoint2D,java.util.Set<CLine>> getPointsToLineMap()
Find how many lines each point is part of by making a map


findPointCount

public int findPointCount()

getEndPointCount

public int getEndPointCount()

getLinesForPoint

public java.util.Collection<CLine> getLinesForPoint(IPoint2D point)

getVersion

public int getVersion()

setVersion

public void setVersion(int version)

startMultiLine

public void startMultiLine()

addBeforeStart

public void addBeforeStart(IPoint2D newPoint)

addAfterEnd

public void addAfterEnd(IPoint2D newPoint)

endMultiLine

public void endMultiLine()
Add all the lines segments in the multi line to _lines


addMultiLine

public void addMultiLine(MultiLine multiLine)

getCurrentMultiLine

public MultiLine getCurrentMultiLine()

getEndPointsClusters

public java.util.List<java.util.Set<IPoint2D>> getEndPointsClusters()

getEndPointsMultiClusters

public java.util.List<java.util.Set<IPoint2D>> getEndPointsMultiClusters()

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

replacePointsInMap

public Polygon replacePointsInMap(java.util.Map<IPoint2D,IPoint2D> pointReplacementMap,
                                  AnnotatedShapeImplementation annotatedShape)
No filtering in first version

Specified by:
replacePointsInMap in interface PointReplacable<Polygon>

getCenter

public IPoint2D getCenter()
Specified by:
getCenter in interface GeometricShape2D

getDiameter

public double getDiameter()
Specified by:
getDiameter in interface GeometricShape2D

setPolygonImprovers

public void setPolygonImprovers(java.util.List<Improver<Polygon>> improvers)

addIndependentLine

public CLine addIndependentLine(IPoint2D point1,
                                IPoint2D point2)
To have the same interface as MultiLinePolygon


addIndependentLine

protected CLine addIndependentLine(CLine line)
Most of the time this should not be used use the version taking input points instead


getIndependentLines

public java.util.Set<CLine> getIndependentLines()
To have the same interface as MultiLinePolygon


getMultiLines

public java.util.List<MultiLine> getMultiLines()
To have the same interface as MultiLinePolygon returns null since this and the independent lines are supposed to be all the lines


filter

public <Element> java.util.Collection<Element> filter(IFilter<Polygon,Element> filterObject)

filter

public <Element> java.util.Collection<Element> filter(java.lang.String inputExpression)

getHoleCount

public int getHoleCount()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

internalInfo

public java.lang.String internalInfo(java.lang.StringBuffer sb)

printAnnotation

public java.lang.String printAnnotation(java.lang.StringBuffer result)

getPerimeter

public java.lang.Double getPerimeter()

setPerimeter

public void setPerimeter(java.lang.Double perimeter)


Copyright © 2009. All Rights Reserved.