vanilladocs
vanillapunch.com
API / ui/autolayout/layoutrow

ui/autolayout/layoutrow

솔버 안의 행. (원본 ui/autolayout/layoutrow.js 의 LayoutRow)

  • tableau 의 한 행이다. 셀(심볼 -> 계수)과 상수항.
  • 바꾸는 함수는 모두 그 자리에서 바꾼다.
  • 원본과 다른 것:
  • 셀은 원본 Map 처럼 넣은 차례를 지키는 LayoutSymbolMap 이다.
  • 원본 copy() 는 Clone 이다. (차례까지 같은 사본)
  • 생략할 수 있던 coefficient(기본 1)는 꼭 받는다.
  • 원본이 행과 솔버에 따로 둔 0 근접 판정은 near_zero 하나를 같이 쓴다.

A row inside the solver. (LayoutRow of the original ui/autolayout/layoutrow.js)

  • One row of the tableau. Cells (symbol -> coefficient) and a constant.
  • All functions that change it change it in place.
  • Differences from the original:
  • Cells are a LayoutSymbolMap that keeps insertion order like the original Map.
  • The original copy() is Clone. (a copy identical down to the order)
  • coefficient, which could be omitted (default 1), is required.
  • The near-zero check that the original kept separately in the row and the solver is shared as a single near_zero.

LayoutRowstruct traits Clone, Debug

소스source

솔버 안의 행.

  • 솔버 안에서 쓰는 값이다. 사용자 코드는 보통 LayoutVariable 과 LayoutSolver 만 쓴다.

A row inside the solver.

  • A value used inside the solver. User code usually uses only LayoutVariable and LayoutSolver.
예제Example10 + 2x + 4s = 0 을 x 에 대해 풀기Solving 10 + 2x + 4s = 0 for x
use vanilla::ui::autolayout::layoutrow::LayoutRow;
use vanilla::ui::autolayout::layoutsymbol::LayoutSymbol;
use vanilla::ui::autolayout::layoutsymboltype::LayoutSymbolType;

let x = LayoutSymbol::new(LayoutSymbolType::External);
let slack = LayoutSymbol::new(LayoutSymbolType::Slack);
let mut row = LayoutRow::new(10.0);
row.insert_symbol(x, 2.0);
row.insert_symbol(slack, 4.0);
row.solve_for(x);
assert_eq!(row.get_constant(), -5.0);
assert_eq!(row.coefficient_for(slack), -2.0);
assert_eq!(row.coefficient_for(x), 0.0);
생성자constructorpub fn new(constant: f64) -> LayoutRow#0.4.0 부터since 0.4.0소스source

생성. (constant 는 처음 상수항)

Constructor. (constant is the initial constant)

constantf64
처음 상수항.Initial constant.

반환ReturnsLayoutRow 셀이 없는 새 행.A new row with no cells.

메서드methodpub fn get_cells(&self) -> &LayoutSymbolMap<f64>#0.4.0 부터since 0.4.0소스source

셀 맵 반환.

Returns the cell map.

반환Returns&LayoutSymbolMap<f64> 셀 맵(심볼 -> 계수, 넣은 차례)의 참조.Reference to the cell map (symbol -> coefficient, insertion order).

메서드methodpub fn get_constant(&self) -> f64#0.4.0 부터since 0.4.0소스source

상수항 반환.

Returns the constant term.

반환Returnsf64 상수항.Constant term.

메서드methodpub fn set_constant(&mut self, constant: f64)#0.4.0 부터since 0.4.0소스source

상수항 설정.

Sets the constant.

constantf64
새 상수항.New constant.
메서드methodpub fn add_constant(&mut self, value: f64) -> f64#0.4.0 부터since 0.4.0소스source

상수항에 값을 더한다. (새 상수항을 돌려준다)

Adds a value to the constant. (returns the new constant)

valuef64
상수항에 더할 값.Value to add to the constant.

반환Returnsf64 더한 뒤의 상수항.The constant after adding.

메서드methodpub fn insert_symbol(&mut self, symbol: LayoutSymbol, coefficient: f64)#0.4.0 부터since 0.4.0소스source

심볼의 계수에 coefficient 를 더한다. (결과가 0 에 가까우면 셀에서 지운다)

Adds coefficient to the symbol's coefficient. (removes it from the cells if the result is near 0)

symbolLayoutSymbol
계수를 더할 심볼. (셀에 없으면 계수 0 에서 시작한다)Symbol whose coefficient to add to. (starts from coefficient 0 if not in the cells)
coefficientf64
더할 계수.Coefficient to add.
메서드methodpub fn insert_row(&mut self, other_row: &LayoutRow, coefficient: f64)#0.4.0 부터since 0.4.0소스source

다른 행에 coefficient 를 곱해 이 행에 더한다.

Multiplies another row by coefficient and adds it to this row.

other_row&LayoutRow
더할 행. (상수항과 셀 모두)Row to add. (both the constant and the cells)
coefficientf64
other_row 에 곱할 수.Number to multiply other_row by.
메서드methodpub fn remove_symbol(&mut self, symbol: LayoutSymbol)#0.4.0 부터since 0.4.0소스source

심볼 지우기.

Removes a symbol.

symbolLayoutSymbol
지울 심볼. (셀에 없으면 그대로)Symbol to remove. (unchanged if not in the cells)
메서드methodpub fn reverse_sign(&mut self)#0.4.0 부터since 0.4.0소스source

부호 뒤집기. (상수항과 모든 계수에 -1 을 곱한다)

Flips the sign. (multiplies the constant and every coefficient by -1)

메서드methodpub fn solve_for(&mut self, subject: LayoutSymbol)#0.4.0 부터since 0.4.0소스source

행을 subject 에 대해 푼다.

  • subject 의 셀을 지우고, 남은 셀과 상수항에 -1 / subject 계수를 곱한다. (Kiwi 관례)
  • subject 가 셀에 없으면 부르는 쪽의 실수다.

Solves the row for subject.

  • Removes subject's cell and multiplies the remaining cells and the constant by -1 / subject coefficient. (Kiwi convention)
  • If subject is not in the cells, it is the caller's mistake.
subjectLayoutSymbol
풀 심볼. (셀에 있어야 한다. 없으면 0 으로 나눠 상수항과 계수가 무한대나 NaN 이 된다)Symbol to solve for. (must be in the cells. If not, dividing by 0 makes the constant and coefficients infinite or NaN)
메서드methodpub fn solve_for_pair(&mut self, lhs: LayoutSymbol, rhs: LayoutSymbol)#0.4.0 부터since 0.4.0소스source

lhs = rhs 꼴로 둔 행을 rhs 에 대해 다시 푼다. (lhs 를 -1 로 넣고 rhs 로 푼다)

Solves a row in lhs = rhs form again for rhs. (puts lhs in with -1 and solves for rhs)

lhsLayoutSymbol
왼쪽 심볼. (계수 -1 로 더한다)Left symbol. (added with coefficient -1)
rhsLayoutSymbol
다시 풀 심볼.Symbol to solve for again.
메서드methodpub fn coefficient_for(&self, symbol: LayoutSymbol) -> f64#0.4.0 부터since 0.4.0소스source

심볼의 계수 반환. (없으면 0)

Returns the symbol's coefficient. (0 if absent)

symbolLayoutSymbol
찾을 심볼.Symbol to find.

반환Returnsf64 계수. 셀에 없으면 0.Coefficient. 0 if not in the cells.

메서드methodpub fn substitute(&mut self, symbol: LayoutSymbol, substitution_row: &LayoutRow)#0.4.0 부터since 0.4.0소스source

symbol 을 substitution_row 로 바꿔 넣는다. (symbol 이 없으면 그대로)

Substitutes substitution_row for symbol. (unchanged if symbol is absent)

symbolLayoutSymbol
바꿀 심볼.Symbol to substitute.
substitution_row&LayoutRow
symbol 자리에 넣을 행. (symbol 의 계수를 곱해 더한다)Row to put in place of symbol. (multiplied by symbol's coefficient and added)

함수Functions

함수functionpub fn near_zero(value: f64) -> bool#0.4.0 부터since 0.4.0소스source

부동소수가 0 에 가까운지. (Kiwi 의 nearZero 와 같다)

Whether a floating point number is near 0. (same as Kiwi's nearZero)

valuef64
볼 값.Value to check.

반환Returnsbool 절댓값이 1e-8 보다 작으면 true.true if the absolute value is less than 1e-8.