Class: Geom::Point2d

Inherits:
Object
  • Object
show all
Defined in:
lib/sketchup-api-stubs/stubs/Geom/Point2d.rb

Overview

The Point2d class allows you to work with a point in 2D space. Point2d is a series of values representing x and y coordinates.

The values are specified as [x, y]. For example [1, 1]. To create a point call Geom::Point2d.new, where the creation method can take a variety of arguments:

Examples:

# No arguments, creates a point at the origin [0, 0]
pt1 = Geom::Point2d.new

# Creates a point at x of 1, y of 2.
pt2 = Geom::Point2d.new(1, 2)

# You can also create a point directly by simply assigning the x, and y
# values to a variable as an array:
pt3 = [1, 2]

Version:

  • LayOut 2018

Instance Method Summary collapse

Constructor Details

#initializeGeom::Point2d #initialize(x, y) ⇒ Geom::Point2d #initialize(point) ⇒ Geom::Point2d

The new method creates a new Geom::Point2d.

Examples:

# No arguments, creates a point at the origin [0, 0]
pt1 = Geom::Point2d.new

# Creates a point at x of 1 and y of 2.
pt2 = Geom::Point2d.new(1, 2)

# You can also create a point directly by simply assigning the x and y
# values to a variable as an array:
pt3 = [1, 2]

Overloads:

Version:

  • LayOut 2018



183
184
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 183

def initialize(*args)
end

Instance Method Details

#+(vector) ⇒ Geom::Point2d

The #+ operator is a simple way to add to the current x and y values of the Geom::Point2d, or to set the values of the Geom::Point2d by adding a Vector2d to the Geom::Point2d.

Examples:

pt = [1, 1]
# the result is a Point2d(2, 3)
pt2 = pt + [1, 2]

Parameters:

Returns:

Version:

  • LayOut 2018



41
42
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 41

def +(vector)
end

#-(vector) ⇒ Geom::Point2d #-(point) ⇒ Geom::Vector2d

The #- operator is a simple way to subtract from the current x and y values of the Geom::Point2d.

Examples:

vec = Geom::Vector2d.new(1, 2)
# result is a Point2d(3, 0)
pt = [4, 2] - vec
# result is a Vector2d(1, 2)
vec2 = [4, 2] - pt

Overloads:

Version:

  • LayOut 2018



66
67
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 66

def -(arg)
end

#==(point) ⇒ Boolean

The #== method compares two points for equality. This uses the standard SketchUp tolerance to determine if two points are the same.

Examples:

point1 = Geom::Point2d.new(1, 1)
point2 = Geom::Point2d.new(0, 1)
status = point1 == point2

Parameters:

Returns:

  • (Boolean)

Version:

  • LayOut 2018



82
83
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 82

def ==(point)
end

#[](index) ⇒ Length

The #[] method returns the value of the Geom::Point2d at the specified index.

Examples:

point = Geom::Point2d.new(1, 2)

# returns the y value of 2
yvalue = point[1]

Parameters:

  • index (Integer)

    The index for a specific x or y value in the Geom::Point2d

Returns:

  • (Length)

    The new x or y value if successful

Version:

  • LayOut 2018



101
102
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 101

def [](index)
end

#[]=(index, value) ⇒ Numeric

The #[]= method sets the x or y value of the Geom::Point2d based on the specific index of the value.

Examples:

point = Geom::Point2d.new(1,2)
point[1] = 4

Parameters:

  • index (Integer)

    The index for a specific x or y value in the Geom::Point2d to set

  • value (Numeric)

    The value to set for x or y

Returns:

  • (Numeric)

    The new x or y value if successful

Version:

  • LayOut 2018



121
122
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 121

def []=(index, value)
end

#cloneGeom::Point2d

The #clone method creates another point identical to the Geom::Point2d being cloned.

Examples:

point = Geom::Point2d.new(1, 2)
newpoint = point.clone

Returns:

Version:

  • LayOut 2018



134
135
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 134

def clone
end

#distance(point) ⇒ Numeric

The #distance method computes the distance from the Geom::Point2d to another Geom::Point2d.

Examples:

point1 = Geom::Point2d.new(1, 1)
point2 = Geom::Point2d.new(1, 4)
# result is a value of 3
distance = point1.distance(point2)

Parameters:

Returns:

  • (Numeric)

    the distance between the points in the current units

Version:

  • LayOut 2018



151
152
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 151

def distance(point)
end

#inspectString

The #inspect method formats the Geom::Point2d as a string.

Examples:

point = Geom::Point2d.new(1, 2)
string = point.inspect

Returns:

Version:

  • LayOut 2018



195
196
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 195

def inspect
end

#offset(vector) ⇒ Geom::Point2d #offset(vector, distance) ⇒ Geom::Point2d

The #offset method offsets the Geom::Point2d by a Vector2d and returns a new Geom::Point2d. If distance is provided, it must be non-zero.

Examples:

point = Geom::Point2d.new
vector = Geom::Vector2d.new(0, 2)
# result is a Point2d(0, 1)
point2 = point1.offset(vector, 1)

Overloads:

Version:

  • LayOut 2018



219
220
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 219

def offset(*args)
end

#offset!(vector) ⇒ Geom::Point2d #offset!(vector, distance) ⇒ Geom::Point2d

The #offset! method offsets the Geom::Point2d by a Vector2d. The Geom::Point2d itself is modified. The length of the vector must not be zero.

Examples:

point = Geom::Point2d.new
vector = Geom::Vector2d.new(0, 2)
# result is a Point2d(0, 1)
point1.offset!(vector, 1)

Overloads:

Version:

  • LayOut 2018



244
245
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 244

def offset!(*args)
end

#set!(point) ⇒ Geom::Point2d #set!(x, y) ⇒ Geom::Point2d

The #set! method sets the values of the Geom::Point2d.

Examples:

point = Geom::Point2d.new(1, 2)
point = point.set!([4, 5])

Overloads:

Version:

  • LayOut 2018



265
266
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 265

def set!(*args)
end

#to_aArray(Numeric, Numeric)

The #to_a method converts the Geom::Point2d to an array of 2 numbers.

Examples:

point = Geom::Point2d.new(1, 2)
array = point.to_a

Returns:

Version:

  • LayOut 2018



278
279
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 278

def to_a
end

#to_sString

The #to_s method returns a string representation of the Geom::Point2d.

Examples:

point = Geom::Point2d.new(1, 2)
str = point.to_s

Returns:

Version:

  • LayOut 2018



290
291
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 290

def to_s
end

#transform(transform) ⇒ Geom::Point2d

The #transform method applies a transformation to a point, returning a new point. The original point is unchanged by this method.

Examples:

point = Geom::Point2d.new(4, 5)
transformation = Geom::Transformation2d.new([1, 0, 0, 1, 2, 3])
# pt will be (6, 8)
pt = point.transform(transformation)

Parameters:

Returns:

Version:

  • LayOut 2019



308
309
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 308

def transform(transform)
end

#transform!(transform) ⇒ Geom::Point2d

The #transform! method applies a transformation to a point. The point itself is modified.

Examples:

point = Geom::Point2d.new(4, 5)
transformation = Geom::Transformation2d.new([1, 0, 0, 1, 2, 3])
# point will be (6, 8)
point.transform!(transformation)

Parameters:

Returns:

Version:

  • LayOut 2019



326
327
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 326

def transform!(transform)
end

#vector_to(point) ⇒ Geom::Vector2d

The #vector_to method returns the vector between points.

Examples:

pt1 = Geom::Point2d.new(1, 1)
pt2 = Geom::Point2d.new(3, 1)

# result is a Vector2d(2, 0)
vec = pt1.vector_to(pt2) # is equivalent to (pt2 - pt1)

Parameters:

Returns:

Version:

  • LayOut 2018



343
344
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 343

def vector_to(point)
end

#xLength

The #x method returns the x value of the Geom::Point2d.

Examples:

point = Geom::Point2d.new(1, 2)
x = point.x

Returns:

Version:

  • LayOut 2018



355
356
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 355

def x
end

#x=(x) ⇒ Numeric

The #x= method sets the x value of the Geom::Point2d.

Examples:

point = Geom::Point2d.new(1, 2)
point.x = 7

Parameters:

Returns:

Version:

  • LayOut 2018



370
371
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 370

def x=(x)
end

#yLength

The #y method returns the y value of the Geom::Point2d.

Examples:

point = Geom::Point2d.new(1, 2)
y = point.y

Returns:

Version:

  • LayOut 2018



382
383
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 382

def y
end

#y=(y) ⇒ Numeric

The #y= method sets the y value of the Geom::Point2d.

Examples:

point = Geom::Point2d.new(1, 2)
point.y = 7

Parameters:

Returns:

Version:

  • LayOut 2018



397
398
# File 'lib/sketchup-api-stubs/stubs/Geom/Point2d.rb', line 397

def y=(y)
end