A 2d bounded object and an implementation of Boxed

This class offers many constructors specialized for different usage. They are named according to the order of their arguments.

Introduced properties

init around(boxed: Boxed[N]...)

geometry :: Box :: around

Create a Box covering all of the boxed
protected fun bottom=(bottom: N)

geometry :: Box :: bottom=

init defaultinit(left: N, right: N, top: N, bottom: N)

geometry :: Box :: defaultinit

init lbwh(left: N, bottom: N, width: N, height: N)

geometry :: Box :: lbwh

Create a Box using left, bottom, width and height
protected fun left=(left: N)

geometry :: Box :: left=

init lrbt(left: N, right: N, bottom: N, top: N)

geometry :: Box :: lrbt

Create a Box using left, right, bottom and top
init lrtb(left: N, right: N, top: N, bottom: N)

geometry :: Box :: lrtb

Create a Box using left, right, top and bottom
init ltwh(left: N, top: N, width: N, height: N)

geometry :: Box :: ltwh

Create a Box using left, top, width and height
protected fun right=(right: N)

geometry :: Box :: right=

protected fun top=(top: N)

geometry :: Box :: top=

Redefined properties

redef type SELF: Box[N]

geometry $ Box :: SELF

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

geometry $ Box :: bottom

Bottom bound
redef fun left: N

geometry $ Box :: left

Left bound
redef fun right: N

geometry $ Box :: right

Right bound
redef fun top: N

geometry $ Box :: 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
init around(boxed: Boxed[N]...)

geometry :: Box :: around

Create a Box covering all of the boxed
abstract fun bottom: N

geometry :: Boxed :: bottom

Bottom bound
protected fun bottom=(bottom: N)

geometry :: Box :: bottom=

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?
init defaultinit(left: N, right: N, top: N, bottom: N)

geometry :: Box :: defaultinit

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.
init lbwh(left: N, bottom: N, width: N, height: N)

geometry :: Box :: lbwh

Create a Box using left, bottom, width and height
abstract fun left: N

geometry :: Boxed :: left

Left bound
protected fun left=(left: N)

geometry :: Box :: left=

init lrbt(left: N, right: N, bottom: N, top: N)

geometry :: Box :: lrbt

Create a Box using left, right, bottom and top
init lrtb(left: N, right: N, top: N, bottom: N)

geometry :: Box :: lrtb

Create a Box using left, right, top and bottom
init ltwh(left: N, top: N, width: N, height: N)

geometry :: Box :: ltwh

Create a Box using left, top, width and height
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
protected fun right=(right: N)

geometry :: Box :: right=

fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
abstract fun top: N

geometry :: Boxed :: top

Top bound
protected fun top=(top: N)

geometry :: Box :: top=

package_diagram geometry::Box Box geometry::Boxed Boxed geometry::Box->geometry::Boxed core::Object Object geometry::Boxed->core::Object ...core::Object ... ...core::Object->core::Object geometry::Box3d Box3d geometry::Box3d->geometry::Box

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

interface Boxed[N: Numeric]

geometry :: Boxed

An 2d abstract bounded object

Children

class Box3d[N: Numeric]

geometry :: Box3d

A 3d bounded object and an implementation of Boxed

Class definitions

geometry $ Box
# A 2d bounded object and an implementation of `Boxed`
#
# This class offers many constructors specialized for different usage. They are
# named according to the order of their arguments.
class Box[N: Numeric]
	super Boxed[N]

	redef var left: N
	redef var right: N
	redef var top: N
	redef var bottom: N

	# Create a `Box` covering all of the `boxed`
	#
	#     var box = new Box[Int].around(new Point[Int](-4,-4), new Point[Int](4,4))
	#     assert box.left == -4 and box.bottom == -4
	#     assert box.right == 4 and box.top == 4
	init around(boxed: Boxed[N]...)
	do
		assert not boxed.is_empty

		var left: nullable N = null
		var right: nullable N = null
		var top: nullable N = null
		var bottom: nullable N = null

		for box in boxed do
			if left == null or box.left < left then left = box.left
			if right == null or box.right > right then right = box.right
			if top == null or box.top > top then top = box.top
			if bottom == null or box.bottom < bottom then bottom = box.bottom
		end

		assert left != null and right != null and top != null and bottom != null

		init(left, right, top, bottom)
	end

	# Create a `Box` using left, right, bottom and top
	init lrbt(left, right, bottom, top: N)
	do
		init(left, right, top, bottom)
	end

	# Create a `Box` using left, right, top and bottom
	init lrtb(left, right, top, bottom: N)
	do
		init(left, right, top, bottom)
	end

	# Create a `Box` using left, bottom, width and height
	init lbwh(left, bottom, width, height: N)
	do
		init(left, left + width, bottom + height, bottom)
	end

	# Create a `Box` using left, top, width and height
	init ltwh(left, top, width, height: N)
	do
		init(left, left+width, top, top - height)
	end
end
lib/geometry/boxes.nit:90,1--151,3