DOMPointReadOnly.fromPoint()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

静的な {domxref("DOMPointReadOnly")}} メソッド fromPoint() は、指定された元の点から新しい DOMPointReadOnly オブジェクトを作成し、それを返します。

また、 new DOMPointReadOnly() コンストラクターを使用しても、新しい DOMPointReadOnly オブジェクトを作成することができます。

構文

js
fromPoint(sourcePoint);

引数

sourcePoint

新しい点のプロパティの値を取得するための DOMPoint または DOMPointReadOnly インスタンス、あるいは以下のプロパティを含むオブジェクトです。

x

空間上の点の x 座標を表す、無制限の浮動小数点数。これは一般に水平座標であり、正の値は右側に、負の値は左側になります。既定値は 0 です。

y

点の y 座標を表す無制限の浮動小数点数。これは垂直座標であり、座標系に適用される変換を除いて、正の値は下向きに、負の値は画面上方に向かって上向きになります。既定値は 0 です。

z

点の z 座標を与える無制限の浮動小数点数.この座標は、(状況を変えるような変換がないと仮定して)奥行き座標です。正の値はユーザーに近く、負の値は画面の奥に引っ込みます。既定値は 0 です。

w

点の w 視点位置。無制限の浮動小数点数で与えられます。 既定値は 1 です。

返値

新しい(元の点と同じ) DOMPointReadOnly オブジェクト。

二次元の点の作成

このサンプルでは、 xy に使用する値を含むインラインオブジェクトを指定し、二次元点を作成しています。 zw プロパティは既定値(それぞれ 01)のままにしておくことが可能です。

js
const point2D = DOMPointReadOnly.fromPoint({ x: 25, y: 25 });

既存の点を使用して三次元の点を作成します

この例では、 DOMPoint を用いて、 new DOMPoint() 型の点 origPoint を作成しています。そして、その点は fromPoint() の入力として使用され、新しい点 newPoint を作成します。

js
const origPoint = new DOMPoint(25, 25, 100, 0.5);

const newPoint = DOMPointReadOnly.fromPoint(origPoint);

仕様書

Specification
Geometry Interfaces Module Level 1
# dom-dompointreadonly-frompoint

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
fromPoint() static method

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support