Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rect and RectF in Android SDK

What is the difference between Rect and RectF in the Android SDK?

like image 355
Iulius Curt Avatar asked Feb 06 '11 13:02

Iulius Curt


People also ask

What is RectF in Android?

android.graphics.RectF. RectF holds four float coordinates for a rectangle. The rectangle is represented by the coordinates of its 4 edges (left, top, right, bottom). These fields can be accessed directly. Use width() and height() to retrieve the rectangle's width and height.

What is Android path?

android.graphics.Path. The Path class encapsulates compound (multiple contour) geometric paths consisting of straight line segments, quadratic curves, and cubic curves. It can be drawn with canvas.


2 Answers

Using Rect you define its edges using integers and using RectF they are defined as floats.

Looking at them more carefully I have spotted a few differences actually. I will only list what one implementation has more compared to the other one.

Rect

  • equals(Object obj) (for some reason it has its own implementation of equals)
  • exactCenterX()
  • exactCenterY()
  • flattenToString()
  • toShortString()
  • unflattenFromString(String str)

RectF

  • round(Rect dst)
  • roundOut(Rect dst)
  • set(Rect src)

So apparently there are some differences.

like image 166
Octavian A. Damiean Avatar answered Sep 20 '22 14:09

Octavian A. Damiean


Rect is final, RectF can be extended

like image 42
JayJay Avatar answered Sep 18 '22 14:09

JayJay