Abstract 2d point, strongly linked to its implementation Point

Introduced properties

fun dist(other: Point[Numeric]): N

geometry :: IPoint :: dist

Distance with other
fun dist2(other: Point[Numeric]): N

geometry :: IPoint :: dist2

Square of the distance with other
fun lerp(other: Point[Numeric], p: Float): Point[N]

geometry :: IPoint :: lerp

Linear interpolation between self and other at p out of 1.0
abstract fun x: N

geometry :: IPoint :: x

Horizontal coordinate
abstract fun y: N

geometry :: IPoint :: y

Vertical coordinate

Redefined properties

redef fun ==(o: nullable Object): Bool

geometry $ IPoint :: ==

Have self and other the same value?
redef type SELF: IPoint[N]

geometry $ IPoint :: SELF

Type of this instance, automatically specialized in every class
redef fun bottom: N

geometry :: boxes $ IPoint :: bottom

Bottom bound
redef fun core_serialize_to(v: Serializer)

geometry $ IPoint :: core_serialize_to

Actual serialization of self to serializer
redef init from_deserializer(v: Deserializer)

geometry $ IPoint :: from_deserializer

Create an instance of this class from the deserializer
redef fun left: N

geometry :: boxes $ IPoint :: left

Left bound
redef fun right: N

geometry :: boxes $ IPoint :: right

Right bound
redef fun to_s: String

geometry $ IPoint :: to_s

User readable representation of self.
redef fun top: N

geometry :: boxes $ IPoint :: top

Top bound

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
protected fun accept_json_serializer(v: JsonSerializer)

serialization :: Serializable :: accept_json_serializer

Refinable service to customize the serialization of this class to JSON
protected fun accept_msgpack_attribute_counter(v: AttributeCounter)

serialization :: Serializable :: accept_msgpack_attribute_counter

Hook to customize the behavior of the AttributeCounter
protected fun accept_msgpack_serializer(v: MsgPackSerializer)

serialization :: Serializable :: accept_msgpack_serializer

Hook to customize the serialization of this class to MessagePack
protected fun add_to_bundle(bundle: NativeBundle, key: JavaString)

serialization :: Serializable :: add_to_bundle

Called by []= to dynamically choose the appropriate method according
abstract fun bottom: N

geometry :: Boxed :: bottom

Bottom bound
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun contains(other: Boxed[N]): Bool

geometry :: Boxed :: contains

Is other contained within self?
fun core_serialize_to(serializer: Serializer)

serialization :: Serializable :: core_serialize_to

Actual serialization of self to serializer
fun dist(other: Point[Numeric]): N

geometry :: IPoint :: dist

Distance with other
fun dist2(other: Point[Numeric]): N

geometry :: IPoint :: dist2

Square of the distance with other
init from_deserializer(deserializer: Deserializer)

serialization :: Serializable :: from_deserializer

Create an instance of this class from the deserializer
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
fun intersects(other: Boxed[N]): Bool

geometry :: Boxed :: intersects

Does self intersect with other?
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
abstract fun left: N

geometry :: Boxed :: left

Left bound
fun lerp(other: Point[Numeric], p: Float): Point[N]

geometry :: IPoint :: lerp

Linear interpolation between self and other at p out of 1.0
protected fun msgpack_extra_array_items: Int

serialization :: Serializable :: msgpack_extra_array_items

Hook to request a larger than usual metadata array
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun padded(dist: N): Box[N]

geometry :: Boxed :: padded

Create a bounding box that encloses the actual bounding box.
abstract fun right: N

geometry :: Boxed :: right

Right bound
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun serialize_msgpack(plain: nullable Bool): Bytes

serialization :: Serializable :: serialize_msgpack

Serialize self to MessagePack bytes
fun serialize_to(serializer: Serializer)

serialization :: Serializable :: serialize_to

Serialize self to serializer
fun serialize_to_json(plain: nullable Bool, pretty: nullable Bool): String

serialization :: Serializable :: serialize_to_json

Serialize self to JSON
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun to_json: String

serialization :: Serializable :: to_json

Serialize self to plain JSON
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_pretty_json: String

serialization :: Serializable :: to_pretty_json

Serialize self to plain pretty JSON
fun to_s: String

core :: Object :: to_s

User readable representation of self.
abstract fun top: N

geometry :: Boxed :: top

Top bound
abstract fun x: N

geometry :: IPoint :: x

Horizontal coordinate
abstract fun y: N

geometry :: IPoint :: y

Vertical coordinate
package_diagram geometry::IPoint IPoint serialization::Serializable Serializable geometry::IPoint->serialization::Serializable geometry::Boxed Boxed geometry::IPoint->geometry::Boxed core::Object Object serialization::Serializable->core::Object geometry::Boxed->core::Object ...core::Object ... ...core::Object->core::Object geometry::Point Point geometry::Point->geometry::IPoint geometry::IPoint3d IPoint3d geometry::IPoint3d->geometry::IPoint geometry::Point3d Point3d geometry::Point3d->geometry::Point geometry::Point3d->geometry::IPoint3d geometry::Point3d... ... geometry::Point3d...->geometry::Point3d

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

interface Boxed[N: Numeric]

geometry :: Boxed

An 2d abstract bounded object
interface Serializable

serialization :: Serializable

Instances of this class can be passed to Serializer::serialize

Children

interface IPoint3d[N: Numeric]

geometry :: IPoint3d

Abstract 3d point, strongly linked to its implementation Point3d
class Point[N: Numeric]

geometry :: Point

2D point with x and z

Descendants

class Point3d[N: Numeric]

geometry :: Point3d

3D point with x, y and z

Class definitions

geometry $ IPoint
# Abstract 2d point, strongly linked to its implementation `Point`
interface IPoint[N: Numeric]

	# Horizontal coordinate
	fun x: N is abstract

	# Vertical coordinate
	fun y: N is abstract

	redef fun to_s do return "({x}, {y})"

	# Distance with `other`
	#
	# ~~~
	# var p0 = new Point[Float](0.0, 0.0)
	# var p1 = new Point[Float](2.0, 3.0)
	# assert p0.dist(p1).is_approx(3.6, 0.01)
	# ~~~
	#
	# If `self` or `other` are in 3D, the distance takes into account the 3 axes.
	# For a 2D point, the Z coordinate is considered to be 0.
	#
	# ~~~
	# var p2 = new Point3d[Float](0.0, 0.0, 0.0)
	# var p3 = new Point3d[Float](2.0, 3.0, 4.0)
	# var p4 = new Point[Float](2.0, 3.0)
	# assert p2.dist(p3).is_approx(5.385, 0.01)
	# assert p2.dist(p4).is_approx(3.606, 0.01)
	# ~~~
	fun dist(other: Point[Numeric]): N
	do
		return x.value_of(dist2(other).to_f.sqrt)
	end

	# Square of the distance with `other`
	#
	# May be used as an approximation to compare distance between two points.
	#
	# ~~~
	# var p0 = new Point[Float](0.0, 0.0)
	# var p1 = new Point[Float](2.0, 3.0)
	# assert p0.dist2(p1) == 13.0
	# ~~~
	#
	# If `self` or `other` are in 3D, the distance takes into account the 3 axes.
	# For a 2D point, the Z coordinate is considered to be 0.
	#
	# ~~~
	# var p2 = new Point3d[Float](0.0, 0.0, 0.0)
	# var p3 = new Point3d[Float](2.0, 3.0, 4.0)
	# var p4 = new Point[Float](2.0, 3.0)
	# assert p2.dist2(p3).is_approx(29.0, 0.01)
	# assert p2.dist2(p4).is_approx(13.0, 0.01)
	# assert p4.dist2(p2).is_approx(13.0, 0.01)
	# ~~~
	fun dist2(other: Point[Numeric]): N
	do return x.value_of(other.dist2_with_2d(self))

	private fun dist2_with_2d(other: IPoint[Numeric]): Numeric
	do return dist2_xy(other)

	private fun dist2_with_3d(other: IPoint3d[Numeric]): Numeric
	do return dist2_xy(other).add(other.z.mul(other.z))

	# Square of the distance with `other` on the X and Y axes
	private fun dist2_xy(other: IPoint[N]): N
	do
		var dx = other.x.sub(x)
		var dy = other.y.sub(y)
		var s = (dx.mul(dx)).add(dy.mul(dy))
		return x.value_of(s)
	end

	# Linear interpolation between `self` and `other` at `p` out of `1.0`
	#
	# ~~~
	# var p0 = new Point[Float](0.0, 0.0)
	# var p1 = new Point[Float](2.0, 3.0)
	# assert p0.lerp(p1, 0.0) == p0
	# assert p0.lerp(p1, 1.0) == p1
	# assert p0.lerp(p1, 0.5) == new Point[Float](1.0, 1.5)
	# ~~~
	#
	# TODO 3D implementation.
	fun lerp(other: Point[Numeric], p: Float): Point[N]
	do
		var xx = x.to_f + (other.x.to_f - x.to_f).to_f * p
		var yy = y.to_f + (other.y.to_f - y.to_f).to_f * p
		return new Point[N](x.value_of(xx), y.value_of(yy))
	end

	redef fun ==(o) do return o isa IPoint[Numeric] and o.x == x and o.y == y
end
lib/geometry/points_and_lines.nit:22,1--114,3

geometry :: boxes $ IPoint
redef class IPoint[N]
	super Boxed[N]

	redef fun left do return x
	redef fun right do return x
	redef fun top do return y
	redef fun bottom do return y
end
lib/geometry/boxes.nit:285,1--292,3