我应该使用哪个Point2D [英] which Point2D should I use

查看:394
本文介绍了我应该使用哪个Point2D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jdk8包含3个不同的 Point2D 类。




  • <$ c $ rt.jar

  • java.awt.geom.Point2D > javafx.geometry.Point2D 在 jfxrt.jar

  • com中。 sun.javafx.geom.Point2D jfxrt.jar中



我应该使用哪个 Point2D 类?

使用/应用程序:我想执行几何计算以确定点是否与线相交。 (例如 Line2D.contains(Point2D)

鉴于我还使用其他javafx功能即也在 javafx。* 包中)。我的第一个猜测是使用 javafx.geometry.Point2D class 。但是,虽然此包包含 Point2D 类,但不包含 Line2D class ,但其他两个软件包 do 包含一个 Line2D 软件包。

另一个软件包 我不想挑选一个在不久的将来会被弃用的类。

编辑:



<也许是一个小细节: Point2D 类的 awt com.sun 包使用 float 来定义它们的点,这需要大量的强制转换。尽管 javafx 版本使用 double ,这非常方便,因为javafx也更喜欢 double 来安排组件(例如 getPrefWidth getLayoutX ,...)。



EDIT2:



实际上 Line2D 类不是一个很大的帮助。 包含方法总是返回 false 。所以,看起来我必须自己编写自己的交集方法。

/ code>是JavaFX的一个不同的UI工具包。不建议混合来自不同库的类,特别是假设您已经使用JavaFX功能。



com.sun 开头的所有内容, code>应该避免,因为它是私人API,并不能保证它会继续在下一次更新中工作。



您在此的最佳行动方案方案是使用 javafx.geometry.Point2D 并实现您自己的 Line2D 。作为替代,您可以使用JavaFX场景图及其 Circle (半径为0.5)和 Line (带笔画宽度为1)的课程,以帮助您进行计算。


The jdk8 contains 3 different Point2D classes.

  • java.awt.geom.Point2D in the rt.jar
  • javafx.geometry.Point2D in the jfxrt.jar
  • com.sun.javafx.geom.Point2D in the jfxrt.jar

Which Point2D class should I use ?

Use/application: I want to perform geometric calculations to determine if a point intersects with a line. (e.g. Line2D.contains(Point2D))

Given the fact that I'm also using other javafx features (i.e. also in the javafx.* package). My first guess, would be to use the javafx.geometry.Point2D class. However while this package does contain a Point2D class, it does not contain a Line2D class, but the other 2 packages do contain a Line2D package.

On the other hand, I don't want to pick a class that will be deprecated in the near future.

EDIT:

Perhaps a minor detail: the Point2D class of the awt and com.sun package use float's for defining their points, which requires a lot of casting. While the javafx version uses double, which is pretty convenient, since javafx also prefers double for arranging components (e.g. getPrefWidth, getLayoutX, ...).

EDIT2:

Actually the Line2D class is not a big help. The contains methods always return false. So, it looks like I have to write my own intersect method anyway.

解决方案

java.awt is a different UI toolkit to JavaFX. It is not recommended to mix classes from different libraries, especially provided that you already use JavaFX features.

Everything that starts with com.sun should be avoided as it is private API and there is no guarantee that it will continue working in the next update.

Your best course of action in this scenario is to use javafx.geometry.Point2D and implement your own Line2D. As an alternative you can use the JavaFX scene graph and its Circle (with radius of 0.5) and Line (with stroke width of 1) classes to help you with your calculations.

这篇关于我应该使用哪个Point2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆