Skip to content
Advertisement

How to Convert Point2D.Double’s to use aritmetic operator >

I have this code:

JavaScript

What I wanted to do is use the > arithmetic operation in Point2D.Double object. But as the following error says I cannot use arithmetic operators in Point2D.Double elements.

JavaScript

How can I modify my code to work with > operator and other aritmetic operators without changing the input elements of the function getMedianX?

Advertisement

Answer

The error is telling you exactly what is wrong. You can’t use arithmetic operators on Point2D.Double objects, and this makes sense since a Point2D represents both an X and a Y value in 2D space — which one are you comparing?

You will need to extract the double values that the Point2D object holds, which as per the API will require your calling either .getX() or .getY() (or both), and then use these in your arithmetic comparisons.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement