Ejemplo n.º 1
0
/* Returns 0 on success, and -ve on error.
 */
static int valid_gps(struct gps_location *loc)
{
	/* TODO: Important.
	 * Can't do direct floating comparison as that causes a compiler error.
	 * From Piazza, it was mentioned that we should return an error
	 * only if the GPS coordinates are all zeros, so we just check for
	 * that
	 * https://piazza.com/class#fall2012/comsw4118/1065
	 */
	const double zero_d = 0;
	const float zero_f = 0;
	unsigned long long int err_lat = double_to_long(zero_d);
	unsigned long long int err_lng = double_to_long(zero_d);
	unsigned int err_acc = float_to_int(zero_f);

	unsigned long long int loc_lat;
	unsigned long long int loc_lng;
	unsigned int loc_acc;

	if (loc == NULL)
		return -EINVAL;

	loc_lat = double_to_long(loc->latitude);
	loc_lng = double_to_long(loc->longitude);
	loc_acc = float_to_int(loc->accuracy);

	if (loc_lat == err_lat && loc_lng == err_lng && loc_acc == err_acc)
		return -EINVAL;
	else
		return 0;
}
Ejemplo n.º 2
0
	bool viewport::try_project(point& screen_position, const mat44& view_projection_transform, const vec3& world_position) const {
		vec3 sp3;
		if (try_project(sp3, view_projection_transform, world_position)) {
			screen_position._x = float_to_int(sp3._x);
			screen_position._y = float_to_int(sp3._y);
			return true;
		}
		return false;
	}
// }}}
// Draw text, used by the console, should be private, use conoutf to print to the console {{{
void RText::draw_text(std::string &str, float left, float top, int gl_num)
{
    int x = float_to_int(left);
    int y = float_to_int(top);
	
    std::string::iterator iter = str.begin();
    GFXColor foreground(1, 1, 1, 1);
    GFXColor background(0.05f, 0.05f, 0.2f, 0.5f);
    TextPlane newTextPlane(foreground,background);
    newTextPlane.SetPos(x, y);
    newTextPlane.SetCharSize(.8, .12);
    newTextPlane.Draw(str);
};
Ejemplo n.º 4
0
// Make sure the cell is visible in the scroll area.  If it is, nothing
//  happens.  If it's not, we move it into the visible section.
// If NULL, this routine does nothing.
void Picker::scrollToCell(const PickerCell* cell, bool middle) {
    if(!cell || !m_scroller) return;

    // If we need to change the displayed cells, do that first.
    if(m_needRecalcDisplay) {
        recalcDisplay();
    }

    for(int i=0; i<m_displayCells.size(); i++) {
        if(cell == m_displayCells[i].cell) {
            const int visibleCells = float_to_int(m_rect.size.height / totalCellHeight());
			if(middle) {
				// Regardless of where cell is, try to put it in the middle of
				//  the visible area.
				m_scroller->setScrollPosition(i - visibleCells/2);
			} else {
				// Just make sure we can see it.
				if(i < m_scrollPosition) {
					// Cell is too "high".  Move it to the top line.
					m_scroller->setScrollPosition(i - SCROLL_EDGE_EXTRA);
				} else if(i >= m_scrollPosition+visibleCells) {
					// Cell is too "low".  Move it to the bottom line.
					m_scroller->setScrollPosition(i-visibleCells+1+SCROLL_EDGE_EXTRA);
				}
			}

			// Found the cell.  Done with loop.
			break;
		}
    }
}
Ejemplo n.º 5
0
int __fixsfsi(float a)
{
	float_t fa;
	
	fa.val = a;
	return float_to_int(fa.data);
}
Ejemplo n.º 6
0
// Range represented by the slider.
void Slider::setMaxMin(int max, int min) {
    m_maxValue = max;
    m_minValue = min;

    // Set default page size
    const int pageSize = float_to_int((max - min) / 10.0 + 0.5);
    setPageSize(pageSize);
}
Ejemplo n.º 7
0
int
main()
{
	float_to_int();

	f();

	g();
}
Ejemplo n.º 8
0
long double			ft_sqrt(long double nb)
{
    long int	*sep_nb;
    long double	ret;

    sep_nb = float_to_int(nb, 12);
    ret = calc_sqrt(sep_nb);
    free(sep_nb);
    return (ret);
}
Ejemplo n.º 9
0
// Find the cell for a mouse point.
PickerCell* Picker::cellForMouse(const Point& point) {
    if(m_rect.inside(point)) {
        const int index = float_to_int((m_rect.top() - point.y) / totalCellHeight() + m_scrollPosition);
        if(index < m_displayCells.size()) {
            // It's within the cells we are displaying.
            return m_displayCells[index].cell;
        }
    }

    // Didn't find anything.
    return NULL;
}
Ejemplo n.º 10
0
	int text_entry::get_caret_offset_from_left() const {
		ASSERT(_caret_pos <= uint_to_int(_text.length()));

		int caret_pos_in_visible_text = _caret_pos - _visible_pos;
		if (caret_pos_in_visible_text <= 0) {
			return 0;
		}

		std::wstring visible_text = std::wstring(_text, _visible_pos, caret_pos_in_visible_text);
		raw_text_to_visible_text(visible_text);
		return float_to_int(std::ceil(get_text_width(visible_text)));
	}
Ejemplo n.º 11
0
bool Slider::processMouseDrag(const InputEvent& event) {
    // The interface for mouse dragging is a little weird.  There is no button information.  All
    //  we know is that some button is down.  This is enough, since we don't get into a specific
    //  mouse state in this control unless we know which mouse button was pressed...
    if(m_mouseState == MOUSE_THUMB_DRAG) {
        if (m_thumbLength == NO_THUMB_LENGTH) return true;

        const Rect cancelRect = m_rect.copyAndInset(THUMB_DRAG_CANCEL_MARGINS);
        if(!cancelRect.inside(event.loc)) {
            // We are outside the cancel rect.  Go back to original position.
            setPosition(m_buttonDownPosition);
            return true;
        } else {
            // We are dragging the thumb -- get a new scroll position.
            if(m_vertical) {
                    // Calculate the factor to convert a change in mouse coords to a change in slider position.
                    // This is derived from the ratio of the non-thumb length in the slider to the
                    //  total range.
                    const float totalMouseLength = (1.0-m_thumbLength) * m_rect.size.height;
                    const int totalRange = m_maxValue - m_minValue;
                    const int positionChange = float_to_int((m_buttonDownMouse-event.loc.y)*totalRange/totalMouseLength + 0.5);
                    setPosition(m_buttonDownPosition + positionChange);
                    return true;
            } else {
                    const float totalMouseLength = (1.0-m_thumbLength) * m_rect.size.width;
                    const int totalRange = m_maxValue - m_minValue;
                    const int positionChange = float_to_int((event.loc.x-m_buttonDownMouse)*totalRange/totalMouseLength + 0.5);
                    setPosition(m_buttonDownPosition + positionChange);
                    return true;
            }
        }
        return Control::processMouseDrag(event);
    }

    return false;
}
Ejemplo n.º 12
0
// Reload the list of cells that are being displayed.
// This should be called when a change is made in the lists of cells, or
//  when we scroll, which again changes the cells we display.
// It does not need to be called for text or color changes, only when
//  cells are added or removed, etc.
void Picker::recalcDisplay(void) {
    // Clear out the old display list.
    m_displayCells.clear();

    // Recursively refill the display list.
    addListToDisplay(m_cells, 0);

    if(m_scroller) {
        // Update the scroller's view of the number of lines, and try to preserve the scroll position.
        int oldScrollPosition = m_scrollPosition;
        const int visibleCells = float_to_int(m_rect.size.height / totalCellHeight());
        m_scroller->setRangeValues(m_displayCells.size()-1, visibleCells);
        m_scroller->setScrollPosition(oldScrollPosition);
    }

    // Mark that we don't need to recalc anymore.
    m_needRecalcDisplay = false;
}
Ejemplo n.º 13
0
static GF_Err AC3_ProcessData(GF_MediaDecoder *ifcg,
		char *inBuffer, u32 inBufferLength,
		u16 ES_ID,
		char *outBuffer, u32 *outBufferLength,
		u8 PaddingBits, u32 mmlevel)
{
    short *out_samples;
	int i, len, bit_rate;
	sample_t level;
	A52CTX();

	/*check not using scalabilty*/
	if (ctx->ES_ID != ES_ID) return GF_BAD_PARAM;

	/*if late or seeking don't decode*/
	switch (mmlevel) {
	case GF_CODEC_LEVEL_SEEK:
	case GF_CODEC_LEVEL_DROP:
		*outBufferLength = 0;
		return GF_OK;
	default:
		break;
	}

	if (ctx->out_size > *outBufferLength) {
		*outBufferLength = ctx->out_size;
		return GF_BUFFER_TOO_SMALL;
	}

	GF_LOG(GF_LOG_DEBUG, GF_LOG_CODEC, ("[A52] Decoding AU\n"));

	len = a52_syncinfo(inBuffer, &ctx->flags, &ctx->sample_rate, &bit_rate);
	if (!len) return GF_NON_COMPLIANT_BITSTREAM;

	/*init decoder*/
	if (!ctx->out_size) {
		ctx->num_channels = ac3_channels[ctx->flags & 7];
		if (ctx->flags & A52_LFE) ctx->num_channels++;
		ctx->flags |= A52_ADJUST_LEVEL;

		ctx->out_size = ctx->num_channels * sizeof(short) * 1536;
		*outBufferLength = ctx->out_size;
		return GF_BUFFER_TOO_SMALL;
	}

	level = 1;
	if ( a52_frame(ctx->codec, inBuffer, &ctx->flags, &level, 384)) {
		GF_LOG(GF_LOG_DEBUG, GF_LOG_CODEC, ("[A52] Error decoding AU\n" ));
		*outBufferLength = 0;
		return GF_NON_COMPLIANT_BITSTREAM;
	}

	out_samples = (short*)outBuffer;
	for (i=0; i<6; i++) {
		if (a52_block(ctx->codec))
			return GF_NON_COMPLIANT_BITSTREAM;

		float_to_int(ctx->samples, out_samples + i * 256 * ctx->num_channels, ctx->num_channels);
	}

	*outBufferLength = 6 * ctx->num_channels * 256 * sizeof(short);

	return GF_OK;
}
Ejemplo n.º 14
0
void motion_next(uint16_t delta)
// Increment the buffer counter by the indicated delta and return the position
// and velocity from the buffered curves.  If the delta is zero the current
// position and velocity is returned.
{
    float fposition;
    float fvelocity;

    // Determine if curve motion is disabled in the registers.
    if (!(registers_read_byte(REG_FLAGS_LO) & (1<<FLAGS_LO_MOTION_ENABLED))) return;

    // Are we processing an empty curve?
    if (motion_tail == motion_head)
    {
        // Yes. Keep the counter and duration at zero.
        motion_counter = 0;
        motion_duration = 0;
    }
    else
    {
        // Increment the counter.
        motion_counter += delta;

        // Have we exceeded the duration of the currently buffered curve?
        while (motion_counter > curve_get_duration())
        {
            // Reduce the buffer counter by the currently buffered curve duration.
            motion_counter -= curve_get_duration();

            // Reduce the buffer duration by the currently buffered curve duration.
            motion_duration -= curve_get_duration();

            // Increment the tail to process the next buffered curve.
            motion_tail = (motion_tail + 1) & MOTION_BUFFER_MASK;

            // Has the tail caught up with the head?
            if (motion_tail == motion_head)
            {
                // Initialize an empty hermite curve with a zero duration.  This is a degenerate case for
                // the hermite cuve that will always return the position of the curve without velocity.
                curve_init(0, 0, keys[motion_head].position, keys[motion_head].position, 0.0, 0.0);

                // Reset the buffer counter and duration to zero.
                motion_counter = 0;
                motion_duration = 0;
            }
            else
            {
                uint8_t curr_point;
                uint8_t next_point;

                // Get the current point and next point for the curve.
                curr_point = motion_tail;
                next_point = (curr_point + 1) & MOTION_BUFFER_MASK;

                // Initialize the hermite curve from the current and next point.
                curve_init(0, keys[next_point].delta,
                           keys[curr_point].position, keys[next_point].position,
                           keys[curr_point].out_velocity, keys[next_point].in_velocity);
            }

            // Update the space available in the buffer.
            registers_write_byte(REG_CURVE_BUFFER, motion_buffer_left());
        }
    }

    // Get the position and velocity from the hermite curve.
    curve_solve(motion_counter, &fposition, &fvelocity);

    // The velocity is in position units a millisecond, but we really need the
    // velocity to be measured in position units every 10 milliseconds to match
    // the sample period of the ADC.
    fvelocity *= 10.0;

    // Update the seek position register.
    registers_write_word(REG_SEEK_POSITION_HI, REG_SEEK_POSITION_LO, float_to_int(fposition));

    // Update the seek velocity register.
    registers_write_word(REG_SEEK_VELOCITY_HI, REG_SEEK_VELOCITY_LO, float_to_int(fvelocity));
}
Ejemplo n.º 15
0
static int a52_decode_frame(AVCodecContext *avctx,
                            void *data, int *data_size,
                            uint8_t *buf, int buf_size)
{
    AC3DecodeState *s = avctx->priv_data;
    uint8_t *buf_ptr;
    int flags, i, len;
    int sample_rate, bit_rate;
    short *out_samples = data;
    float level;
    static const int ac3_channels[8] = {
	2, 1, 2, 3, 3, 4, 4, 5
    };

    buf_ptr = buf;
    while (buf_size > 0) {
        len = s->inbuf_ptr - s->inbuf;
        if (s->frame_size == 0) {
            /* no header seen : find one. We need at least 7 bytes to parse it */
            len = HEADER_SIZE - len;
            if (len > buf_size)
                len = buf_size;
            memcpy(s->inbuf_ptr, buf_ptr, len);
            buf_ptr += len;
            s->inbuf_ptr += len;
            buf_size -= len;
            if ((s->inbuf_ptr - s->inbuf) == HEADER_SIZE) {
                len = s->a52_syncinfo(s->inbuf, &s->flags, &sample_rate, &bit_rate);
                if (len == 0) {
                    /* no sync found : move by one byte (inefficient, but simple!) */
                    memcpy(s->inbuf, s->inbuf + 1, HEADER_SIZE - 1);
                    s->inbuf_ptr--;
                } else {
		    s->frame_size = len;
                    /* update codec info */
                    avctx->sample_rate = sample_rate;
                    s->channels = ac3_channels[s->flags & 7];
                    if (s->flags & A52_LFE)
			s->channels++;
		    if (avctx->channels == 0)
			/* No specific number of channel requested */
			avctx->channels = s->channels;
		    else if (s->channels < avctx->channels) {
			av_log(avctx, AV_LOG_ERROR, "ac3dec: AC3 Source channels are less than specified: output to %d channels.. (frmsize: %d)\n", s->channels, len);
			avctx->channels = s->channels;
		    }
		    avctx->bit_rate = bit_rate;
                }
            }
        } else if (len < s->frame_size) {
            len = s->frame_size - len;
            if (len > buf_size)
                len = buf_size;

            memcpy(s->inbuf_ptr, buf_ptr, len);
            buf_ptr += len;
            s->inbuf_ptr += len;
            buf_size -= len;
        } else {
            flags = s->flags;
            if (avctx->channels == 1)
                flags = A52_MONO;
            else if (avctx->channels == 2)
                flags = A52_STEREO;
            else
                flags |= A52_ADJUST_LEVEL;
            level = 1;
            if (s->a52_frame(s->state, s->inbuf, &flags, &level, 384)) {
            fail:
                s->inbuf_ptr = s->inbuf;
                s->frame_size = 0;
                continue;
            }
            for (i = 0; i < 6; i++) {
                if (s->a52_block(s->state))
                    goto fail;
                float_to_int(s->samples, out_samples + i * 256 * avctx->channels, avctx->channels);
            }
            s->inbuf_ptr = s->inbuf;
            s->frame_size = 0;
            *data_size = 6 * avctx->channels * 256 * sizeof(int16_t);
            break;
        }
    }
    return buf_ptr - buf;
}
Ejemplo n.º 16
0
static int a52_decode_frame(AVCodecContext *avctx,
                            void *data, int *data_size,
                            uint8_t *buf, int buf_size)
{
    AC3DecodeState *s = avctx->priv_data;
    int flags, i, len;
    int sample_rate, bit_rate;
    short *out_samples = data;
    float level;
    static const int ac3_channels[8] = {
        2, 1, 2, 3, 3, 4, 4, 5
    };

    *data_size= 0;

    if (buf_size < HEADER_SIZE) {
        av_log(avctx, AV_LOG_ERROR, "Error decoding frame, not enough bytes for header\n");
        return -1;
    }
    len = s->a52_syncinfo(buf, &s->flags, &sample_rate, &bit_rate);
    if (len == 0) {
        av_log(avctx, AV_LOG_ERROR, "Error decoding frame, no sync byte at begin\n");
        return -1;
    }
    if (buf_size < len) {
        av_log(avctx, AV_LOG_ERROR, "Error decoding frame, not enough bytes\n");
        return -1;
    }
    /* update codec info */
    avctx->sample_rate = sample_rate;
    s->channels = ac3_channels[s->flags & 7];
    if (s->flags & A52_LFE)
            s->channels++;
    if (avctx->request_channels > 0 &&
        avctx->request_channels <= 2 &&
        avctx->request_channels < s->channels) {
        avctx->channels = avctx->request_channels;
    } else {
        avctx->channels = s->channels;
    }
    avctx->bit_rate = bit_rate;
    flags = s->flags;
    if (avctx->channels == 1)
        flags = A52_MONO;
    else if (avctx->channels == 2)
        flags = A52_STEREO;
    else
        flags |= A52_ADJUST_LEVEL;
    level = 1;
    if (s->a52_frame(s->state, buf, &flags, &level, 384)) {
    fail:
        av_log(avctx, AV_LOG_ERROR, "Error decoding frame\n");
        return -1;
    }
    for (i = 0; i < 6; i++) {
        if (s->a52_block(s->state))
            goto fail;
        float_to_int(s->samples, out_samples + i * 256 * avctx->channels, avctx->channels);
    }
    *data_size = 6 * avctx->channels * 256 * sizeof(int16_t);
    return len;
}