Change getInteriorPoint type to XYM with intersection length as M
This commit is contained in:
@@ -14,7 +14,8 @@ goog.require('ol.geom.flat.contains');
|
||||
* @param {Array.<number>} flatCenters Flat centers.
|
||||
* @param {number} flatCentersOffset Flat center offset.
|
||||
* @param {Array.<number>=} opt_dest Destination.
|
||||
* @return {Array.<number>} Destination.
|
||||
* @return {Array.<number>} Destination point as XYM coordinate, where M is the
|
||||
* length of the horizontal intersection that the point belongs to.
|
||||
*/
|
||||
ol.geom.flat.interiorpoint.linearRings = function(flatCoordinates, offset,
|
||||
ends, stride, flatCenters, flatCentersOffset, opt_dest) {
|
||||
@@ -61,10 +62,10 @@ ol.geom.flat.interiorpoint.linearRings = function(flatCoordinates, offset,
|
||||
pointX = flatCenters[flatCentersOffset];
|
||||
}
|
||||
if (opt_dest) {
|
||||
opt_dest.push(pointX, y);
|
||||
opt_dest.push(pointX, y, maxSegmentLength);
|
||||
return opt_dest;
|
||||
} else {
|
||||
return [pointX, y];
|
||||
return [pointX, y, maxSegmentLength];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -75,7 +76,8 @@ ol.geom.flat.interiorpoint.linearRings = function(flatCoordinates, offset,
|
||||
* @param {Array.<Array.<number>>} endss Endss.
|
||||
* @param {number} stride Stride.
|
||||
* @param {Array.<number>} flatCenters Flat centers.
|
||||
* @return {Array.<number>} Interior points.
|
||||
* @return {Array.<number>} Interior points as XYM coordinates, where M is the
|
||||
* length of the horizontal intersection that the point belongs to.
|
||||
*/
|
||||
ol.geom.flat.interiorpoint.linearRingss = function(flatCoordinates, offset, endss, stride, flatCenters) {
|
||||
var interiorPoints = [];
|
||||
|
||||
@@ -223,12 +223,13 @@ ol.geom.MultiPolygon.prototype.getFlatInteriorPoints = function() {
|
||||
|
||||
/**
|
||||
* Return the interior points as {@link ol.geom.MultiPoint multipoint}.
|
||||
* @return {ol.geom.MultiPoint} Interior points.
|
||||
* @return {ol.geom.MultiPoint} Interior points as XYM coordinates, where M is
|
||||
* the length of the horizontal intersection that the point belongs to.
|
||||
* @api
|
||||
*/
|
||||
ol.geom.MultiPolygon.prototype.getInteriorPoints = function() {
|
||||
var interiorPoints = new ol.geom.MultiPoint(null);
|
||||
interiorPoints.setFlatCoordinates(ol.geom.GeometryLayout.XY,
|
||||
interiorPoints.setFlatCoordinates(ol.geom.GeometryLayout.XYM,
|
||||
this.getFlatInteriorPoints().slice());
|
||||
return interiorPoints;
|
||||
};
|
||||
|
||||
@@ -210,11 +210,12 @@ ol.geom.Polygon.prototype.getFlatInteriorPoint = function() {
|
||||
|
||||
/**
|
||||
* Return an interior point of the polygon.
|
||||
* @return {ol.geom.Point} Interior point.
|
||||
* @return {ol.geom.Point} Interior point as XYM coordinate, where M is the
|
||||
* length of the horizontal intersection that the point belongs to.
|
||||
* @api
|
||||
*/
|
||||
ol.geom.Polygon.prototype.getInteriorPoint = function() {
|
||||
return new ol.geom.Point(this.getFlatInteriorPoint());
|
||||
return new ol.geom.Point(this.getFlatInteriorPoint(), ol.geom.GeometryLayout.XYM);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -195,4 +195,18 @@ describe('ol.geom.MultiPolygon', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#getInteriorPoints', function() {
|
||||
|
||||
it('returns XYM multipoint with intersection width as M', function() {
|
||||
var geom = new ol.geom.MultiPolygon([
|
||||
[[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]],
|
||||
[[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]
|
||||
]);
|
||||
var interiorPoints = geom.getInteriorPoints();
|
||||
expect(interiorPoints.getType()).to.be('MultiPoint');
|
||||
expect(interiorPoints.layout).to.be('XYM');
|
||||
expect(interiorPoints.getCoordinates()).to.eql([[0.5, 0.5, 1], [1.5, 1.5, 1]]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -541,6 +541,17 @@ describe('ol.geom.Polygon', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#getInteriorPoint', function() {
|
||||
|
||||
it('returns XYM point with intersection width as M', function() {
|
||||
var geom = new ol.geom.Polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]);
|
||||
var interiorPoint = geom.getInteriorPoint();
|
||||
expect(interiorPoint.getType()).to.be('Point');
|
||||
expect(interiorPoint.layout).to.be('XYM');
|
||||
expect(interiorPoint.getCoordinates()).to.eql([0.5, 0.5, 1]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.Polygon.fromExtent', function() {
|
||||
it('creates the correct polygon', function() {
|
||||
var extent = [1, 2, 3, 5];
|
||||
|
||||
Reference in New Issue
Block a user