• <small id='pCJga'></small><noframes id='pCJga'>

    <legend id='pCJga'><style id='pCJga'><dir id='pCJga'><q id='pCJga'></q></dir></style></legend>
    <tfoot id='pCJga'></tfoot>
      <bdo id='pCJga'></bdo><ul id='pCJga'></ul>

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

      1. 检查一个点是否在指定的 Rectangle 内

        checking if a point is inside a specified Rectangle(检查一个点是否在指定的 Rectangle 内)

          <bdo id='aMl2S'></bdo><ul id='aMl2S'></ul>

          <tfoot id='aMl2S'></tfoot>
            <tbody id='aMl2S'></tbody>

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

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

                1. 本文介绍了检查一个点是否在指定的 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 内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
                  Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
                  How to convert Integer to int?(如何将整数转换为整数?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
                  Inconsistent behavior on java#39;s ==(java的行为不一致==)
                  Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)
                2. <small id='RGXqi'></small><noframes id='RGXqi'>

                  1. <tfoot id='RGXqi'></tfoot>
                          <legend id='RGXqi'><style id='RGXqi'><dir id='RGXqi'><q id='RGXqi'></q></dir></style></legend>
                            <bdo id='RGXqi'></bdo><ul id='RGXqi'></ul>
                              <tbody id='RGXqi'></tbody>

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