Logo

Programming-Idioms

Declare a container type for two floating-point numbers x and y
Implementation
JS

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another JS implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
class Point{
  double x;
  double y;
}
type Point struct {
    x, y float64
}
typedef struct {
  double x;
  double y;
} Point;
struct Point{
  double x;
  double y;
};
Point = Struct.new(:x, :y)
var p = { x: 1.122, y: 7.45 };
my $point = [ 1.5, 6.3 ];
struct Point {
    x: f64,
    y: f64,
}
struct Point{
    double x;
    double y;
}

    
class Point {
  double x, y;
}
my $point = { x => 1, y => 2 };
Type
  TPoint = Record
    x : Double;
    y : Double;
  End;
from dataclasses import dataclass
@dataclass
class Point:
    x: float
    y: float
class Point {
  double x, y;
  Point(this.x, this.y);
}
data Point = Point 
  { x :: Double
  , y :: Double 
  }
data Point = Point
  { x :: Double
  , y :: Double
  } deriving (Eq, Ord, Show, Read)
[x y]
p = [ x: 1.122, y: 7.45 ]
-module(points).
-export([new/2, x/1, y/1]).

-opaque point() :: #{x => float(), y => float()}.
-export_type([point/0]).

-spec new(float(), float()) -> point().
new(X, Y) -> #{x => X, y => Y}.

-spec x(point()) -> float().
x(#{x := X}) -> X.

-spec y(point()) -> float().
y(#{y := Y}) -> Y.
PointAsAMap = #{x => X, y => Y}.
PointAsATuple = {X, Y}.
struct Point
{
    public double x;
    public double y;
};
class Point
{
    /** @var float */
    public $x = 0.0;

    /** @var float */
    public $y = 0.0;
}
point = { x = 123, y = 456 }
type Point is
   record
      X : Float;
      Y : Float;
   end record;
case class Point(x: Float, y: Float)
type point
  real :: x
  real :: y
end type point
(define (make-point x y)
  (cons x y))
(define (point-x p)
  (car p))
(define (point-y p)
  (cdr p))
class Point
{
    float x;
    float y;
}
{x, y}
defmodule Point do
  defstruct x: 0.0, y: 0.0
end
(defstruct point
  (x 0.0d0 :type double-float)
  (y 0.0d0 :type double-float))
type point = {
	x: float;
	y: float;
}
module x
  type point
  real :: x, y
  end type point
end module x
data class Point(val x: Float, val y: Float)
Structure Point
    Public x As Double
    Public y As Double
End Structure
struct Point(f64, f64);
typedef struct {
  double x,y;
} NSPoint;
class Point{
  double x
  double y
}
record Point(double x, double y);
Object subclass: #Point
	instanceVariableNames: 'x y'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Graphics-Primitives'
(double x, double y)
from collections import namedtuple
Point = namedtuple("Point", "x y")
(vector-of :double x y)
private class Point
{
	private final float x;
	private final float y;
	
	public Point(float x, float y)
	{
		this.x = x;
		this.y = y;
	}
	
	public float getX()
	{
		return this.x;
	}
	
	public float getY()
	{
		return this.y;
	}
}
public record Point(double x, double y) { }