use Fixed for bits_size values (test)
This commit is contained in:
parent
cd3e25696d
commit
cb6b42591b
|
@ -118,7 +118,7 @@ fn crush_stone_object(mut ob Object) {
|
|||
|
||||
// XXX crush entire object
|
||||
|
||||
num_bits := ob.bits_volume()
|
||||
num_bits := int(ob.bits_volume().value()) // XXX
|
||||
|
||||
// Create separate objects
|
||||
for i in 0..num_bits {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
module bits
|
||||
|
||||
import bits.fixed
|
||||
|
||||
/*
|
||||
// Material Elem Record
|
||||
struct MaterialElem {
|
||||
|
@ -26,7 +28,8 @@ struct MaterialPart {
|
|||
pub mut:
|
||||
name string
|
||||
elem &Elem
|
||||
bits_size int
|
||||
//bits_size int
|
||||
bits_size fixed.Fixed
|
||||
}
|
||||
|
||||
// MaterialInfo information about materials in object
|
||||
|
@ -55,7 +58,7 @@ pub fn (mi &MaterialInfo) has_elem_name(elem_name string) bool {
|
|||
}
|
||||
|
||||
// Add elem record
|
||||
pub fn (mut mi MaterialInfo) add_elem(bits_size int, elem &Elem) {
|
||||
pub fn (mut mi MaterialInfo) add_elem(bits_size fixed.Fixed, elem &Elem) {
|
||||
println("MaterialInfo add_elem: bits_size: $bits_size, elem.name: $elem.name")
|
||||
|
||||
pt := &MaterialPart{
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
module bits
|
||||
|
||||
import bits.fixed
|
||||
|
||||
// Object bit
|
||||
// size: 10x10x10 (cm) (?)
|
||||
//
|
||||
|
@ -58,13 +60,13 @@ pub fn new_object() &Object {
|
|||
}
|
||||
|
||||
// Calc total volume in bits
|
||||
pub fn (o &Object) bits_volume() int {
|
||||
pub fn (o &Object) bits_volume() fixed.Fixed {
|
||||
//return o.dim_x * o.dim_y * o.dim_z
|
||||
//return o.bits_size
|
||||
|
||||
mut ret := 0
|
||||
mut ret := fixed.new_f(0.0)
|
||||
for me in o.mat_info.elems_list() {
|
||||
ret += me.bits_size
|
||||
ret = ret.add(me.bits_size)
|
||||
}
|
||||
|
||||
return ret
|
||||
|
@ -78,13 +80,15 @@ pub fn (o &Object) volume() f32 {
|
|||
// Calc total mass in kg
|
||||
pub fn (o &Object) mass() f32 {
|
||||
|
||||
mut total_mass := 0
|
||||
mut total_mass := f32(0.0)
|
||||
|
||||
for _, me in o.mat_info.elems {
|
||||
|
||||
mat_density := me.elem.density
|
||||
mat_volume := me.bits_size
|
||||
mat_volume := f32(me.bits_size.value())
|
||||
|
||||
// XXX is this correct?
|
||||
// shouldn't this be in m3 instead?
|
||||
mass := mat_density * mat_volume
|
||||
|
||||
total_mass += mass
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
module bits
|
||||
|
||||
import bits.fixed
|
||||
|
||||
// Out elem record/info
|
||||
// One to [Many]
|
||||
struct ProcessorOutElemRec {
|
||||
|
@ -73,7 +75,7 @@ fn (p &Processor) process(mut o Object) []&MaterialPart {
|
|||
println("process for ${pt.elem.name}")
|
||||
|
||||
// Save initial size
|
||||
orig_pt_bits_size := pt.bits_size
|
||||
orig_pt_bits_size := pt.bits_size.value()
|
||||
|
||||
for out_elem_rec in p.out_elems {
|
||||
|
||||
|
@ -88,7 +90,7 @@ fn (p &Processor) process(mut o Object) []&MaterialPart {
|
|||
}
|
||||
|
||||
//new_bits_size := int(pt.bits_size * out_elem_rec.output_factor)
|
||||
new_bits_size := int(orig_pt_bits_size * out_elem_rec.output_factor)
|
||||
new_bits_size := fixed.new_f(orig_pt_bits_size * out_elem_rec.output_factor)
|
||||
|
||||
println("new_elem: ${isnil(new_elem)}")
|
||||
println("new_elem: $new_elem")
|
||||
|
|
|
@ -1,28 +1,29 @@
|
|||
module bits
|
||||
|
||||
//import math
|
||||
import bits.fixed
|
||||
|
||||
[inline]
|
||||
fn bits_to_m(n_bits int) f32 {
|
||||
fn bits_to_m(n_bits fixed.Fixed) f32 {
|
||||
//return f32(n_bits) * c_bit_size / 100.0
|
||||
return f32(n_bits) / c_bit_size
|
||||
return f32(n_bits.value()) / c_bit_size
|
||||
}
|
||||
|
||||
[inline]
|
||||
fn m_to_bits(m f32) int {
|
||||
return int(m * 100.0 / c_bit_size)
|
||||
fn m_to_bits(m f32) fixed.Fixed {
|
||||
return fixed.new_f(m * 100.0 / c_bit_size)
|
||||
}
|
||||
|
||||
[inline]
|
||||
fn bits_to_m3(n_bits int) f32 {
|
||||
fn bits_to_m3(n_bits fixed.Fixed) f32 {
|
||||
//return f32(n_bits) / (math.powf(c_bit_size, 3))
|
||||
return f32(n_bits) / c_bits_in_m3
|
||||
return f32(n_bits.value()) / c_bits_in_m3
|
||||
}
|
||||
|
||||
[inline]
|
||||
fn m3_to_bits(m3 f32) int {
|
||||
fn m3_to_bits(m3 f32) fixed.Fixed {
|
||||
//return int(m3 * 1000 / (math.powf(c_bit_size, 3)))
|
||||
return int(m3 * c_bits_in_m3)
|
||||
return fixed.new_f(m3 * c_bits_in_m3)
|
||||
}
|
||||
|
||||
[inline]
|
||||
|
|
|
@ -11,7 +11,7 @@ fn main() {
|
|||
println("main()")
|
||||
|
||||
bits.bits_main()
|
||||
//pp(2)
|
||||
pp(2)
|
||||
|
||||
// XXX init context
|
||||
//mut ctx := new_context()
|
||||
|
|
Loading…
Reference in New Issue