オブジェクト内でのポイントのテスト

Rogue Wave® JViews グラフィック・オブジェクトを描画する際には、オブジェクト内にポイントがあるかどうかを確認する必要があります。ShadowEllipse 例では、contains メソッドが実装されます。このメソッドは、指定ポイントが主な楕円内にある場合、true を返します。すべての座標はビューの座標系を基準に指定されます。
 /**
   * Tests whether a point lies within the shape of the object.
   * This method will be called when you click the object.
   * @param p The point where user clicks in the object’s coordinate system.
   * @param tp Same point as ’p’ but transformed by transformer ’t’
   * @param t The transformer used to draw the object.
   */
  public boolean contains(IlvPoint p, IlvPoint tp,
                          IlvTransformer t)
  {
    // Allow the user to click the main ellipse
    // but not on the shadow ellipse. 
    // This method will return true when the clicked point is
    // on the main ellipse.
    // First compute the bounding rectangle of the main
    // ellipse in the view coordinate system, just like in the
    // method draw.
    IlvRect r = new IlvRect(drawrect);
             
    if (t != null) 
      t.apply(r);
               
    int thick = thickness;
         
    if ((r.width <= thick) || (r.height <= thick))
      thick = (int)Math.min(r.width, r.height);
 
    r.width  -= thick;
    r.height -= thick;
 
    // Then call PointInFilledArc that will return true
    // if the point is in the ellipse. ’r’ and ’tp’ are both
    // in the view coordinate system.
    return IlvArcUtil.PointInFilledArc(tp, r, (float)0, (float)360);
  }