2. Algorithms

2.1. Enumerations

enum bimpp::plan2d::algorithm::room_side

An enum, it means the direction of the room’s edges.

Values:

enumerator room_side_both

Don’t know the room faces inside or outside.

enumerator room_side_in

The room faces inside.

enumerator room_side_out

The room faces outside.

2.2. Data structures

Define some data for algorithm.

class wall_ex
class node_ex
class room_ex

2.3. Functions

They implement some algorithms that.

template<typename TItem>
static inline bool bimpp::plan2d::algorithm::isContainsForBiggerVector(const std::vector<TItem> &_all, const std::vector<TItem> &_sub)

Is the _all contains _sub?

Importance: The _all and _sub must be sorted from small to big.

Parameters
  • _all: A vector contains all items

  • _sub: A vector contains a part of items

static inline precision_type bimpp::plan2d::algorithm::calculateAngleEx(const node_type &_o, const node_type &_a, const node_type &_b)

Calculate the angle \( \alpha \) between \( \vec{OA} \) and \( \vec{OB} \).

\[\begin{split} f(\vec{OA}, \vec{OB}) = \begin{cases} \cos^{-1}(\vec{OA} \cdot \vec{OB}) & \quad \text{if } 0^{\circ} \leq \alpha \leq 180^{\circ}\\ \pi * 2 - \cos^{-1}(\vec{OA} \cdot \vec{OB}) & \quad \text{if } 180^{\circ} < \alpha < 360^{\circ} \end{cases} \end{split}\]

Parameters
  • _o: The \( {O} \) node(point)

  • _a: The \( {A} \) node(point)

  • _b: The \( {B} \) node(point)

_images/plot_angleex.png

x-axis: \(cos(\alpha)\); y-axis: \(\alpha\) in radians

static inline precision_type bimpp::plan2d::algorithm::calculateSinAngleEx(const node_type &_o, const node_type &_a, const node_type &_b)

Calculate the increased sine of a angle \( \alpha \) between \( \vec{OA} \) and \( \vec{OB} \).

\[\begin{split} f(\vec{OA}, \vec{OB}) = \begin{cases} \vert\vec{OA} \times \vec{OB}\vert & \quad \text{if } 0^{\circ} \leq \alpha \leq 90^{\circ}\\ 2 - \vert\vec{OA} \times \vec{OB}\vert & \quad \text{if } 90^{\circ} < \alpha < 270^{\circ}\\ 4 + \vert\vec{OA} \times \vec{OB}\vert & \quad \text{if } 270^{\circ} \leq \alpha < 360^{\circ} \end{cases} \end{split}\]

Parameters
  • _o: The \( {O} \) node(point)

  • _a: The \( {A} \) node(point)

  • _b: The \( {B} \) node(point)

_images/plot_sinex.png

x-axis: \(\alpha\) in radians; y-axis: increased \(sin(\alpha)\)

static inline precision_type bimpp::plan2d::algorithm::calculateCosAngleEx(const node_type &_o, const node_type &_a, const node_type &_b)

Calculate the increased cosine of a angle \( \alpha \) between \( \vec{OA} \) and \( \vec{OB} \).

\[\begin{split} f(\vec{OA}, \vec{OB}) = \begin{cases} 1 - \vec{OA} \cdot \vec{OB} & \quad \text{if } 0^{\circ} \leq \alpha \leq 180^{\circ}\\ 3 + \vec{OA} \cdot \vec{OB} & \quad \text{if } 180^{\circ} < \alpha < 360^{\circ} \end{cases} \end{split}\]

Parameters
  • _o: The \( {O} \) node(point)

  • _a: The \( {A} \) node(point)

  • _b: The \( {B} \) node(point)

_images/plot_cosex.png

x-axis: \(\alpha\) in radians; y-axis: increased \(cos(\alpha)\)

static inline bool bimpp::plan2d::algorithm::computeRoomExs(const house_type &_house, room_ex_vector &_room_exs, id_type _room_id = TConstant::none_id)

Compute all room’s edges by all walls, and don’t use recursion.

Parameters
  • _house: The house

  • _room_exs: Output the room’s edge list

  • _room_id: The special id of room, find all rooms if it is none

_images/side_type.png

This function computes some edges of all areas that are wrapped by colourful lines.

  • Blue lines: Means the room_ex is inside of the lines, and the side_type is bimpp::plan2d::algorithm::room_side_in.

  • Green lines: Means the room_ex is outside of the lines, and the side_type is bimpp::plan2d::algorithm::room_side_out.

  • Red lines: Means the room_ex is both inside and outside of the lines, and the side_type is bimpp::plan2d::algorithm::room_side_both.