<legend id='Buz94'><style id='Buz94'><dir id='Buz94'><q id='Buz94'></q></dir></style></legend>

      1. <i id='Buz94'><tr id='Buz94'><dt id='Buz94'><q id='Buz94'><span id='Buz94'><b id='Buz94'><form id='Buz94'><ins id='Buz94'></ins><ul id='Buz94'></ul><sub id='Buz94'></sub></form><legend id='Buz94'></legend><bdo id='Buz94'><pre id='Buz94'><center id='Buz94'></center></pre></bdo></b><th id='Buz94'></th></span></q></dt></tr></i><div id='Buz94'><tfoot id='Buz94'></tfoot><dl id='Buz94'><fieldset id='Buz94'></fieldset></dl></div>

        <small id='Buz94'></small><noframes id='Buz94'>

        <tfoot id='Buz94'></tfoot>
          <bdo id='Buz94'></bdo><ul id='Buz94'></ul>
      2. 检查一个点是否在指定的 Rectangle 内

        时间:2023-10-01
          <legend id='ZirFW'><style id='ZirFW'><dir id='ZirFW'><q id='ZirFW'></q></dir></style></legend>

          <small id='ZirFW'></small><noframes id='ZirFW'>

              <i id='ZirFW'><tr id='ZirFW'><dt id='ZirFW'><q id='ZirFW'><span id='ZirFW'><b id='ZirFW'><form id='ZirFW'><ins id='ZirFW'></ins><ul id='ZirFW'></ul><sub id='ZirFW'></sub></form><legend id='ZirFW'></legend><bdo id='ZirFW'><pre id='ZirFW'><center id='ZirFW'></center></pre></bdo></b><th id='ZirFW'></th></span></q></dt></tr></i><div id='ZirFW'><tfoot id='ZirFW'></tfoot><dl id='ZirFW'><fieldset id='ZirFW'></fieldset></dl></div>
              • <bdo id='ZirFW'></bdo><ul id='ZirFW'></ul>
                    <tbody id='ZirFW'></tbody>
                  <tfoot id='ZirFW'></tfoot>

                  本文介绍了检查一个点是否在指定的 Rectangle 内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  好的,所以我正在为一个 Java 类进行分配,其中一部分是确定一个点是否在矩形的尺寸范围内.所以我创建了这段代码:

                  ok, so i'm doing an assignment for a Java class and one part of the assignment is to find out if a point is within the dimensions of a rectangle. so I created this code:

                  public boolean contains(Point p) {
                      return (this.getLocation().getX() < p.getX() && this.getLocation().getY() < p.getY() &&
                              this.getLocation().getX() + this.getWidth() > p.getX()  &&
                              this.getLocation().getY() + this.getHeight() > p.getY());
                  }
                  

                  我也创建了一个 Point 类,这就是我要求 Point p 参数的原因.为了测试这个 boolean 我在我的 Main 类中创建了一个简单的 if 语句:

                  I created a Point class as well, which is why I asked for a Point p parameter. To test this boolean I created a simple if statement in my Main class:

                  //check if one rectangle's point is inside another
                  if (rectangle.contains(rectangle2.getLocation()))
                      System.out.println("the point is in the rectangle");
                  

                  点的位置是(6,7).矩形 1 的点、宽和高分别为 (4,5)、9 和 3.我知道这一点在第一个矩形内,但是 println 语句没有显示,这意味着我创建的 boolean 肯定有问题,但我没有'没有看到错误,也许我的头是多云的,但有人可以向我指出这里有什么问题吗?

                  The location of the point is (6,7). The point, width, and height of rectangle 1 is (4,5), 9, and 3, respectively. I know for a fact that this point is inside the first rectangle, but the println statement is not showing, meaning there must be a problem with the boolean i created but I don't see an error, maybe my head is cloudy but can someone point out to me what's wrong here?

                  附:这都是控制台工作,我不是在处理一些 GUI 或图形编程.

                  P.S. this is all Console work, i'm not dealing with some GUI or graphics programming.

                  推荐答案

                  我觉得没问题.我会检查你的测试用例是否真的有你认为的数字;我还会检查您的访问器是否都返回了正确的值(我无法告诉您我将 getX() 实现为 {return this.y;} 的次数).除此之外,这是任何人的猜测.

                  It looks ok to me. I would check that your test case actually has the numbers you think it does; I would also check that your accessors are all returning the right values (I can't tell you the number of times I've implemented getX() as {return this.y;}). Other than that it's anyone's guess.

                  这篇关于检查一个点是否在指定的 Rectangle 内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Java:基于距离的绘图点 下一篇:如何在不小于或大于周长的情况下绘制圆的半径

                  相关文章

                  最新文章

                  <i id='0H0QB'><tr id='0H0QB'><dt id='0H0QB'><q id='0H0QB'><span id='0H0QB'><b id='0H0QB'><form id='0H0QB'><ins id='0H0QB'></ins><ul id='0H0QB'></ul><sub id='0H0QB'></sub></form><legend id='0H0QB'></legend><bdo id='0H0QB'><pre id='0H0QB'><center id='0H0QB'></center></pre></bdo></b><th id='0H0QB'></th></span></q></dt></tr></i><div id='0H0QB'><tfoot id='0H0QB'></tfoot><dl id='0H0QB'><fieldset id='0H0QB'></fieldset></dl></div>

                  <small id='0H0QB'></small><noframes id='0H0QB'>

                  <tfoot id='0H0QB'></tfoot>

                      • <bdo id='0H0QB'></bdo><ul id='0H0QB'></ul>
                    1. <legend id='0H0QB'><style id='0H0QB'><dir id='0H0QB'><q id='0H0QB'></q></dir></style></legend>