※この翻訳ドキュメントはスクリプトによって出力・同期されています。内容が怪しそうな場合はGitHubにissueを追加したり英語の原文の確認をお願いします。
get_bounds インターフェイス¶
このページではget_boundsメソッドのインターフェイスについて説明します。
インターフェイス概要¶
get_boundsメソッドはインスタンスのバウンディングボックスのデータ(座標やサイズなどの幾何データ)を返却します。
基本的な使い方¶
get_boundsメソッドではRectangleGeomクラスのインスタンスを返却します。
このメソッドは省略可能なtarget_coordinate_space_object引数を受け付けます。
もしこの引数が指定された場合、返却値の基準となる座標は指定された引数のDisplayObjectからの相対座標となります。
この設定は親のDisplayObjectの座標などの相対座標を取得したい場合などに役に立つことがあります。
もしこの引数の指定を省略した場合、座標はStageを基準とした座標となります(実質的に絶対座標となります)。
引数の指定を省略した場合の例 :
import apysc as ap
stage: ap.Stage = ap.Stage(
    background_color=ap.Color("#333"),
    stage_width=500,
    stage_height=440,
    stage_elem_id="stage",
)
circle: ap.Circle = ap.Circle(
    x=250,
    y=220,
    radius=150,
    fill_color=ap.Color("#0af"),
)
bounding_box: ap.RectangleGeom = circle.get_bounds()
box_rectangle: ap.Rectangle = ap.Rectangle(
    x=bounding_box.left_x,
    y=bounding_box.top_y,
    width=bounding_box.width,
    height=bounding_box.height,
    line_color=ap.Color("#aaa"),
)
fill_color: ap.Color = ap.Color("#fd63c3")
left_x_and_top_y_circle: ap.Circle = ap.Circle(
    x=bounding_box.left_x,
    y=bounding_box.top_y,
    radius=10,
    fill_color=fill_color,
)
left_x_and_top_y_text: ap.SvgText = ap.SvgText(
    text="left_x and top_y",
    x=bounding_box.left_x,
    y=bounding_box.top_y - 15,
    fill_color=fill_color,
)
ap.save_overall_html(dest_dir_path="get_bounds_basic_usage_1/")
target_coordinate_space_object引数を指定した場合の例 :
import apysc as ap
stage: ap.Stage = ap.Stage(
    background_color=ap.Color("#333"),
    stage_width=500,
    stage_height=440,
    stage_elem_id="stage",
)
sprite: ap.Sprite = ap.Sprite()
sprite.x = ap.Number(250)
sprite.y = ap.Number(220)
circle: ap.Circle = ap.Circle(
    x=0,
    y=0,
    radius=150,
    fill_color=ap.Color("#0af"),
    parent=sprite,
)
bounding_box: ap.RectangleGeom = circle.get_bounds(
    target_coordinate_space_object=sprite,
)
box_rectangle: ap.Rectangle = ap.Rectangle(
    x=bounding_box.left_x,
    y=bounding_box.top_y,
    width=bounding_box.width,
    height=bounding_box.height,
    line_color=ap.Color("#aaa"),
    parent=sprite,
)
ap.save_overall_html(dest_dir_path="get_bounds_basic_usage_2/")
get_bounds メソッドのAPI¶
特記事項: このAPIドキュメントはドキュメントビルド用のスクリプトによって自動で生成・同期されています。そのためもしかしたらこの節の内容は前節までの内容と重複している場合があります。
[インターフェイスの構造] get_bounds(self, target_coordinate_space_object: Union[apysc._display.display_object.DisplayObject, NoneType] = None) -> apysc._geom.rectangle_geom.RectangleGeom
[インターフェイス概要]
インスタンスのバウンディングボックスの幾何データを取得します。
[引数]
target_coordinate_space_object: DisplayObject or None, default None座標の基準となるオブジェクト。もしNoneが指定された場合、このメソッドはステージを基準としたバウンディングボックスのデータを返却します。もし
DisplayObjectのインスタンスが指定された場合、ごのメソッドは指定されたオブジェクトの座標を基準としたバウンディングボックスのデータを返却します。
[返却値]
bounding_box: RectangleGeomインスタンスのバウンディングボックスの幾何データ。
[コードサンプル]
>>> import apysc as ap
>>> stage: ap.Stage = ap.Stage(
...     background_color=ap.Color("#333"), stage_width=250, stage_height=350
... )
>>> rectangle: ap.Rectangle = ap.Rectangle(
...     x=50,
...     y=100,
...     width=150,
...     height=200,
...     fill_color=ap.Color("#0af"),
... )
>>> bounding_box: ap.RectangleGeom = rectangle.get_bounds()
[関連資料]