技术标签: RectF Android 自定义控件 Rect android 自定义 Android
Rect()
Rect(int left,int top,int right,int bottom)
Rect(Rect r)
public final boolean isEmpty(){
return left>=right ||top>= bottom;
}
判断 Rect 是否为空,也就是矩形区域面积是否为 0 或者为无效矩形。
public final int width(){
return right - left;
}
返回矩形的宽度。
public final int height(){
return bottom - top;
}
返回矩形的高度。
public final int centerX(){
return (left + right) >> 1;
}
计算矩形中心点的 x 坐标,右移一位相当于除以 2,移位运算比普通的除法运算效率
更高。
public final int centerY(){
return (top + bottom) >> 1;
}
计算矩形中心点的 y 坐标。
public final float exactCenterX(){
return (left + right) * 0.5f;
}
计算矩形中心点的 x 坐标,返回 float 类型,结果更精确。
public final float exactCenterY(){
return (top + bottom) * 0.5f;
}
计算矩形中心点的 y 坐标,返回 float 类型,结果更精确。
public void setEmpty(){
left = right = top = bottom = 0;
}
将矩形的 left、top、right 和 bottom 置 0。
public void set(int left,int top,int right,int bottom){
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
给 left、top、right 和 bottom 重新赋值。
public void set(Rect src){
this.left = src.left;
this.top = src.top;
this.right = src.right;
this.bottom = src.bottom;
}
public void offset(int dx,int dy){
left += dx;
top += dy;
right += dx;
bottom += dy;
}
矩形的 left 和 right 同时移动相同的距离 dx,矩形的 top 和 bottom 同时移动相同的距
离 dy,实际上就是将矩形移动(dx、dy)距离,正负决定移动的方向。
public void offsetTo(int newLeft,int newTop){
right += newLeft - left;
bottom += newTop - top;
left = newLeft;
top = newTop;
}
offsetTo()方法也是移位,和 offset()不同的是前者是绝对定位,后者是相对定位。
public void inset(int dx,int dy){
left += dx;
top += dy;
right -= dx;
bottom -= dy;
}
实现了矩形的缩放功能,缩放中心点就是矩形的中心点,要注意的是 dx、dy 为正数时
public boolean contains(int x,int y){
return left < right && top < bottom
&& x >= left && x < right && y >= top && y < bottom;
}
判断点(x,y)是否位于矩形内。
public boolean contains(int left,int top,int right,int bottom){
return this.left < this.right && this.top < this.bottom
&& this.left <= left && this.top <= top
&& this.right >= right && this.bottom >= bottom;
}
判断传递过来的矩形是否位于矩形内。
public boolean contains(Rect r){
return this.left < this.right && this.top < this.bottom
&& left <= r.left && top <= r.top && right >= r.right && bottom >= r.bottom;
}
判断传递过来的矩形是否位于矩形内。
public boolean intersect(int left,int top,int right,int bottom){
if (this.left < right && left < this.right && this.top < bottom && top < this.bottom) {
if (this.left < left) this.left = left;
if (this.top < top) this.top = top;
if (this.right > right) this.right = right;
if (this.bottom > bottom) this.bottom = bottom;
return true;
}
return false;
}
传入 Rect 的 left、top、right、bottom,并将构建的 Rect 对象与当前 Rect 对象做交集运算,结果保存在当前 Rect 对象中。
public boolean intersect(Rect r){
return intersect(r.left, r.top, r.right, r.bottom);
}
传入新的 Rect 对象,并将该对象与当前 Rect 对象做交集运算,结果保存在当前 Rect对象中。比如有下面的代码段:
Rect rect1 = new Rect(0, 0, 400, 400);
Rect rect2 = new Rect(200, 200, 600, 600);
rect1.intersect(rect2);
此时,rect1 的 left、top、right、bottom 属性被改变了,分别为 200、200、400、400,
public void union(int left,int top,int right,int bottom){
if ((left < right) && (top < bottom)) {
if ((this.left < this.right) && (this.top < this.bottom)) {
if (this.left > left) this.left = left;
if (this.top > top) this.top = top;
if (this.right < right) this.right = right;
if (this.bottom < bottom) this.bottom = bottom;
} else {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
}
}
public void union(Rect r){
union(r.left, r.top, r.right, r.bottom);
}
union()方法是计算两个矩形的并集,传入一个新的 Rect,与当前 Rect 进行并集运算,并将结果保存在当前 Rect 对象中。比如有下面的代码段:
Rect rect1 = new Rect(0, 0, 400, 400);
Rect rect2 = new Rect(200, 200, 600, 600);
rect1.union(rect2);
运行后与交集一样,最终的结果保存在 rect1 对象中, rect1 的 left、top、right、bottom属性值分别为:0,0,600,600,也就是说,并集取的是四个方向的最大值。与 Rect 类类似的还有 RectF 类,RectF 类的代码实现与 Rect 如出一辙,主要的不同是 Rect的 left、top、right、bottom 四个成员变量为 int 类型,而 RectF 为 float 类型。在开发中,常常会出现 Rect 与 RectF 相互转换的情况,Rect 类中没有定义与 RectF 相关的任何信息,但在 RectF 类中,则定义了二者相互转换的方法。RectF 转换成 Rect。RectF 定义了两个名为 round 和 roundOut 的方法,round()方法将 RectF类的类型为 float 的 left、top、right、bottom 属性以四舍五入的方式转换成 int 再通过 Rect 类型的参数传回,roundOut()方法虽然和 round()差不多,但在某些情况下返回的矩形区域要大些。
public void round(Rect dst){
dst.set(FastMath.round(left), FastMath.round(top),
FastMath.round(right), FastMath.round(bottom));
}
public void roundOut(Rect dst){
dst.set((int) FloatMath.floor(left), (int) FloatMath.floor(top),
(int) FloatMath.ceil(right), (int) FloatMath.ceil(bottom));
}
public RectF(Rect r) {
if (r == null) {
left = top = right = bottom = 0.0f;
} else {
left = r.left;
top = r.top;
right = r.right;
bottom = r.bottom;
}
}
文章浏览阅读2.1k次。FX3 JLINK调试是一个有些麻烦的事情,经常有些莫名其妙的问题。 设置参见 c:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\doc\firmware 下的 EzUsbSuite_UG.pdf 文档。 常见问题: 1.装了多个版本的jlink,使用了未注册或不适当的版本 选择一个正确的版本。JLinkARM_V408l,JLinkA_ezusbsuite_qsg.pdf
文章浏览阅读2.6k次。** 本文仅通过用openGL+QT简单实现二进制stl文件读取显示并通过鼠标旋转缩放, 是比较入门的级别,由于个人能力有限,新手级别,所以未能施加光影灯光等操作, 未能让显示的stl文件更加真实。****效果图:**1. main.cpp```cpp#include "widget.h"#include <QApplication>int main(int argc, char *argv[]){ QApplication a(argc, argv); _qopengl如何鼠标控制旋转
文章浏览阅读943次,点赞22次,收藏19次。以大规模预训练语言模型为基础的chatgpt成功出圈,在近几日已经给人工智能板块带来了多次涨停,这足够说明这一风口的到来。而作为曾经的风口“知识图谱”而言,如何找到其与chatgpt之间的区别,找好自身的定位显得尤为重要。形式化知识和参数化知识在表现形式上一直都是大家考虑的问题,两种技术都应该有自己的定位与价值所在。知识图谱构建往往是抽取式的,而且往往包含一系列知识冲突检测、消解过程,整个过程都能溯源。以这样的知识作为输入,能在相当程度上解决当前ChatGPT的事实谬误问题,并具有可解释性。
文章浏览阅读1.3k次。最重要的一点,一定是degbug的方式启动,不然热部署不会生效,注意,注意!_tomcat热部署
文章浏览阅读10w+次,点赞56次,收藏482次。html5 ,用css去修饰自己的个人主页代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xh..._个人主页源码
文章浏览阅读201次。开发者(KaiFaX)面向全栈工程师的开发者专注于前端、Java/Python/Go/PHP的技术社区来源:开源最前线链接:https://github.com/svenstaro/gen..._程序员怎么上班摸鱼
文章浏览阅读1.3k次。改变Block UI界面的尺寸_ug二次开发 调整 对话框大小
文章浏览阅读1.3w次,点赞18次,收藏291次。基于深度学习的股票预测数据获取数据转换LSTM模型搭建训练模型预测结果数据获取采用tushare的数据接口(不知道tushare的筒子们自行百度一下,简而言之其免费提供各类金融数据 , 助力智能投资与创新型投资。)python可以直接使用pip安装tushare!pip install tushareCollecting tushare Downloading https://files.pythonhosted.org/packages/17/76/dc6784a1c07ec040e74_基于深度学习的股票操纵识别研究python代码
文章浏览阅读2k次。【IT168 厂商动态】 近日,北京中科网威(NETPOWER)工业级防火墙通过了中国电力工业电力设备及仪表质量检验测试中心(厂站自动化及远动)测试,并成为中国首家通过电力协议访问控制专业测评的工业级防火墙生产厂商。 北京中科网威(NETPOWER)工业级防火墙专为工业及恶劣环境下的网络安全需求而设计,它采用了非X86的高可靠嵌入式处理器并采用无风扇设计,整机功耗不到22W,具备极_电力行业防火墙有哪些
文章浏览阅读206次。/*烟台大学计算机学院 作者:董玉祥 完成日期: 2017 12 3 问题描述:二叉树排序树中查找的路径 */#include #include #define MaxSize 100typedef int KeyType; //定义关键字类型typedef char InfoType;typedef struct node
文章浏览阅读775次。当时老师一定会告诉你,这个一个"warning"的报警,可以不用管它,也确实如此。不过,这条报警信息我们至少可以知道一点,就是scanf函数调用完之后是有一个返回值的,下面我们就要对scanf返回值进行详细的讨论。并给出在编程时利用scanf的返回值可以实现的一些功能。_c语言ignoring return value
文章浏览阅读9.6k次。十四五规划下,数据安全成为国家、社会发展面临的重要议题,《数据安全法》《个人信息保护法》《关键信息基础设施安全保护条例》已陆续施行。如何做好“数据安全建设”是数字时代的必答题。_数字医疗服务保障方案