Beispiel #1
0
void			pos_line(t_form *form, t_bunny_pixelarray *pix)
{
  t_obj			*tmp;
  t_bunny_position	pos[2];
  t_color		col[2];

  tmp = form->objs;
  while (tmp != NULL)
    {
      set_pos(pos, &tmp->a, &tmp->b, col);
      add_pos(pos, form);
      tekline(pix, pos, col);
      tmp = tmp->next;
    }
}
Beispiel #2
0
Datum
tsvector_concat(PG_FUNCTION_ARGS)
{
	TSVector	in1 = PG_GETARG_TSVECTOR(0);
	TSVector	in2 = PG_GETARG_TSVECTOR(1);
	TSVector	out;
	WordEntry  *ptr;
	WordEntry  *ptr1,
			   *ptr2;
	WordEntryPos *p;
	int			maxpos = 0,
				i,
				j,
				i1,
				i2,
				dataoff,
				output_bytes,
				output_size;
	char	   *data,
			   *data1,
			   *data2;

	/* Get max position in in1; we'll need this to offset in2's positions */
	ptr = ARRPTR(in1);
	i = in1->size;
	while (i--)
	{
		if ((j = POSDATALEN(in1, ptr)) != 0)
		{
			p = POSDATAPTR(in1, ptr);
			while (j--)
			{
				if (WEP_GETPOS(*p) > maxpos)
					maxpos = WEP_GETPOS(*p);
				p++;
			}
		}
		ptr++;
	}

	ptr1 = ARRPTR(in1);
	ptr2 = ARRPTR(in2);
	data1 = STRPTR(in1);
	data2 = STRPTR(in2);
	i1 = in1->size;
	i2 = in2->size;

	/*
	 * Conservative estimate of space needed.  We might need all the data in
	 * both inputs, and conceivably add a pad byte before position data for
	 * each item where there was none before.
	 */
	output_bytes = VARSIZE(in1) + VARSIZE(in2) + i1 + i2;

	out = (TSVector) palloc0(output_bytes);
	SET_VARSIZE(out, output_bytes);

	/*
	 * We must make out->size valid so that STRPTR(out) is sensible.  We'll
	 * collapse out any unused space at the end.
	 */
	out->size = in1->size + in2->size;

	ptr = ARRPTR(out);
	data = STRPTR(out);
	dataoff = 0;
	while (i1 && i2)
	{
		int			cmp = compareEntry(data1, ptr1, data2, ptr2);

		if (cmp < 0)
		{						/* in1 first */
			ptr->haspos = ptr1->haspos;
			ptr->len = ptr1->len;
			memcpy(data + dataoff, data1 + ptr1->pos, ptr1->len);
			ptr->pos = dataoff;
			dataoff += ptr1->len;
			if (ptr->haspos)
			{
				dataoff = SHORTALIGN(dataoff);
				memcpy(data + dataoff, _POSVECPTR(in1, ptr1), POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16));
				dataoff += POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16);
			}

			ptr++;
			ptr1++;
			i1--;
		}
		else if (cmp > 0)
		{						/* in2 first */
			ptr->haspos = ptr2->haspos;
			ptr->len = ptr2->len;
			memcpy(data + dataoff, data2 + ptr2->pos, ptr2->len);
			ptr->pos = dataoff;
			dataoff += ptr2->len;
			if (ptr->haspos)
			{
				int			addlen = add_pos(in2, ptr2, out, ptr, maxpos);

				if (addlen == 0)
					ptr->haspos = 0;
				else
				{
					dataoff = SHORTALIGN(dataoff);
					dataoff += addlen * sizeof(WordEntryPos) + sizeof(uint16);
				}
			}

			ptr++;
			ptr2++;
			i2--;
		}
		else
		{
			ptr->haspos = ptr1->haspos | ptr2->haspos;
			ptr->len = ptr1->len;
			memcpy(data + dataoff, data1 + ptr1->pos, ptr1->len);
			ptr->pos = dataoff;
			dataoff += ptr1->len;
			if (ptr->haspos)
			{
				if (ptr1->haspos)
				{
					dataoff = SHORTALIGN(dataoff);
					memcpy(data + dataoff, _POSVECPTR(in1, ptr1), POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16));
					dataoff += POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16);
					if (ptr2->haspos)
						dataoff += add_pos(in2, ptr2, out, ptr, maxpos) * sizeof(WordEntryPos);
				}
				else	/* must have ptr2->haspos */
				{
					int			addlen = add_pos(in2, ptr2, out, ptr, maxpos);

					if (addlen == 0)
						ptr->haspos = 0;
					else
					{
						dataoff = SHORTALIGN(dataoff);
						dataoff += addlen * sizeof(WordEntryPos) + sizeof(uint16);
					}
				}
			}

			ptr++;
			ptr1++;
			ptr2++;
			i1--;
			i2--;
		}
	}

	while (i1)
	{
		ptr->haspos = ptr1->haspos;
		ptr->len = ptr1->len;
		memcpy(data + dataoff, data1 + ptr1->pos, ptr1->len);
		ptr->pos = dataoff;
		dataoff += ptr1->len;
		if (ptr->haspos)
		{
			dataoff = SHORTALIGN(dataoff);
			memcpy(data + dataoff, _POSVECPTR(in1, ptr1), POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16));
			dataoff += POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16);
		}

		ptr++;
		ptr1++;
		i1--;
	}

	while (i2)
	{
		ptr->haspos = ptr2->haspos;
		ptr->len = ptr2->len;
		memcpy(data + dataoff, data2 + ptr2->pos, ptr2->len);
		ptr->pos = dataoff;
		dataoff += ptr2->len;
		if (ptr->haspos)
		{
			int			addlen = add_pos(in2, ptr2, out, ptr, maxpos);

			if (addlen == 0)
				ptr->haspos = 0;
			else
			{
				dataoff = SHORTALIGN(dataoff);
				dataoff += addlen * sizeof(WordEntryPos) + sizeof(uint16);
			}
		}

		ptr++;
		ptr2++;
		i2--;
	}

	/*
	 * Instead of checking each offset individually, we check for overflow of
	 * pos fields once at the end.
	 */
	if (dataoff > MAXSTRPOS)
		ereport(ERROR,
				(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
				 errmsg("string is too long for tsvector (%d bytes, max %d bytes)", dataoff, MAXSTRPOS)));

	/*
	 * Adjust sizes (asserting that we didn't overrun the original estimates)
	 * and collapse out any unused array entries.
	 */
	output_size = ptr - ARRPTR(out);
	Assert(output_size <= out->size);
	out->size = output_size;
	if (data != STRPTR(out))
		memmove(STRPTR(out), data, dataoff);
	output_bytes = CALCDATASIZE(out->size, dataoff);
	Assert(output_bytes <= VARSIZE(out));
	SET_VARSIZE(out, output_bytes);

	PG_FREE_IF_COPY(in1, 0);
	PG_FREE_IF_COPY(in2, 1);
	PG_RETURN_POINTER(out);
}
Beispiel #3
0
Datum
tsvector_concat(PG_FUNCTION_ARGS)
{
	TSVector	in1 = PG_GETARG_TSVECTOR(0);
	TSVector	in2 = PG_GETARG_TSVECTOR(1);
	TSVector	out;
	WordEntry  *ptr;
	WordEntry  *ptr1,
			   *ptr2;
	WordEntryPos *p;
	int			maxpos = 0,
				i,
				j,
				i1,
				i2,
				dataoff;
	char	   *data,
			   *data1,
			   *data2;

	ptr = ARRPTR(in1);
	i = in1->size;
	while (i--)
	{
		if ((j = POSDATALEN(in1, ptr)) != 0)
		{
			p = POSDATAPTR(in1, ptr);
			while (j--)
			{
				if (WEP_GETPOS(*p) > maxpos)
					maxpos = WEP_GETPOS(*p);
				p++;
			}
		}
		ptr++;
	}

	ptr1 = ARRPTR(in1);
	ptr2 = ARRPTR(in2);
	data1 = STRPTR(in1);
	data2 = STRPTR(in2);
	i1 = in1->size;
	i2 = in2->size;
	/* conservative estimate of space needed */
	out = (TSVector) palloc0(VARSIZE(in1) + VARSIZE(in2));
	SET_VARSIZE(out, VARSIZE(in1) + VARSIZE(in2));
	out->size = in1->size + in2->size;
	ptr = ARRPTR(out);
	data = STRPTR(out);
	dataoff = 0;
	while (i1 && i2)
	{
		int			cmp = compareEntry(data1, ptr1, data2, ptr2);

		if (cmp < 0)
		{						/* in1 first */
			ptr->haspos = ptr1->haspos;
			ptr->len = ptr1->len;
			memcpy(data + dataoff, data1 + ptr1->pos, ptr1->len);
			ptr->pos = dataoff;
			dataoff += ptr1->len;
			if (ptr->haspos)
			{
				dataoff = SHORTALIGN(dataoff);
				memcpy(data + dataoff, _POSVECPTR(in1, ptr1), POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16));
				dataoff += POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16);
			}

			ptr++;
			ptr1++;
			i1--;
		}
		else if (cmp > 0)
		{						/* in2 first */
			ptr->haspos = ptr2->haspos;
			ptr->len = ptr2->len;
			memcpy(data + dataoff, data2 + ptr2->pos, ptr2->len);
			ptr->pos = dataoff;
			dataoff += ptr2->len;
			if (ptr->haspos)
			{
				int			addlen = add_pos(in2, ptr2, out, ptr, maxpos);

				if (addlen == 0)
					ptr->haspos = 0;
				else
				{
					dataoff = SHORTALIGN(dataoff);
					dataoff += addlen * sizeof(WordEntryPos) + sizeof(uint16);
				}
			}

			ptr++;
			ptr2++;
			i2--;
		}
		else
		{
			ptr->haspos = ptr1->haspos | ptr2->haspos;
			ptr->len = ptr1->len;
			memcpy(data + dataoff, data1 + ptr1->pos, ptr1->len);
			ptr->pos = dataoff;
			dataoff += ptr1->len;
			if (ptr->haspos)
			{
				if (ptr1->haspos)
				{
					dataoff = SHORTALIGN(dataoff);
					memcpy(data + dataoff, _POSVECPTR(in1, ptr1), POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16));
					dataoff += POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16);
					if (ptr2->haspos)
						dataoff += add_pos(in2, ptr2, out, ptr, maxpos) * sizeof(WordEntryPos);
				}
				else	/* must have ptr2->haspos */
				{
					int			addlen = add_pos(in2, ptr2, out, ptr, maxpos);

					if (addlen == 0)
						ptr->haspos = 0;
					else
					{
						dataoff = SHORTALIGN(dataoff);
						dataoff += addlen * sizeof(WordEntryPos) + sizeof(uint16);
					}
				}
			}

			ptr++;
			ptr1++;
			ptr2++;
			i1--;
			i2--;
		}
	}

	while (i1)
	{
		ptr->haspos = ptr1->haspos;
		ptr->len = ptr1->len;
		memcpy(data + dataoff, data1 + ptr1->pos, ptr1->len);
		ptr->pos = dataoff;
		dataoff += ptr1->len;
		if (ptr->haspos)
		{
			dataoff = SHORTALIGN(dataoff);
			memcpy(data + dataoff, _POSVECPTR(in1, ptr1), POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16));
			dataoff += POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16);
		}

		ptr++;
		ptr1++;
		i1--;
	}

	while (i2)
	{
		ptr->haspos = ptr2->haspos;
		ptr->len = ptr2->len;
		memcpy(data + dataoff, data2 + ptr2->pos, ptr2->len);
		ptr->pos = dataoff;
		dataoff += ptr2->len;
		if (ptr->haspos)
		{
			int			addlen = add_pos(in2, ptr2, out, ptr, maxpos);

			if (addlen == 0)
				ptr->haspos = 0;
			else
			{
				dataoff = SHORTALIGN(dataoff);
				dataoff += addlen * sizeof(WordEntryPos) + sizeof(uint16);
			}
		}

		ptr++;
		ptr2++;
		i2--;
	}

	/*
	 * Instead of checking each offset individually, we check for overflow of
	 * pos fields once at the end.
	 */
	if (dataoff > MAXSTRPOS)
		ereport(ERROR,
				(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
				 errmsg("string is too long for tsvector (%d bytes, max %d bytes)", dataoff, MAXSTRPOS)));

	out->size = ptr - ARRPTR(out);
	SET_VARSIZE(out, CALCDATASIZE(out->size, dataoff));
	if (data != STRPTR(out))
		memmove(STRPTR(out), data, dataoff);

	PG_FREE_IF_COPY(in1, 0);
	PG_FREE_IF_COPY(in2, 1);
	PG_RETURN_POINTER(out);
}
void ShaderEditor::onGUIRightColumn()
{
	ImGui::BeginChild("right_col");

	if(ImGui::IsWindowHovered() && !ImGui::IsAnyItemActive() && ImGui::IsMouseDragging(2, 0.0f))
	{
		m_canvas_pos = m_canvas_pos + ImGui::GetIO().MouseDelta;
	}

	int current_shader = (int)m_current_shader_type;
	if(ImGui::Combo("Shader", &current_shader, "Vertex\0Fragment\0"))
	{
		m_current_shader_type = (ShaderType)current_shader;
	}

	auto cursor_screen_pos = ImGui::GetCursorScreenPos();

	auto& nodes = m_current_shader_type == ShaderType::FRAGMENT ? m_fragment_nodes : m_vertex_nodes;
	for(auto* node : nodes)
	{
		auto node_screen_pos = cursor_screen_pos + node->m_pos + m_canvas_pos;

		ImGui::BeginNode(node->m_id, node_screen_pos);
		node->onNodeGUI();
		ImGui::EndNode(node_screen_pos);
		if(ImGui::IsItemHovered() && ImGui::IsMouseDown(1))
		{
			m_current_node_id = node->m_id;
		}

		for(int i = 0; i < node->m_outputs.size(); ++i)
		{
			Node* output = node->m_outputs[i];
			if(!output) continue;

			auto output_screen_pos = cursor_screen_pos + output->m_pos + m_canvas_pos;

			auto output_pos = ImGui::GetNodeOutputPos(node->m_id, i);
			auto input_pos = ImGui::GetNodeInputPos(output->m_id, output->m_inputs.indexOf(node));
			ImGui::NodeLink(output_pos, input_pos);
		}

		for(int i = 0; i < node->m_outputs.size(); ++i)
		{
			auto pin_pos = ImGui::GetNodeOutputPos(node->m_id, i);
			if(ImGui::NodePin(i, pin_pos))
			{
				if(ImGui::IsMouseReleased(0) && m_new_link_info.is_active)
				{
					createConnection(node, i, false);
				}
				if(ImGui::IsMouseClicked(0)) nodePinMouseDown(node, i, false);
			}
		}

		for(int i = 0; i < node->m_inputs.size(); ++i)
		{
			auto pin_pos = ImGui::GetNodeInputPos(node->m_id, i);
			if(ImGui::NodePin(i + node->m_outputs.size(), pin_pos))
			{
				if(ImGui::IsMouseReleased(0) && m_new_link_info.is_active)
				{
					createConnection(node, i, true);
				}
				if(ImGui::IsMouseClicked(0)) nodePinMouseDown(node, i, true);
			}
		}

		ImVec2 new_pos = node_screen_pos - cursor_screen_pos - m_canvas_pos;
		if(new_pos.x != node->m_pos.x || new_pos.y != node->m_pos.y)
		{
			execute(LUMIX_NEW(m_allocator, MoveNodeCommand)(node->m_id, new_pos, *this));
		}
	}

	if(m_new_link_info.is_active && ImGui::IsMouseDown(0))
	{
		if(m_new_link_info.is_from_input)
		{
			auto pos = ImGui::GetNodeInputPos(
				m_new_link_info.from->m_id, m_new_link_info.from_pin_index);
			ImGui::NodeLink(ImGui::GetMousePos(), pos);
		}
		else
		{
			auto pos = ImGui::GetNodeOutputPos(
				m_new_link_info.from->m_id, m_new_link_info.from_pin_index);
			ImGui::NodeLink(pos, ImGui::GetMousePos());
		}
	}
	else
	{
		m_new_link_info.is_active = false;
	}

	if(ImGui::IsMouseClicked(1))
	{
		ImGui::OpenPopup("context_menu");
	}

	if(ImGui::BeginPopup("context_menu"))
	{
		ImVec2 add_pos(ImGui::GetMousePos() - cursor_screen_pos - m_canvas_pos);
		if(m_current_node_id >= 0)
		{
			if(ImGui::MenuItem("Remove"))
			{
				execute(LUMIX_NEW(m_allocator, RemoveNodeCommand)(m_current_node_id, m_current_shader_type, *this));
				m_current_node_id = -1;
			}
		}

		if (ImGui::BeginMenu("Add"))
		{
			for (auto node_type : NODE_TYPES)
			{
				if (!node_type.is_frag && m_current_shader_type == ShaderType::FRAGMENT) continue;
				if (!node_type.is_vert && m_current_shader_type == ShaderType::VERTEX) continue;

				if (ImGui::MenuItem(node_type.name))
				{
					execute(LUMIX_NEW(m_allocator, CreateNodeCommand)(
						-1, node_type.type, m_current_shader_type, add_pos, *this));
				}
			}
			ImGui::EndMenu();
		}

		ImGui::EndPopup();
	}
	ImGui::EndChild();
}
largeNum Nsubl(largeNum a1, largeNum a2) // For substracting any +ve/-ve numbers
{
	int i,k,d;
	largeNum result;
	if(Nequal_to_zero(a1) && Nequal_to_zero(a2))
	{
		result.sign=0;
		result.len=1;
		result.line[0]=0;
		return(result);	
	}
	else
	{
		if(a1.sign==1 && a2.sign==0)
		{
			result=add_pos(a1,a2);
			result.sign=1;
			return(result);
		}
		else if(a1.sign==0 && a2.sign==1)
		{
			result=add_pos(a1,a2);
			result.sign=0;
			return(result);
		}
		else 
		{
				if(Ngreaterthan(a1,a2)==1)		
		   		{		
			
					d=a1.len-a2.len;
					shift(&a2,d);
					k=a1.len-1;
					for(i=k;i>=0;i--)
					{
						if(a1.line[i]<a2.line[i])
						{
							result.line[i]=(a1.line[i]+10)-a2.line[i];
							a2.line[i-1]++;
						}
						else
						{
							result.line[i]=a1.line[i]-a2.line[i];
						}
					}
				
					result.len=a1.len;
					if(a1.sign==0&&a2.sign==0)
						result.sign=0;
					else
						result.sign=1;
					return(result);
				}
				else
				{
					d=a2.len-a1.len;
					shift(&a1,d);
					k=a2.len-1;
					for(i=k;i>=0;i--)
					{
						if(a2.line[i]<a1.line[i])
						{
							result.line[i]=(a2.line[i]+10)-a1.line[i];
							a1.line[i-1]++;
						}
						else
						{
							result.line[i]=a2.line[i]-a1.line[i];
						}
					}
					result.len=a2.len;
					if(a1.sign==0&&a2.sign==0)
						result.sign=1;
					else
						result.sign=0;
					return(result);
				}
		 	
		}
	}
}
//*****(F-2)
largeInt subl(largeInt ia1, largeInt ia2) // For substracting any +ve/-ve numbers
{
	int i,k,d;
	largeNum result,a1,a2;
	largeInt iresult;
	if(equal_to_zero(ia1) && equal_to_zero(ia2))
	{
		iresult.sign=0;
		iresult.len=1;
		iresult.line[0]='0';
		return(iresult);	
	}
	else
	{
		IntToNum(ia1,&a1);
		IntToNum(ia2,&a2);
		if(a1.sign==1 && a2.sign==0)
		{
			result=add_pos(a1,a2);
			result.sign=1;
			NumToInt(result,&iresult);
			return(iresult);
		}
		else if(a1.sign==0 && a2.sign==1)
		{
			result=add_pos(a1,a2);
			result.sign=0;
			NumToInt(result,&iresult);
			return(iresult);
		}
		else 
		{
				if(greaterthan(ia1,ia2)==1)		
		   		{		
			
					d=a1.len-a2.len;
					shift(&a2,d);
					k=a1.len-1;
					for(i=k;i>=0;i--)
					{
						if(a1.line[i]<a2.line[i])
						{
							result.line[i]=(a1.line[i]+10)-a2.line[i];
							a2.line[i-1]++;
						}
						else
						{
							result.line[i]=a1.line[i]-a2.line[i];
						}
					}
				
					result.len=a1.len;
					if(a1.sign==0&&a2.sign==0)
						result.sign=0;
					else
						result.sign=1;
					rem_all_zeros_from_left(&result);
					NumToInt(result,&iresult);
					if(equal_to_zero(iresult))
					{
						iresult.sign=0;
						iresult.len=1;
						iresult.line[0]='0';
					} 
					return(iresult);
				}
				else
				{
					d=a2.len-a1.len;
					shift(&a1,d);
					k=a2.len-1;
					for(i=k;i>=0;i--)
					{
						if(a2.line[i]<a1.line[i])
						{
							result.line[i]=(a2.line[i]+10)-a1.line[i];
							a1.line[i-1]++;
						}
						else
						{
							result.line[i]=a2.line[i]-a1.line[i];
						}
					}
					result.len=a2.len;
					if(a1.sign==0&&a2.sign==0)
						result.sign=1;
					else
						result.sign=0;
					rem_all_zeros_from_left(&result);
					NumToInt(result,&iresult);
					if(equal_to_zero(iresult))
					{
						iresult.sign=0;
						iresult.len=1;
						iresult.line[0]='0';
					} 
					return(iresult);
				}
		 	
		}
	}
}
Beispiel #7
0
static position
linear_combination(GLfloat t, position p, position q)
{
  return add_pos(scale_pos(1.0 - t, p), scale_pos(t, q));
}