Rects- ClientRect, DOMRect, how do I instantiate a rect? Should I roll my own?

663 views
Skip to first unread message

Brennan Young

unread,
Nov 13, 2015, 7:57:01 AM11/13/15
to Haxe
I am using haxe 3.2 with html5 browsers as the runtime environment.

I am trying to check whether two rects overlap, one of which comes from getBoundingClientRect, the other I am trying to construct from a mouse position.

I've already discovered that ClientRect is deprecated. Haxe now has a class called DOMRect, but when I try to instantiate it, I get a "cannot be called" warning. I am using haxe 3.2 

In the haxe source it seems that the constructor for this class returns void, which doesn't make a lot of sense. The name is also pretty dumb, because I might be making rects which have no relation to the DOM.

Is it not possible to instantiate this thing? If so, what is the point of it?

[Also this class seems wholly underdefined. A decent rect class should have methods for intersects(rect) and inside(point), and maybe some other goodies such as offset, inflate etc.]

Do I have to make an anonymous 'rect' or use a map of floats instead?

Thank you in advance

Andreas Mokros

unread,
Nov 13, 2015, 9:17:56 AM11/13/15
to haxe...@googlegroups.com
Hi.

On Fri, 13 Nov 2015 04:57:01 -0800 (PST)
Brennan Young <gurun...@gmail.com> wrote:
> I've already discovered that ClientRect is deprecated. Haxe now has a class
> called DOMRect, but when I try to instantiate it, I get a "cannot be
> called" warning.

There is a comment:
/** @throws DOMError */
Maybe it's not meant to be instantiated (yet).

> In the haxe source it seems that the constructor for this class returns
> void, which doesn't make a lot of sense.

A constructor always returns Void in the definition.

> The name is also pretty dumb,
> because I might be making rects which have no relation to the DOM.

The class is just an extern to an interface that the browser provides:
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDOMClientRect
So Haxe devs are not responsible for the name nor the functionality.

> [Also this class seems wholly underdefined. A decent rect class should have
> methods for intersects(rect) and inside(point), and maybe some other
> goodies such as offset, inflate etc.]
> Do I have to make an anonymous 'rect' or use a map of floats instead?

Probably yes. Or find a js-lib that provides this functionality.

--
Mockey
Reply all
Reply to author
Forward
0 new messages