void Footholdtree::limitmoves(PhysicsObject& phobj) const
	{
		if (phobj.hmobile())
		{
			double crntx = phobj.crntx();
			double nextx = phobj.nextx();

			bool left = phobj.hspeed < 0.0f;
			double wall = getwall(phobj.fhid, left, phobj.nexty());
			bool collision = left ?
				crntx >= wall && nextx <= wall :
				crntx <= wall && nextx >= wall;

			if (!collision && phobj.flagset(PhysicsObject::TURNATEDGES))
			{
				wall = getedge(phobj.fhid, left);
				collision = left ?
					crntx >= wall && nextx <= wall : 
					crntx <= wall && nextx >= wall;
			}

			if (collision)
			{
				phobj.limitx(wall);
				phobj.clearflag(PhysicsObject::TURNATEDGES);
			}
		}

		if (phobj.vmobile())
		{
			double crnty = phobj.crnty();
			double nexty = phobj.nexty();

			auto ground = Range<double>(
				getfh(phobj.fhid).resolvex(phobj.crntx()),
				getfh(phobj.fhid).resolvex(phobj.nextx())
				);
			bool collision = crnty <= ground.first() && nexty >= ground.second();
			if (collision)
			{
				phobj.limity(ground.second());

				limitmoves(phobj);
			}
			else
			{
				if (nexty < borders.first())
				{
					phobj.limity(borders.first());
				}
				else if (nexty > borders.second())
				{
					phobj.limity(borders.second());
				}
			}
		}
	}
	void Footholdtree::limit_movement(PhysicsObject& phobj) const
	{
		if (phobj.hmobile())
		{
			double crnt_x = phobj.crnt_x();
			double next_x = phobj.next_x();

			bool left = phobj.hspeed < 0.0f;
			double wall = get_wall(phobj.fhid, left, phobj.next_y());
			bool collision = left ?
				crnt_x >= wall && next_x <= wall :
				crnt_x <= wall && next_x >= wall;

			if (!collision && phobj.is_flag_set(PhysicsObject::TURNATEDGES))
			{
				wall = get_edge(phobj.fhid, left);
				collision = left ?
					crnt_x >= wall && next_x <= wall : 
					crnt_x <= wall && next_x >= wall;
			}

			if (collision)
			{
				phobj.limitx(wall);
				phobj.clear_flag(PhysicsObject::TURNATEDGES);
			}
		}

		if (phobj.vmobile())
		{
			double crnt_y = phobj.crnt_y();
			double next_y = phobj.next_y();

			auto ground = Range<double>(
				get_fh(phobj.fhid).ground_below(phobj.crnt_x()),
				get_fh(phobj.fhid).ground_below(phobj.next_x())
				);
			bool collision = crnt_y <= ground.first() && next_y >= ground.second();
			if (collision)
			{
				phobj.limity(ground.second());

				limit_movement(phobj);
			}
			else
			{
				if (next_y < borders.first())
				{
					phobj.limity(borders.first());
				}
				else if (next_y > borders.second())
				{
					phobj.limity(borders.second());
				}
			}
		}
	}