Automatic generation produced by ISE Eiffel

```

Classes
Clusters
Cluster hierarchy
Chart
Relations
Flat contracts
Go to:
note
description: "[
Calculating the energy on a particle depending on dt of the particle.

force := center_attraction * distance (particle_position, center)
+ sum [for all links l element particle links] stiffnes * link_stiffnes (l) * (distance (particle_position, other_particle_position))^2 / 2
+ sum [for all particles p element particles] electrical_repulsion / distance (particle_position, other_particle_position)
where particle position is position of particle + dt * dx/y
]"
legal: "See notice at end of class."
status: "See notice at end of class."
author: "Benno Baumgartner"
date: "\$Date: 2016-01-22 00:57:54 -0900 (Fri, 22 Jan 2016) \$"
revision: "\$Revision: 98412 \$"

class interface
EG_SPRING_ENERGY

create
make_with_particles (a_particles: like particles)
-- Make an EG_PARTICLE_SIMULATION with a_particles interacting with each other.
-- (from EG_PARTICLE_SIMULATION)
require -- from EG_PARTICLE_SIMULATION
a_particles_not_void: a_particles /= Void
not_empty: not a_particles.is_empty
ensure -- from EG_PARTICLE_SIMULATION
set: particles = a_particles

feature -- Access

arc_cosine (v: REAL_64): REAL_64
-- Trigonometric arccosine of radian v
-- in the range [0, pi].
-- (from DOUBLE_MATH)
ensure -- from DOUBLE_MATH
instance_free: class

arc_sine (v: REAL_64): REAL_64
-- Trigonometric arcsine of radian v
-- in the range [-pi/2, +pi/2].
-- (from DOUBLE_MATH)
ensure -- from DOUBLE_MATH
instance_free: class

arc_tangent (v: REAL_64): REAL_64
-- Trigonometric arctangent of radian v
-- in the range [-pi/2, +pi/2].
-- (from DOUBLE_MATH)
ensure -- from DOUBLE_MATH
instance_free: class

ceiling (v: REAL_64): REAL_64
-- Least integral greater than or equal to v.
-- (from DOUBLE_MATH)
ensure -- from DOUBLE_MATH
instance_free: class

center_attraction: REAL_64
-- Attraction of the center for particles.
-- (from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES)

center_x: INTEGER_32
-- X position of the center.
-- (from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES)

center_y: INTEGER_32
-- Y position of the center
-- (from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES)

cosine (v: REAL_64): REAL_64
-- Trigonometric cosine of radian v approximated
-- in the range [-pi/4, +pi/4].
-- (from DOUBLE_MATH)
ensure -- from DOUBLE_MATH
instance_free: class

dabs (v: REAL_64): REAL_64
-- Absolute of v.
-- (from DOUBLE_MATH)
ensure -- from DOUBLE_MATH
instance_free: class

electrical_repulsion: REAL_64
-- Repulsion between particles in the system.
-- (from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES)

Euler: REAL_64 = 2.7182818284590452353602874713526625
-- Logarithm base
-- (from MATH_CONST)

exp (x: REAL_64): REAL_64
-- Exponential of v.
-- (from DOUBLE_MATH)
ensure -- from DOUBLE_MATH
instance_free: class

floor (v: REAL_64): REAL_64
-- Greatest integral less than or equal to v.
-- (from DOUBLE_MATH)
ensure -- from DOUBLE_MATH
instance_free: class

force (a_particle: like particle_type): REAL_64
-- The force affecting a_particle.
-- (from EG_PARTICLE_SIMULATION)
ensure -- from EG_PARTICLE_SIMULATION
result_exists: Result /= Void

generating_type: TYPE [detachable EG_SPRING_ENERGY]
-- Type of current object
-- (type of which it is a direct instance)
-- (from ANY)
ensure -- from ANY
generating_type_not_void: Result /= Void

generator: STRING_8
-- Name of current object's generating class
-- (base class of the type of which it is a direct instance)
-- (from ANY)
ensure -- from ANY
generator_not_void: Result /= Void
generator_not_empty: not Result.is_empty

last_theta_average: REAL_64
-- The average theta value on last call to force.
-- (from EG_PARTICLE_SIMULATION_BH)

log (v: REAL_64): REAL_64
-- Natural logarithm of v.
-- (from DOUBLE_MATH)
ensure -- from DOUBLE_MATH
instance_free: class

log10 (v: REAL_64): REAL_64
-- Base 10 logarithm of v.
-- (from DOUBLE_MATH)
ensure -- from DOUBLE_MATH
instance_free: class

log_2 (v: REAL_64): REAL_64
-- Base 2 logarithm of v.
-- (from DOUBLE_MATH)
ensure -- from DOUBLE_MATH
instance_free: class

particles: LIST [like particle_type]
-- Particles in the system.
-- (from EG_PARTICLE_SIMULATION)

Pi: REAL_64 = 3.1415926535897932384626433832795029
-- (from MATH_CONST)

Pi_2: REAL_64 = 1.5707963267948966192313216916397514
-- (from MATH_CONST)

Pi_4: REAL_64 = 0.7853981633974483096156608458198757
-- (from MATH_CONST)

-- The quad tree to traverse.
-- (from EG_PARTICLE_SIMULATION_BH)

sine (v: REAL_64): REAL_64
-- Trigonometric sine of radian v approximated
-- in range [-pi/4, +pi/4].
-- (from DOUBLE_MATH)
ensure -- from DOUBLE_MATH
instance_free: class

sqrt (v: REAL_64): REAL_64
-- Square root of v.
-- (from DOUBLE_MATH)
ensure -- from DOUBLE_MATH
instance_free: class

Sqrt2: REAL_64 = 1.4142135623730950488016887242096981
-- Square root of 2
-- (from MATH_CONST)

stiffness: REAL_64
-- Stiffness of all links connecting particles.
-- (from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES)

tangent (v: REAL_64): REAL_64
-- Trigonometric tangent of radian v approximated
-- in range [-pi/4, +pi/4].
-- (from DOUBLE_MATH)
ensure -- from DOUBLE_MATH
instance_free: class

theta: REAL_64
-- The higher theta the more approximations are made (see comment in indexing)
-- (from EG_PARTICLE_SIMULATION_BH)

feature -- Comparison

frozen deep_equal (a: detachable ANY; b: like arg #1): BOOLEAN
-- Are a and b either both void
-- or attached to isomorphic object structures?
-- (from ANY)
ensure -- from ANY
instance_free: class
shallow_implies_deep: standard_equal (a, b) implies Result
both_or_none_void: (a = Void) implies (Result = (b = Void))
same_type: (Result and (a /= Void)) implies (b /= Void and then a.same_type (b))
symmetric: Result implies deep_equal (b, a)

frozen equal (a: detachable ANY; b: like arg #1): BOOLEAN
-- Are a and b either both void or attached
-- to objects considered equal?
-- (from ANY)
ensure -- from ANY
instance_free: class
definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.is_equal (b))

frozen is_deep_equal alias "≡≡≡" (other: EG_SPRING_ENERGY): BOOLEAN
-- Are Current and other attached to isomorphic object structures?
-- (from ANY)
require -- from ANY
other_not_void: other /= Void
ensure -- from ANY
shallow_implies_deep: standard_is_equal (other) implies Result
same_type: Result implies same_type (other)
symmetric: Result implies other.is_deep_equal (Current)

is_equal (other: EG_SPRING_ENERGY): BOOLEAN
-- Is other attached to an object considered
-- equal to current object?
-- (from ANY)
require -- from ANY
other_not_void: other /= Void
ensure -- from ANY
symmetric: Result implies other ~ Current
consistent: standard_is_equal (other) implies Result

frozen standard_equal (a: detachable ANY; b: like arg #1): BOOLEAN
-- Are a and b either both void or attached to
-- field-by-field identical objects of the same type?
-- Always uses default object comparison criterion.
-- (from ANY)
ensure -- from ANY
instance_free: class
definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.standard_is_equal (b))

frozen standard_is_equal alias "≜" (other: EG_SPRING_ENERGY): BOOLEAN
-- Is other attached to an object of the same type
-- as current object, and field-by-field identical to it?
-- (from ANY)
require -- from ANY
other_not_void: other /= Void
ensure -- from ANY
same_type: Result implies same_type (other)
symmetric: Result implies other.standard_is_equal (Current)

feature -- Status report

conforms_to (other: ANY): BOOLEAN
-- Does type of current object conform to type
-- of other (as per Eiffel: The Language, chapter 13)?
-- (from ANY)
require -- from ANY
other_not_void: other /= Void

same_type (other: ANY): BOOLEAN
-- Is type of current object identical to type of other?
-- (from ANY)
require -- from ANY
other_not_void: other /= Void
ensure -- from ANY
definition: Result = (conforms_to (other) and other.conforms_to (Current))

feature -- Element change

set_center (ax, ay: INTEGER_32)
-- Set center_x to ax and center_y to ay.
-- (from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES)
ensure -- from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES
set: center_x = ax and center_y = ay

set_center_attraction (a_value: REAL_64)
-- Set center_attraction to a_value.
-- (from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES)
require -- from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES
valid_value: a_value >= 0.0
ensure -- from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES
set: center_attraction = a_value

set_electrical_repulsion (a_value: REAL_64)
-- Set electrical_repulsion to a_value.
-- (from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES)
require -- from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES
valid_value: a_value >= 0.0
ensure -- from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES
set: electrical_repulsion = a_value

set_stiffness (a_value: REAL_64)
-- Set stiffness to a_value.
-- (from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES)
require -- from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES
valid_value: a_value >= 0.0
ensure -- from EG_FORCE_DIRECTED_PHYSICS_PROPERTIES
set: stiffness = a_value

feature -- Duplication

copy (other: EG_SPRING_ENERGY)
-- Update current object using fields of object attached
-- to other, so as to yield equal objects.
-- (from ANY)
require -- from ANY
other_not_void: other /= Void
type_identity: same_type (other)
ensure -- from ANY
is_equal: Current ~ other

frozen deep_copy (other: EG_SPRING_ENERGY)
-- Effect equivalent to that of:
--		copy (other . deep_twin)
-- (from ANY)
require -- from ANY
other_not_void: other /= Void
ensure -- from ANY
deep_equal: deep_equal (Current, other)

frozen deep_twin: EG_SPRING_ENERGY
-- New object structure recursively duplicated from Current.
-- (from ANY)
ensure -- from ANY
deep_twin_not_void: Result /= Void
deep_equal: deep_equal (Current, Result)

frozen standard_copy (other: EG_SPRING_ENERGY)
-- Copy every field of other onto corresponding field
-- of current object.
-- (from ANY)
require -- from ANY
other_not_void: other /= Void
type_identity: same_type (other)
ensure -- from ANY
is_standard_equal: standard_is_equal (other)

frozen standard_twin: EG_SPRING_ENERGY
-- New object field-by-field identical to other.
-- Always uses default copying semantics.
-- (from ANY)
ensure -- from ANY
standard_twin_not_void: Result /= Void
equal: standard_equal (Result, Current)

frozen twin: EG_SPRING_ENERGY
-- New object equal to Current
-- twin calls copy; to change copying/twinning semantics, redefine copy.
-- (from ANY)
ensure -- from ANY
twin_not_void: Result /= Void
is_equal: Result ~ Current

feature -- Basic operations

frozen default: detachable EG_SPRING_ENERGY
-- Default value of object's type
-- (from ANY)

frozen default_pointer: POINTER
-- Default value of type POINTER
-- (Avoid the need to write p.default for
-- some p of type POINTER.)
-- (from ANY)
ensure -- from ANY
instance_free: class

default_rescue
-- Process exception for routines with no Rescue clause.
-- (Default: do nothing.)
-- (from ANY)

frozen do_nothing
-- Execute a null action.
-- (from ANY)
ensure -- from ANY
instance_free: class

feature -- Implementation

between (n, a, b: REAL_64): BOOLEAN
-- Is n a value between a and b?
-- (from EV_MODEL_DOUBLE_MATH)
ensure -- from EV_MODEL_DOUBLE_MATH
instance_free: class

delta_x (angle: REAL_64; length: REAL_64): REAL_64
-- Get dx component of line segment with length and angle.
-- (from EV_MODEL_DOUBLE_MATH)
ensure -- from EV_MODEL_DOUBLE_MATH
instance_free: class

delta_y (angle: REAL_64; length: REAL_64): REAL_64
-- Get dy component of line segment with length and angle.
-- (from EV_MODEL_DOUBLE_MATH)
ensure -- from EV_MODEL_DOUBLE_MATH
instance_free: class

distance (x1, y1, x2, y2: REAL_64): REAL_64
-- Calculate distance between (x1, y1) and (x2, y2).
-- (from EV_MODEL_DOUBLE_MATH)
ensure -- from EV_MODEL_DOUBLE_MATH
instance_free: class

distance_from_line (x, y, x1, y1, x2, y2: REAL_64): REAL_64
-- Calculate distance between (x, y) and (x1, y1)-(x2, y2).
-- The line is considered to be infinite.
-- (from EV_MODEL_DOUBLE_MATH)
ensure -- from EV_MODEL_DOUBLE_MATH
instance_free: class

line_angle (x1, y1, x2, y2: REAL_64): REAL_64
-- Return angle of line from (x1, y1) to (x2, y2) relative to world.
-- clockwise. 0.0 is 3 o'clock.
-- (from EV_MODEL_DOUBLE_MATH)
ensure -- from EV_MODEL_DOUBLE_MATH
instance_free: class

modulo (a, b: REAL_64): REAL_64
-- a modulo b.
-- (from EV_MODEL_DOUBLE_MATH)
require -- from EV_MODEL_DOUBLE_MATH
divisible: b /= 0.0
ensure -- from EV_MODEL_DOUBLE_MATH
in_interval: Result >= 0.0 and Result < b
instance_free: class

point_on_ellipse (x, y, xc, yc, r1, r2: REAL_64): BOOLEAN
-- Is (x, y) inside specified ellipse?
-- (from EV_MODEL_DOUBLE_MATH)
ensure -- from EV_MODEL_DOUBLE_MATH
equals_point_on_rotated: Result = point_on_rotated_ellipse (x, y, xc, yc, r1, r2, 0.0)
instance_free: class

point_on_ellipse_boundary (x, y, xc, yc, r1, r2, width: REAL_64): BOOLEAN
-- Is (x, y) on specified ellipse border?
-- (from EV_MODEL_DOUBLE_MATH)
ensure -- from EV_MODEL_DOUBLE_MATH
instance_free: class

point_on_line (x, y, x1, y1, x2, y2, width: REAL_64): BOOLEAN
-- Is (x, y) on line from (x2, y2) to (x1, y1) with width?
-- (from EV_MODEL_DOUBLE_MATH)
ensure -- from EV_MODEL_DOUBLE_MATH
instance_free: class

point_on_polygon (x, y: REAL_64; points: SPECIAL [EV_COORDINATE]): BOOLEAN
-- Is (x, y) contained in polygon with points?
-- Based on code by Hanpeter van Vliet.
-- (from EV_MODEL_DOUBLE_MATH)
ensure -- from EV_MODEL_DOUBLE_MATH
instance_free: class

point_on_rectangle (x, y, x1, y1, x2, y2: REAL_64): BOOLEAN
-- Is (x, y) inside specified box?
-- (from EV_MODEL_DOUBLE_MATH)
ensure -- from EV_MODEL_DOUBLE_MATH
instance_free: class

point_on_rotated_ellipse (x, y, xc, yc, r1, r2, angle: REAL_64): BOOLEAN
-- Is ('x', y) inside specified ellipse?
-- (from EV_MODEL_DOUBLE_MATH)
ensure -- from EV_MODEL_DOUBLE_MATH
instance_free: class

point_on_rotated_ellipse_boundary (x, y, xc, yc, r1, r2, angle, width: REAL_64): BOOLEAN
-- Is (x, y) on specified ellipse border?
-- (from EV_MODEL_DOUBLE_MATH)
ensure -- from EV_MODEL_DOUBLE_MATH
instance_free: class

point_on_segment (x, y, x1, y1, x2, y2, width: REAL_64): BOOLEAN
-- Is (x, y) on segment [(x2, y2), (x1, y1)] with width?
-- (from EV_MODEL_DOUBLE_MATH)
ensure -- from EV_MODEL_DOUBLE_MATH
instance_free: class

feature -- Element change.

set_particles (a_particles: like particles)
-- Set particles to a_particles and build quad_tree.
-- (from EG_PARTICLE_SIMULATION_BH)
require -- from EG_PARTICLE_SIMULATION
a_particles_not_void: a_particles /= Void
not_empty: not a_particles.is_empty
ensure -- from EG_PARTICLE_SIMULATION
set: particles = a_particles
ensure then -- from EG_PARTICLE_SIMULATION_BH

set_theta (a_theta: like theta)
-- Set theta to a_theta.
-- (from EG_PARTICLE_SIMULATION_BH)
require -- from EG_PARTICLE_SIMULATION_BH
a_theta_in_range: theta >= 0.to_double and theta <= 1.0
ensure -- from EG_PARTICLE_SIMULATION_BH
set: theta = a_theta

feature -- Output

Io: STD_FILES
-- Handle to standard file setup
-- (from ANY)
ensure -- from ANY
instance_free: class
io_not_void: Result /= Void

out: STRING_8
-- New string containing terse printable representation
-- of current object
-- (from ANY)
ensure -- from ANY
out_not_void: Result /= Void

print (o: detachable ANY)
-- Write terse external representation of o
-- on standard output.
-- (from ANY)
ensure -- from ANY
instance_free: class

frozen tagged_out: STRING_8
-- New string containing terse printable representation
-- of current object
-- (from ANY)
ensure -- from ANY
tagged_out_not_void: Result /= Void

feature -- Platform

Operating_environment: OPERATING_ENVIRONMENT
-- Objects available from the operating system
-- (from ANY)
ensure -- from ANY
instance_free: class
operating_environment_not_void: Result /= Void

invariant
-- from EG_PARTICLE_SIMULATION_BH

-- from EG_PARTICLE_SIMULATION
particles_exist: particles /= Void
particles_not_empty: not particles.is_empty

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

note
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"

end -- class EG_SPRING_ENERGY

Classes
Clusters
Cluster hierarchy
Chart
Relations
Flat contracts
Go to:
```

-- Generated by Eiffel Studio --
For more details: eiffel.org