linux系统之(一) 深入理解/proc文件系统
2015-10-13 18:06
811 查看
getPerimeterPoint(VertexView view, Point2D source, Point2D p)
是获取VertexView的边框与连线之间的交叉点的方法。
源码:
/** * Returns the intersection of the bounding rectangle and the straight line * between the source and the specified point p. The specified point is * expected not to intersect the bounds. */ public Point2D getPerimeterPoint(VertexView view, Point2D source, Point2D p) { Rectangle2D bounds = view.getBounds(); Icon icon = GraphConstants.getIcon(view.getAllAttributes()); double x = bounds.getX(); double y = bounds.getY(); double width = bounds.getWidth(); double height = bounds.getHeight(); double xCenter = x + width / 2; double yCenter = y + height / 2; double dx = p.getX() - xCenter; // Compute Angle double dy = p.getY() - yCenter; double alpha = Math.atan2(dy, dx); double xout = 0, yout = 0; double pi = Math.PI; double pi2 = Math.PI / 2.0; double beta = pi2 - alpha; double t = Math.atan2(height, width); if (alpha < -pi + t || alpha > pi - t) { // Left edge xout = x; yout = yCenter - width * Math.tan(alpha) / 2; } else if (alpha < -t) { // Top Edge yout = y; xout = xCenter - height * Math.tan(beta) / 2; } else if (alpha < t) { // Right Edge xout = x + width; yout = yCenter + width * Math.tan(alpha) / 2; } else { // Bottom Edge yout = y + height; xout = xCenter + height * Math.tan(beta) / 2; } return new Point2D.Double(xout, yout); }
如果想在连线连接图元对象时,连接到图元的图标范围上,而不是连接到图元的边框上(有些图元设置了小图标,而显示的名称很小,连线连到图元的边框时,看上去感觉不是连接到图元上)
连接到图标上,可以修改如下:
/** * Returns the intersection of the bounding rectangle and the straight line * between the source and the specified point p. The specified point is * expected not to intersect the bounds. */ public Point2D getPerimeterPoint(VertexView view, Point2D source, Point2D p) { Rectangle2D bounds = view.getBounds(); //获取图标 Icon icon = GraphConstants.getIcon(view.getAllAttributes()); if (icon != null) {//图标不为空 //获取X坐标偏移的大小 double doubX = bounds.getX() + (bounds.getWidth()-icon.getIconWidth())/2; //重新构建边框(图标的边框) bounds = new Rectangle2D.Double(doubX, bounds.getY(), icon.getIconWidth(), icon.getIconWidth()); } double x = bounds.getX(); double y = bounds.getY(); double width = bounds.getWidth(); double height = bounds.getHeight(); double xCenter = x + width / 2; double yCenter = y + height / 2; double dx = p.getX() - xCenter; // Compute Angle double dy = p.getY() - yCenter; double alpha = Math.atan2(dy, dx); double xout = 0, yout = 0; double pi = Math.PI; double pi2 = Math.PI / 2.0; double beta = pi2 - alpha; double t = Math.atan2(height, width); if (alpha < -pi + t || alpha > pi - t) { // Left edge xout = x; yout = yCenter - width * Math.tan(alpha) / 2; } else if (alpha < -t) { // Top Edge yout = y; xout = xCenter - height * Math.tan(beta) / 2; } else if (alpha < t) { // Right Edge xout = x + width; yout = yCenter + width * Math.tan(alpha) / 2; } else { // Bottom Edge yout = y + height; xout = xCenter + height * Math.tan(beta) / 2; } return new Point2D.Double(xout, yout); }
相关文章推荐
- linux源码分析之cpu初始化 kernel/head.s
- Linux集群理论及技术
- SVN服务器环境搭建
- Linux下Mysql 5.6.27 tar包安装实践
- 【linux学习笔记】samba在RHEL7上配置
- linux 目录结构及文件基本操作
- windows / linux系统中,端口被占用解决方法
- CentOS新系统必做的几件事
- Linux内核同步方法(一)
- Linux进程理解与实践(五)细谈守护进程
- Linux进程理解与实践(四)wait函数处理僵尸进程
- Linux进程理解与实践(三)进程终止函数和exec函数族的使用
- Linux 防火墙开放特定端口 (iptables)
- linux命令grep用法汇总
- linux vmware -tools 安装
- Linux cp 实现强行覆盖
- 《王保明老师----Linux开发学习笔记》------讲09:进程 -----vfork()+execve()拉起一个可执行程序
- 【转】Linux中断处理学习笔记
- 【转】Linux 中断学习之小试牛刀篇
- linux添加系统负载日志