Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSPoint

Inherits from
Object
Implements
Cloneable
Package
com.apple.cocoa.foundation
Companion guide
Geometry and Range Utilities

Overview

An NSPoint represents a location in a coordinate system. It has two primary values, an x-coordinate (horizontal) and a y-coordinate (vertical). The methods of NSPoint give access to these values, convert between an NSPoint and its string representation, measure the distance between two NSPoints, and compare two NSPoints for equality.

Tasks

Constructors

Accessing Coordinate Values

Converting Points

Finding the Distance Between Points

Testing Points

Copying

Constructors

NSPoint

public NSPoint()

Discussion

Initializes both x and y coordinates to zero.

public NSPoint(float x, float y)

Discussion

Initializes the NSPoint with the horizontal coordinate x and the vertical coordinate y.

public NSPoint(NSPoint aPoint)

Discussion

Initializes the new NSPoint with the coordinate values of existing NSPoint aPoint; this constructor is used in cloning the receiver.

public NSPoint(java.awt.Point javaPoint)

Discussion

Initializes the NSPoint with the values extracted from an AWT Point object.

Static Methods

fromString

public static NSPoint fromString(String pointAsString)

Discussion

Creates an NSPoint from the string pointAsString, which must be of the form “{x , y}” where x is a float representation of the x-coordinate and y is a float representation of the y-coordinate. Throws an IllegalArgumentException if the string is improperly formatted.

See Also

Instance Methods

clone

Creates and returns a copy of the receiver.

public Object clone()

distanceToPoint

Computes and returns the distance between aPoint and the receiver.

public float distanceToPoint(NSPoint aPoint)

equals

Returns whether otherObject is an NSPoint and has the same x-coordinate and y-coordinate values as the receiver.

public boolean equals(Object otherObject)

See Also

hashCode

Provide an appropriate hash code useful for storing the receiver in a hash-based data structure.

public int hashCode()

Discussion

This value is the sum of the receiver’s x-coordinate and y-coordinate, rounded to the nearest integer.

isEqualToPoint

Returns whether aPoint has the same x-coordinate and y-coordinate as the receiver.

public boolean isEqualToPoint(NSPoint aPoint)

See Also

toAWTPoint

Returns the receiver as a AWT Point object.

public java.awt.Point toAWTPoint()

Discussion

The float values of the x-coordinate and the y-coordinate are rounded down to the nearest integer (that is, the point is moved “down” and to the “left” to the nearest integer).

See Also

toString

Returns the receiver as converted to a string object in the form of “{x, y}” where x is the float representation of the x-coordinate value and y is the float representation of the y-coordinate value.

public String toString()

See Also

x

Returns the x-coordinate of the receiver.

public float x()

y

Returns the y-coordinate of the receiver.

public float y()

Constants

NSPoint provides the following constant as a convenience; you can use it to compare values returned by some NSPoint methods:

Constant

Description

ZeroPoint

An NSPoint with both x and y coordinates set to zero.



Next Page > Hide TOC


© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.