Angle related service using Float to represent an angle in radians

Redefined classes

redef enum Float

geometry :: angles $ Float

Native floating point numbers.
redef class Point[N: Numeric]

geometry :: angles $ Point

2D point with x and z

All class definitions

redef enum Float

geometry :: angles $ Float

Native floating point numbers.
redef class Point[N: Numeric]

geometry :: angles $ Point

2D point with x and z
package_diagram geometry::angles angles geometry::points_and_lines points_and_lines geometry::angles->geometry::points_and_lines serialization serialization geometry::points_and_lines->serialization ...serialization ... ...serialization->serialization geometry::geometry geometry geometry::geometry->geometry::angles gamnit::cameras cameras gamnit::cameras->geometry::geometry gamnit::cameras... ... gamnit::cameras...->gamnit::cameras

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module caching

serialization :: caching

Services for caching serialization engines
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module engine_tools

serialization :: engine_tools

Advanced services for serialization engines
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module inspect

serialization :: inspect

Refine Serializable::inspect to show more useful information
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module list

core :: list

This module handle double linked lists
module math

core :: math

Mathematical operations
module meta

meta :: meta

Simple user-defined meta-level to manipulate types of instances as object.
module native

core :: native

Native structures for text and bytes
module numeric

core :: numeric

Advanced services for Numeric types
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module serialization

serialization :: serialization

General serialization services
module serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O

Parents

module points_and_lines

geometry :: points_and_lines

Interfaces and classes to represent basic geometry needs.

Children

module geometry

geometry :: geometry

Provides interfaces and classes to represent basic geometry needs.

Descendants

module a_star-m

a_star-m

module bmfont

gamnit :: bmfont

Parse Angel Code BMFont format and draw text
module camera_control

gamnit :: camera_control

Simple camera control for user, as the method accept_scroll_and_zoom
module camera_control_android

gamnit :: camera_control_android

Two fingers camera manipulation, pinch to zoom and slide to scroll
module camera_control_linux

gamnit :: camera_control_linux

Mouse wheel and middle mouse button to control camera
module cameras

gamnit :: cameras

Camera services producing Model-View-Projection matrices
module cameras_cache

gamnit :: cameras_cache

Cache the Matrix produced by Camera::mvp_matrix
module cardboard

gamnit :: cardboard

Update the orientation of world_camera at each frame using the head position given by android::cardboard
module depth

gamnit :: depth

Framework for 3D games in Nit
module depth_core

gamnit :: depth_core

Base entities of the depth 3D game framework
module flat

gamnit :: flat

Simple API for 2D games, built around Sprite and App::update
module flat_core

gamnit :: flat_core

Core services for the flat API for 2D games
module font

gamnit :: font

Abstract font drawing services, implemented by bmfont and tileset
module model_dimensions

gamnit :: model_dimensions

Dimensions related services for Model and Mesh
module more_lights

gamnit :: more_lights

More implementations of Light
module more_materials

gamnit :: more_materials

Various material implementations
module more_meshes

gamnit :: more_meshes

More simple geometric meshes
module more_models

gamnit :: more_models

Services to load models from the assets folder
module particles

gamnit :: particles

Particle effects
module selection

gamnit :: selection

Select Actor from a screen coordinate
module shadow

gamnit :: shadow

Shadow mapping using a depth texture
module stereoscopic_view

gamnit :: stereoscopic_view

Refine EulerCamera and App::frame_core_draw to get a stereoscopic view
module tileset

gamnit :: tileset

Support for TileSet, TileSetFont and drawing text with TextSprites
module virtual_gamepad

gamnit :: virtual_gamepad

Virtual gamepad mapped to keyboard keys for quick and dirty mobile support
module vr

gamnit :: vr

VR support for gamnit depth, for Android only
# Angle related service using `Float` to represent an angle in radians
module angles

import points_and_lines

redef class Point[N]
	# Arctangent function using the difference between `self` and `other` as trigonometric ratio
	#
	# Behave similarly to the toplevel `atan2` as it returns the angle in the appropriate quadrant.
	#
	# ~~~
	# var p0 = new Point[Float](0.0, 0.0)
	# var p1 = new Point[Float](1.0, 1.0)
	# assert p0.atan2(p1).is_approx(0.25*pi, 0.0001)
	# ~~~
	fun atan2(other: Point[N]): Float
	do
		var dx = other.x.to_f - x.to_f
		var dy = other.y.to_f - y.to_f
		return sys.atan2(dy.to_f, dx.to_f)
	end
end

redef universal Float
	# Normalize the `self` angle in radians to be within `[-pi .. pi[`
	#
	# ~~~
	# assert (1.5*pi).angle_normalize.is_approx(-0.5*pi, 0.0001)
	# assert 8.0.angle_normalize.is_approx(1.7168, 0.0001)
	# assert (-1.0).angle_normalize == -1.0
	# ~~~
	fun angle_normalize: Float
	do
		var s = self
		while s < -pi do s += 2.0*pi
		while s >= pi do s -= 2.0*pi
		return s
	end

	# Linear interpolation of between the angles `a` and `b`, in radians
	#
	# The result is normalized with `angle_normalize`.
	#
	# ~~~
	# assert 0.5.angle_lerp(0.0, pi).is_approx(0.5*pi, 0.0001)
	# assert 8.5.angle_lerp(0.0, pi).is_approx(0.5*pi, 0.0001)
	# assert 7.5.angle_lerp(0.0, pi).is_approx(-0.5*pi, 0.0001)
	# assert 0.5.angle_lerp(0.2, 2.0*pi-0.1).is_approx(0.05, 0.0001)
	# ~~~
	fun angle_lerp(a, b: Float): Float
	do
		var d = b - a
		while d > pi do d -= 2.0*pi
		while d < -pi do d += 2.0*pi
		return (a + d*self).angle_normalize
	end
end
lib/geometry/angles.nit:15,1--71,3