Important: The information in this document is obsolete and should not be used for new development.
Inherits from | Object |
Implements |
Cloneable |
Package | com.apple.cocoa.foundation |
Companion guide | Geometry and Range Utilities |
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.
public NSPoint
()
Initializes both x and y coordinates to zero.
public NSPoint
(float x, float y)
Initializes the NSPoint with the horizontal coordinate x and the vertical coordinate y.
public NSPoint
(NSPoint aPoint)
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)
Initializes the NSPoint with the values extracted from an AWT Point object.
public static NSPoint fromString
(String pointAsString)
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.
Creates and returns a copy of the receiver.
public Object clone
()
Computes and returns the distance between aPoint and the receiver.
public float distanceToPoint
(NSPoint aPoint)
Returns whether otherObject is an NSPoint and has the same x-coordinate and y-coordinate values as the receiver.
public boolean equals
(Object otherObject)
Provide an appropriate hash code useful for storing the receiver in a hash-based data structure.
public int hashCode
()
This value is the sum of the receiver’s x-coordinate and y-coordinate, rounded to the nearest integer.
Returns whether aPoint has the same x-coordinate and y-coordinate as the receiver.
public boolean isEqualToPoint
(NSPoint aPoint)
Returns the receiver as a AWT Point object.
public java.awt.Point toAWTPoint
()
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).
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
()
Returns the x-coordinate of the receiver.
public float x
()
Returns the y-coordinate of the receiver.
public float y
()
NSPoint provides the following constant as a convenience; you can use it to compare values returned by some NSPoint methods:
© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)