Skip to content

Commit 40d6169

Browse files
committed
Add contains method to Shape and update docs
Introduces the contains(x, y, options) method to the Shape class for hit testing, with options for visibility and tolerance. Updates documentation for Shape and Two to reflect the new method and other API changes, including version bump to v0.8.22 and new getShapesAtPoint method in Two.
1 parent e181ee6 commit 40d6169

File tree

4 files changed

+322
-184
lines changed

4 files changed

+322
-184
lines changed

src/shape.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,25 @@ export class Shape extends Element {
204204
* @description Remove self from the scene / parent.
205205
*/
206206
remove() {
207-
if (!this.parent) {
208-
return this;
209-
}
207+
if (!this.parent) {
208+
return this;
209+
}
210210

211-
this.parent.remove(this);
211+
this.parent.remove(this);
212212

213-
return this;
213+
return this;
214214
}
215215

216+
/**
217+
* @name Two.Shape#contains
218+
* @function
219+
* @param {Number} x - x coordinate to hit test against
220+
* @param {Number} y - y coordinate to hit test against
221+
* @param {Object} [options] - Optional options object
222+
* @param {Boolean} options.ignoreVisibility - If `true`, hit test against `shape.visible = false` shapes
223+
* @param {Number} options.tolerance - Padding to hit test against in pixels
224+
* @description Remove self from the scene / parent.
225+
*/
216226
contains(x, y, options) {
217227
const opts = options || {};
218228
const ignoreVisibility = opts.ignoreVisibility === true;
@@ -234,8 +244,7 @@ export class Shape extends Element {
234244
return false;
235245
}
236246

237-
const tolerance =
238-
typeof opts.tolerance === 'number' ? opts.tolerance : 0;
247+
const tolerance = typeof opts.tolerance === 'number' ? opts.tolerance : 0;
239248

240249
this._update(true);
241250

0 commit comments

Comments
 (0)