Eiffel Media API
Overview Cluster Class Classes Index      Previous Next      Top Features

em.utility

Class EM_ORTHOGONAL_RECTANGLE


Known direct descendants

EM_RECTANGLE

Creation

Features

Invariants

indexing

description

Orthogonal rectangular areas.

date

$Date: 2005/10/24 04:01:08 $

revision

$Revision: 1.6 $

class

EM_ORTHOGONAL_RECTANGLE

create

make (a_point_a, a_point_b: EM_VECTOR_2D)

-- Create a new rectangle from a_point_a and a_point_b.

require
a_point_a_not_void: a_point_a /= Void
a_point_b_not_void: a_point_b /= Void
ensure
point_a_set: point_a = a_point_a
point_b_set: point_b = a_point_b
make_from_coordinates (x1, y1, x2, y2: DOUBLE)

-- Create a rectangle from DOUBLE coordinates.

ensure
point_a_set: point_a.x = x1 and then point_a.y = y1
point_b_set: point_b.x = x2 and then point_b.y = y2
make_from_position_and_size (x1, y1, a_width, a_height: DOUBLE)

-- Create a rectangle with upper left corner x1, y1
-- and a_width, a_height.

require
a_width_not_negative: a_width >= 0.0
a_height_not_negative: a_height >= 0.0
ensure
upper_left_set: upper_left.x = x1 and then upper_left.y = y1
size_set: width = a_width and then height = a_height
make_from_rectangle (a_rectangle: EM_ORTHOGONAL_RECTANGLE)

-- Initialize from a_rectangle.

require
a_rectangle_not_void: a_rectangle /= Void
ensure
initialized_as_a_rectangle: point_a.is_equal (a_rectangle.point_a) and then point_b.is_equal (a_rectangle.point_b)

feature -- Initialization

make (a_point_a, a_point_b: EM_VECTOR_2D)

-- Create a new rectangle from a_point_a and a_point_b.

require
a_point_a_not_void: a_point_a /= Void
a_point_b_not_void: a_point_b /= Void
ensure
point_a_set: point_a = a_point_a
point_b_set: point_b = a_point_b
make_from_coordinates (x1, y1, x2, y2: DOUBLE)

-- Create a rectangle from DOUBLE coordinates.

ensure
point_a_set: point_a.x = x1 and then point_a.y = y1
point_b_set: point_b.x = x2 and then point_b.y = y2
make_from_position_and_size (x1, y1, a_width, a_height: DOUBLE)

-- Create a rectangle with upper left corner x1, y1
-- and a_width, a_height.

require
a_width_not_negative: a_width >= 0.0
a_height_not_negative: a_height >= 0.0
ensure
upper_left_set: upper_left.x = x1 and then upper_left.y = y1
size_set: width = a_width and then height = a_height
make_from_rectangle (a_rectangle: EM_ORTHOGONAL_RECTANGLE)

-- Initialize from a_rectangle.

require
a_rectangle_not_void: a_rectangle /= Void
ensure
initialized_as_a_rectangle: point_a.is_equal (a_rectangle.point_a) and then point_b.is_equal (a_rectangle.point_b)

feature -- Access

point_a: EM_VECTOR_2D

-- One corner point of the rectangle

point_b: EM_VECTOR_2D

-- The other corner point of the rectangle

feature -- Status report

height: DOUBLE

-- Height of Current

size: DOUBLE

-- Size of Current.

ensure
size_calculated: size > width * height - eps and size < width * height + eps
width: DOUBLE

-- Width of Current

feature -- Element change

down_by (a_distance: DOUBLE)

-- Move Current down by a_distance.

ensure
upper_bound_moved_down: upper_bound > old upper_bound + a_distance - eps and upper_bound < old upper_bound + a_distance + eps
lower_bound_moved_down: lower_bound > old lower_bound + a_distance - eps and lower_bound < old lower_bound + a_distance + eps
extend (a_point: EM_VECTOR_2D)

-- Resize Current to contain a_point.

require
a_point_attached: a_point /= Void
ensure
has_a_point: has (a_point)
left_by (a_distance: DOUBLE)

-- Move Current left by a_distance.

ensure
left_bound_moved_left: left_bound > old left_bound - a_distance - eps and left_bound < old left_bound - a_distance + eps
right_bound_moved_left: right_bound > old right_bound - a_distance - eps and right_bound < old right_bound - a_distance + eps
move_by (a_distance: EM_VECTOR_2D)

-- Move Current by the vector a_distance.

require
a_distance_not_void: a_distance /= Void
a_distance_not_point_a: a_distance /= point_a
a_distance_not_point_b: a_distance /= point_b
ensure
left_bound_moved: left_bound > old left_bound +a_distance.x - eps and left_bound < old left_bound + a_distance.x + eps
right_bound_moved: right_bound > old right_bound + a_distance.x - eps and right_bound < old right_bound + a_distance.x + eps
upper_bound_moved: upper_bound > old upper_bound + a_distance.y - eps and upper_bound < old upper_bound + a_distance.y + eps
lower_bound_moved: lower_bound > old lower_bound + a_distance.y - eps and lower_bound < old lower_bound + a_distance.y + eps
move_center_to (a_position: EM_VECTOR_2D)

-- Move center to a_position.

require
a_position_not_void: a_position /= Void
ensure
size_unchanged: size = old size
move_to (a_position: EM_VECTOR_2D)

-- Move upper_left to a_position.

require
a_position_not_void: a_position /= Void
ensure
size_unchanged: size = old size
right_by (a_distance: DOUBLE)

-- Move Current right by a_distance.

ensure
left_bound_moved_right: left_bound > old left_bound + a_distance - eps and left_bound < old left_bound + a_distance + eps
right_bound_moved_right: right_bound > old right_bound + a_distance - eps and right_bound < old right_bound + a_distance + eps
scale (a_factor: DOUBLE)

-- Scalar multiplication by a_factor

set_size (a_width, a_height: DOUBLE)

-- Set size to a_width and a_height
-- by not changing upper_left

require
a_width_not_negative: a_width >= 0
a_height_not_negative: a_height >= 0
ensure
upper_left_kept: upper_left.is_equal (old upper_left)
set_size_centered (a_width, a_height: DOUBLE)

-- Set size to a_width and a_height
-- by not changing center

require
a_width_not_negative: a_width >= 0
a_height_not_negative: a_height >= 0
up_by (a_distance: DOUBLE)

-- Move Current up by a_distance.

ensure
upper_bound_moved_up: upper_bound > old upper_bound - a_distance - eps and upper_bound < old upper_bound - a_distance + eps
lower_bound_moved_up: lower_bound > old lower_bound - a_distance - eps and lower_bound < old lower_bound - a_distance + eps
zoom (a_factor: DOUBLE)

-- Zoom Current by a_factor with respect to center.

feature -- Change Processing

process_changes

-- Process changes of Current rectangle state.
-- (Can be redefined by descendants to do something
-- whenever the state of Current rectangle changes)

feature -- Queries

center: EM_VECTOR_2D

-- Center of Current

ensure
result_not_void: Result /= Void
has (a_coordinate: EM_VECTOR_2D): BOOLEAN

-- Is a_coordinate inside Current?

require
a_coordinate_not_void: a_coordinate /= Void
intersection (other: like Current): like Current

-- Overlaping area of Current with other.

require
other_not_void: other /= Void
ensure
zero_sized_result_when_not_overlaping: not intersects (other) implies Result.size = 0
intersects (other: like Current): BOOLEAN

-- Do Current and other overlap?

require
other_not_void: other /= Void
left_bound: DOUBLE

-- Upper bound of Current

lower_bound: DOUBLE

-- Upper bound of Current

lower_left: EM_VECTOR_2D

-- Lower-left corner of Current

ensure
result_not_void: Result /= Void
lower_right: EM_VECTOR_2D

-- Lower-right corner of Current

ensure
result_not_void: Result /= Void
right_bound: DOUBLE

-- Upper bound of Current

upper_bound: DOUBLE

-- Upper bound of Current

upper_left: EM_VECTOR_2D

-- Upper-left corner of Current

ensure
result_not_void: Result /= Void
upper_right: EM_VECTOR_2D

-- Upper-right corner of Current

ensure
result_not_void: Result /= Void

feature -- Output

out: STRING

-- Return readable string.

-- (From ANY)

feature -- Constants

eps: DOUBLE

-- Epsilon for assertions with DOUBLES

invariant

width_not_negative: width >= 0
height_not_negative: height >= 0
point_a_not_void: point_a /= Void
point_b_not_void: point_b /= Void

-- From ANY
reflexive_equality: standard_is_equal (Current)
reflexive_conformance: conforms_to (Current)

end