public class DefaultLabelModelParameterFinder extends Object implements ILabelModelParameterFinder
ILabelModelParameterFinder
interface that uses the ILabelModel
's
own ILabelModelParameterProvider
instance to find the closest match.
This implementation uses a metric to find the closest of the provided parameter candidates to the layout provided in
findBestParameter(ILabel, IOrientedRectangle, Iterable)
.
Modifier and Type | Field and Description |
---|---|
static DefaultLabelModelParameterFinder |
INSTANCE
A singleton instance of this class.
|
Constructor and Description |
---|
DefaultLabelModelParameterFinder() |
Modifier and Type | Method and Description |
---|---|
protected double |
calculateMetric(ILabel label,
ILabelModelParameter layoutParameter,
IOrientedRectangle layout)
Calculates a metric for the given label/parameter pair and the target label layout.
|
protected double |
distance(IOrientedRectangle rectangle1,
IOrientedRectangle rectangle2)
Returns the distance between two
IOrientedRectangle instances. |
ILabelModelParameter |
findBestParameter(ILabel label,
ILabelModel model,
IOrientedRectangle layout)
Tries to find a parameter that best matches the given layout for the provided label instance.
|
ILabelModelParameter |
findBestParameter(ILabel label,
IOrientedRectangle layout,
Iterable<ILabelModelParameter> layoutParameters)
Tries to find a parameter that best matches the given layout for the provided label instance among the set of given
parameters.
|
protected Iterable<ILabelModelParameter> |
getCandidateParameters(ILabel label,
ILabelModel model)
Retrieves an enumerator over all candidates for a given label and model.
|
public static final DefaultLabelModelParameterFinder INSTANCE
protected double calculateMetric(ILabel label, ILabelModelParameter layoutParameter, IOrientedRectangle layout)
This implementation gets the geometry from the parameter's model's ILabelModel.getGeometry(ILabel, ILabelModelParameter)
method and returns the result of a call to distance(IOrientedRectangle, IOrientedRectangle)
.
label
- The label to apply the parameter to.layoutParameter
- The parameter candidate.layout
- The targeted layout rectangle.protected final double distance(IOrientedRectangle rectangle1, IOrientedRectangle rectangle2)
IOrientedRectangle
instances.
The distance is calculated using the Euclidean distance between the two centers and the angular deviation between the two up vectors.
rectangle1
- The first geometry.rectangle2
- The geometry to compare the first one with.public final ILabelModelParameter findBestParameter(ILabel label, ILabelModel model, IOrientedRectangle layout)
This method may not necessarily find a parameter that matches the provided layout exactly. It will first query the getCandidateParameters(ILabel, ILabelModel)
parameter for an enumeration of candidates and will then find the best matching candidate using a metric calculated by
calculateMetric(ILabel, ILabelModelParameter, IOrientedRectangle)
. If no parameter can be found this method
returns the default parameter
for the model.
findBestParameter
in interface ILabelModelParameterFinder
label
- The label to find a parameter for.model
- The model instance to use. This should be the instance this instance has been obtained from.layout
- The anticipated layout for the label.null
parameter that can be used for the label to approximate the provided layout.public final ILabelModelParameter findBestParameter(ILabel label, IOrientedRectangle layout, Iterable<ILabelModelParameter> layoutParameters)
Null may be returned if an empty enumerable is passed.
label
- The label to find a parameter for.layout
- The anticipated layout for the label.layoutParameters
- A set of parameters to choose from.protected Iterable<ILabelModelParameter> getCandidateParameters(ILabel label, ILabelModel model)
label
- The label.model
- The model of the label.